5 // Marius Ungureanu <marius.ungureanu@xamarin.com>
7 // Copyright (c) 2015 Xamarin, Inc (http://www.xamarin.com)
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 #if !MONOTOUCH && !FULL_AOT_RUNTIME
31 using System
.Reflection
;
32 using NUnit
.Framework
;
33 using System
.Collections
;
35 namespace MonoTests
.System
.Reflection
.VisibilityTypes
38 public class VisibilityTests
40 static void DoesNotContain (IEnumerable collection
, object val
)
42 Assert
.That(collection
, Has
.No
.Member(val
));
45 static void Contains (IEnumerable collection
, object val
)
47 Assert
.That(collection
, Has
.Member(val
));
51 public void TestsExportedTypes ()
53 var types
= typeof (VisibilityTests
).Assembly
.GetExportedTypes ();
55 // Test visibility means that the class is public by applying and on the 'public' visibility of the nested items.
56 DoesNotContain (types
, typeof (InternalClass
));
57 Contains (types
, typeof (PublicClass
));
59 DoesNotContain (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+InternalNested", true));
60 DoesNotContain (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PrivateNested", true));
61 DoesNotContain (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+ProtectedNested", true));
62 DoesNotContain (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PublicNested", true));
64 DoesNotContain (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+InternalNested", true));
65 DoesNotContain (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PrivateNested", true));
66 DoesNotContain (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+ProtectedNested", true));
67 Contains (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PublicNested", true));
71 public void TestsModuleTypes ()
73 var types
= typeof (VisibilityTests
).Module
.GetTypes ();
75 // Test that all the types defined exist.
76 Contains (types
, typeof (InternalClass
));
77 Contains (types
, typeof (PublicClass
));
79 Contains (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+InternalNested", true));
80 Contains (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PrivateNested", true));
81 Contains (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+ProtectedNested", true));
82 Contains (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PublicNested", true));
84 Contains (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+InternalNested", true));
85 Contains (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PrivateNested", true));
86 Contains (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+ProtectedNested", true));
87 Contains (types
, Type
.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PublicNested", true));
92 internal class InternalNested
{}
93 private class PrivateNested
{}
94 protected class ProtectedNested
{}
95 public class PublicNested
{}
98 public class PublicClass
100 internal class InternalNested
{}
101 private class PrivateNested
{}
102 protected class ProtectedNested
{}
103 public class PublicNested
{}