OLD | NEW |
1 #region Copyright notice and license | 1 #region Copyright notice and license |
2 // Protocol Buffers - Google's data interchange format | 2 // Protocol Buffers - Google's data interchange format |
3 // Copyright 2015 Google Inc. All rights reserved. | 3 // Copyright 2015 Google Inc. All rights reserved. |
4 // https://developers.google.com/protocol-buffers/ | 4 // https://developers.google.com/protocol-buffers/ |
5 // | 5 // |
6 // Redistribution and use in source and binary forms, with or without | 6 // Redistribution and use in source and binary forms, with or without |
7 // modification, are permitted provided that the following conditions are | 7 // modification, are permitted provided that the following conditions are |
8 // met: | 8 // met: |
9 // | 9 // |
10 // * Redistributions of source code must retain the above copyright | 10 // * Redistributions of source code must retain the above copyright |
(...skipping 16 matching lines...) Expand all Loading... |
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 #endregion | 31 #endregion |
32 using NUnit.Framework; | 32 using NUnit.Framework; |
33 using System; | 33 using System; |
34 using System.Collections.Generic; | 34 using System.Collections.Generic; |
35 using System.Reflection; | 35 using System.Reflection; |
36 | 36 |
37 #if !DOTNET35 | |
38 namespace Google.Protobuf.Compatibility | 37 namespace Google.Protobuf.Compatibility |
39 { | 38 { |
40 public class TypeExtensionsTest | 39 public class TypeExtensionsTest |
41 { | 40 { |
42 public class DerivedList : List<string> { } | 41 public class DerivedList : List<string> { } |
43 public string PublicProperty { get; set; } | 42 public string PublicProperty { get; set; } |
44 private string PrivateProperty { get; set; } | 43 private string PrivateProperty { get; set; } |
45 | 44 |
46 public void PublicMethod() | 45 public void PublicMethod() |
47 { | 46 { |
48 } | 47 } |
49 | 48 |
50 private void PrivateMethod() | 49 private void PrivateMethod() |
51 { | 50 { |
52 } | 51 } |
53 | 52 |
54 [Test] | 53 [Test] |
| 54 [TestCase(typeof(int), true)] |
| 55 [TestCase(typeof(int?), true)] |
| 56 [TestCase(typeof(Nullable<>), true)] |
| 57 [TestCase(typeof(WireFormat.WireType), true)] |
| 58 [TestCase(typeof(string), false)] |
| 59 [TestCase(typeof(object), false)] |
| 60 [TestCase(typeof(Enum), false)] |
| 61 [TestCase(typeof(ValueType), false)] |
| 62 [TestCase(typeof(TypeExtensionsTest), false)] |
| 63 [TestCase(typeof(Action), false)] |
| 64 [TestCase(typeof(Action<>), false)] |
| 65 [TestCase(typeof(IDisposable), false)] |
| 66 public void IsValueType(Type type, bool expected) |
| 67 { |
| 68 Assert.AreEqual(expected, TypeExtensions.IsValueType(type)); |
| 69 } |
| 70 |
| 71 [Test] |
55 [TestCase(typeof(object), typeof(string), true)] | 72 [TestCase(typeof(object), typeof(string), true)] |
56 [TestCase(typeof(object), typeof(int), true)] | 73 [TestCase(typeof(object), typeof(int), true)] |
57 [TestCase(typeof(string), typeof(string), true)] | 74 [TestCase(typeof(string), typeof(string), true)] |
58 [TestCase(typeof(string), typeof(object), false)] | 75 [TestCase(typeof(string), typeof(object), false)] |
59 [TestCase(typeof(string), typeof(int), false)] | 76 [TestCase(typeof(string), typeof(int), false)] |
60 [TestCase(typeof(int), typeof(int), true)] | 77 [TestCase(typeof(int), typeof(int), true)] |
61 [TestCase(typeof(ValueType), typeof(int), true)] | 78 [TestCase(typeof(ValueType), typeof(int), true)] |
62 [TestCase(typeof(long), typeof(int), false)] // | 79 [TestCase(typeof(long), typeof(int), false)] // |
63 public void IsAssignableFrom(Type target, Type argument, bool expected) | 80 public void IsAssignableFrom(Type target, Type argument, bool expected) |
64 { | 81 { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 124 } |
108 | 125 |
109 [Test] | 126 [Test] |
110 [TestCase(typeof(List<string>), "IndexOf")] | 127 [TestCase(typeof(List<string>), "IndexOf")] |
111 public void GetMethod_Ambiguous(Type type, string name) | 128 public void GetMethod_Ambiguous(Type type, string name) |
112 { | 129 { |
113 Assert.Throws<AmbiguousMatchException>(() => TypeExtensions.GetMetho
d(type, name)); | 130 Assert.Throws<AmbiguousMatchException>(() => TypeExtensions.GetMetho
d(type, name)); |
114 } | 131 } |
115 } | 132 } |
116 } | 133 } |
117 #endif | |
OLD | NEW |