• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 // Protocol Buffers - Google's data interchange format
3 // Copyright 2015 Google Inc.  All rights reserved.
4 //
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file or at
7 // https://developers.google.com/open-source/licenses/bsd
8 #endregion
9 
10 using NUnit.Framework;
11 using System.Reflection;
12 
13 namespace Google.Protobuf.Compatibility
14 {
15     public class PropertyInfoExtensionsTest
16     {
17         public string PublicReadWrite { get; set; }
18         private string PrivateReadWrite { get; set; }
19         public string PublicReadPrivateWrite { get; private set; }
20         public string PrivateReadPublicWrite { private get; set; }
21         public string PublicReadOnly { get { return null; } }
22         private string PrivateReadOnly { get { return null; } }
23         public string PublicWriteOnly { set { } }
24         private string PrivateWriteOnly { set {  } }
25 
26         [Test]
27         [TestCase("PublicReadWrite")]
28         [TestCase("PublicReadPrivateWrite")]
29         [TestCase("PublicReadOnly")]
GetGetMethod_Success(string name)30         public void GetGetMethod_Success(string name)
31         {
32             var propertyInfo = typeof(PropertyInfoExtensionsTest)
33                 .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
34             Assert.IsNotNull(PropertyInfoExtensions.GetGetMethod(propertyInfo));
35         }
36 
37         [Test]
38         [TestCase("PrivateReadWrite")]
39         [TestCase("PrivateReadPublicWrite")]
40         [TestCase("PrivateReadOnly")]
41         [TestCase("PublicWriteOnly")]
42         [TestCase("PrivateWriteOnly")]
GetGetMethod_NoAccessibleGetter(string name)43         public void GetGetMethod_NoAccessibleGetter(string name)
44         {
45             var propertyInfo = typeof(PropertyInfoExtensionsTest)
46                 .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
47             Assert.IsNull(PropertyInfoExtensions.GetGetMethod(propertyInfo));
48         }
49 
50         [Test]
51         [TestCase("PublicReadWrite")]
52         [TestCase("PrivateReadPublicWrite")]
53         [TestCase("PublicWriteOnly")]
GetSetMethod_Success(string name)54         public void GetSetMethod_Success(string name)
55         {
56             var propertyInfo = typeof(PropertyInfoExtensionsTest)
57                 .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
58             Assert.IsNotNull(PropertyInfoExtensions.GetSetMethod(propertyInfo));
59         }
60 
61         [Test]
62         [TestCase("PublicReadPrivateWrite")]
63         [TestCase("PrivateReadWrite")]
64         [TestCase("PrivateReadOnly")]
65         [TestCase("PublicReadOnly")]
66         [TestCase("PrivateWriteOnly")]
GetSetMethod_NoAccessibleGetter(string name)67         public void GetSetMethod_NoAccessibleGetter(string name)
68         {
69             var propertyInfo = typeof(PropertyInfoExtensionsTest)
70                 .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
71             Assert.IsNull(PropertyInfoExtensions.GetSetMethod(propertyInfo));
72         }
73     }
74 
75 }
76