Merge pull request #1936 from esdrubal/DotNetRelativeOrAbsolute
[mono.git] / mcs / class / System.Data.Services / Test / System.Data.Services.Providers / ResourceTypeTest.cs
1 // 
2 // DataServiceProviderMethods.cs
3 //  
4 // Author:
5 //       Marek Habersack <grendel@twistedcode.net>
6 // 
7 // Copyright (c) 2011 Novell, Inc
8 // 
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:
15 // 
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 // 
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
25 // THE SOFTWARE.
26
27 using System;
28 using System.Collections.Generic;
29 using System.Data.Services.Providers;
30
31 using NUnit.Framework;
32 using MonoTests.Common;
33
34 namespace MonoTests.System.Data.Services.Providers
35 {
36         [TestFixture]
37         public class ResourceTypeTest
38         {
39                 [Test]
40                 public void Constructor ()
41                 {
42                         var dummy = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
43                         ResourceType rt;
44
45                         AssertExtensions.Throws<ArgumentNullException> (() => {
46                                 rt = new ResourceType (null, ResourceTypeKind.ComplexType, dummy, "System", "Null", false);
47                         }, "#A1-1");
48
49                         AssertExtensions.Throws<ArgumentNullException> (() => {
50                                 rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, "System", null, false);
51                         }, "#A1-2");
52
53                         AssertExtensions.Throws<ArgumentNullException> (() => {
54                                 rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, null, null, false);
55                         }, "#A1-3");
56
57                         AssertExtensions.Throws<ArgumentNullException> (() => {
58                                 rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, "System", String.Empty, false);
59                         }, "#A1-4");
60
61                         AssertExtensions.Throws<ArgumentException> (() => {
62                                 rt = new ResourceType (typeof (string), ResourceTypeKind.Primitive, null, "System", "String", false);
63                         }, "#A2-1");
64                         
65                         AssertExtensions.Throws<ArgumentException> (() => {
66                                 rt = new ResourceType (typeof (bool), ResourceTypeKind.Primitive, null, "System", "Bool", false);
67                         }, "#A2-2");
68
69                         AssertExtensions.Throws<ArgumentException> (() => {
70                                 rt = new ResourceType (typeof (int), ResourceTypeKind.EntityType, null, "System", "Int32", true);
71                         }, "#A2-3");
72
73                         rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, null, "String", false);
74                         Assert.AreEqual (typeof (string), rt.InstanceType, "#B1-1");
75                         Assert.AreEqual (ResourceTypeKind.ComplexType, rt.ResourceTypeKind, "#B1-2");
76                         Assert.AreEqual (dummy, rt.BaseType, "#B1-3");
77                         Assert.AreEqual (String.Empty, rt.Namespace, "#B1-4");
78                         Assert.AreEqual ("String", rt.Name, "#B1-5");
79                         Assert.AreEqual (false, rt.IsAbstract, "#B1-6");
80                         Assert.AreEqual ("String", rt.FullName, "#B1-7");
81
82                         rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, String.Empty, "String", false);
83                         Assert.AreEqual (typeof (string), rt.InstanceType, "#B2-1");
84                         Assert.AreEqual (ResourceTypeKind.ComplexType, rt.ResourceTypeKind, "#B2-2");
85                         Assert.AreEqual (dummy, rt.BaseType, "#B2-3");
86                         Assert.AreEqual (String.Empty, rt.Namespace, "#B2-4");
87                         Assert.AreEqual ("String", rt.Name, "#B2-5");
88                         Assert.AreEqual (false, rt.IsAbstract, "#B2-6");
89                         Assert.AreEqual ("String", rt.FullName, "#B2-7");
90
91                         rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
92                         Assert.AreEqual (typeof (string), rt.InstanceType, "#B3-1");
93                         Assert.AreEqual (ResourceTypeKind.ComplexType, rt.ResourceTypeKind, "#B3-2");
94                         Assert.AreEqual (null, rt.BaseType, "#B3-3");
95                         Assert.AreEqual ("System", rt.Namespace, "#B3-4");
96                         Assert.AreEqual ("String", rt.Name, "#B3-5");
97                         Assert.AreEqual (false, rt.IsAbstract, "#B3-6");
98                         Assert.AreEqual ("System.String", rt.FullName, "#B3-7");
99
100                         rt = new ResourceType (typeof (string), ResourceTypeKind.EntityType, null, "System", "String", false);
101                         Assert.AreEqual (typeof (string), rt.InstanceType, "#B4-1");
102                         Assert.AreEqual (ResourceTypeKind.EntityType, rt.ResourceTypeKind, "#B4-2");
103                         Assert.AreEqual (null, rt.BaseType, "#B4-3");
104                         Assert.AreEqual ("System", rt.Namespace, "#B4-4");
105                         Assert.AreEqual ("String", rt.Name, "#B4-5");
106                         Assert.AreEqual (false, rt.IsAbstract, "#B4-6");
107                         Assert.AreEqual ("System.String", rt.FullName, "#B4-7");
108
109                         rt = new ResourceType (typeof (string), ResourceTypeKind.EntityType, null, "System", "String", true);
110                         Assert.AreEqual (typeof (string), rt.InstanceType, "#B5-1");
111                         Assert.AreEqual (ResourceTypeKind.EntityType, rt.ResourceTypeKind, "#B5-2");
112                         Assert.AreEqual (null, rt.BaseType, "#B5-3");
113                         Assert.AreEqual ("System", rt.Namespace, "#B5-4");
114                         Assert.AreEqual ("String", rt.Name, "#B5-5");
115                         Assert.AreEqual (true, rt.IsAbstract, "#B5-6");
116                         Assert.AreEqual ("System.String", rt.FullName, "#B5-7");
117                 }
118
119                 [Test]
120                 public void CanReflectOnInstanceType ()
121                 {
122                         var rt = new ResourceType (typeof (string), ResourceTypeKind.EntityType, null, "System", "String", true);
123                         Assert.AreEqual (true, rt.CanReflectOnInstanceType, "#A1-1");
124                         rt.CanReflectOnInstanceType = false;
125                         Assert.AreEqual (false, rt.CanReflectOnInstanceType, "#A1-2");
126
127                         rt = new ResourceType (typeof (ResourceTypeTest), ResourceTypeKind.ComplexType, null, "MonoTests.System.Data.Services.Providers", "ResourceTypeTest", true);
128                         Assert.AreEqual (true, rt.CanReflectOnInstanceType, "#A2-1");
129                         rt.CanReflectOnInstanceType = false;
130                         Assert.AreEqual (false, rt.CanReflectOnInstanceType, "#A2-2");
131                 }
132         }
133 }