[system.data.services] Stubs for a few 4.0 types + some implementation + some tests
[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 #if NET_4_0
28 using System;
29 using System.Collections.Generic;
30 using System.Data.Services.Providers;
31
32 using NUnit.Framework;
33 using MonoTests.Common;
34
35 namespace MonoTests.System.Data.Services.Providers
36 {
37         [TestFixture]
38         public class ResourceTypeTest
39         {
40                 [Test]
41                 public void Constructor ()
42                 {
43                         var dummy = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
44                         ResourceType rt;
45
46                         AssertExtensions.Throws<ArgumentNullException> (() => {
47                                 rt = new ResourceType (null, ResourceTypeKind.ComplexType, dummy, "System", "Null", false);
48                         }, "#A1-1");
49
50                         AssertExtensions.Throws<ArgumentNullException> (() => {
51                                 rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, "System", null, false);
52                         }, "#A1-2");
53
54                         AssertExtensions.Throws<ArgumentNullException> (() => {
55                                 rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, null, null, false);
56                         }, "#A1-3");
57
58                         AssertExtensions.Throws<ArgumentNullException> (() => {
59                                 rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, "System", String.Empty, false);
60                         }, "#A1-4");
61
62                         AssertExtensions.Throws<ArgumentException> (() => {
63                                 rt = new ResourceType (typeof (string), ResourceTypeKind.Primitive, null, "System", "String", false);
64                         }, "#A2-1");
65                         
66                         AssertExtensions.Throws<ArgumentException> (() => {
67                                 rt = new ResourceType (typeof (bool), ResourceTypeKind.Primitive, null, "System", "Bool", false);
68                         }, "#A2-2");
69
70                         AssertExtensions.Throws<ArgumentException> (() => {
71                                 rt = new ResourceType (typeof (int), ResourceTypeKind.EntityType, null, "System", "Int32", true);
72                         }, "#A2-3");
73
74                         rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, null, "String", false);
75                         Assert.AreEqual (typeof (string), rt.InstanceType, "#B1-1");
76                         Assert.AreEqual (ResourceTypeKind.ComplexType, rt.ResourceTypeKind, "#B1-2");
77                         Assert.AreEqual (dummy, rt.BaseType, "#B1-3");
78                         Assert.AreEqual (String.Empty, rt.Namespace, "#B1-4");
79                         Assert.AreEqual ("String", rt.Name, "#B1-5");
80                         Assert.AreEqual (false, rt.IsAbstract, "#B1-6");
81                         Assert.AreEqual ("String", rt.FullName, "#B1-7");
82
83                         rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, String.Empty, "String", false);
84                         Assert.AreEqual (typeof (string), rt.InstanceType, "#B2-1");
85                         Assert.AreEqual (ResourceTypeKind.ComplexType, rt.ResourceTypeKind, "#B2-2");
86                         Assert.AreEqual (dummy, rt.BaseType, "#B2-3");
87                         Assert.AreEqual (String.Empty, rt.Namespace, "#B2-4");
88                         Assert.AreEqual ("String", rt.Name, "#B2-5");
89                         Assert.AreEqual (false, rt.IsAbstract, "#B2-6");
90                         Assert.AreEqual ("String", rt.FullName, "#B2-7");
91
92                         rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
93                         Assert.AreEqual (typeof (string), rt.InstanceType, "#B3-1");
94                         Assert.AreEqual (ResourceTypeKind.ComplexType, rt.ResourceTypeKind, "#B3-2");
95                         Assert.AreEqual (null, rt.BaseType, "#B3-3");
96                         Assert.AreEqual ("System", rt.Namespace, "#B3-4");
97                         Assert.AreEqual ("String", rt.Name, "#B3-5");
98                         Assert.AreEqual (false, rt.IsAbstract, "#B3-6");
99                         Assert.AreEqual ("System.String", rt.FullName, "#B3-7");
100
101                         rt = new ResourceType (typeof (string), ResourceTypeKind.EntityType, null, "System", "String", false);
102                         Assert.AreEqual (typeof (string), rt.InstanceType, "#B4-1");
103                         Assert.AreEqual (ResourceTypeKind.EntityType, rt.ResourceTypeKind, "#B4-2");
104                         Assert.AreEqual (null, rt.BaseType, "#B4-3");
105                         Assert.AreEqual ("System", rt.Namespace, "#B4-4");
106                         Assert.AreEqual ("String", rt.Name, "#B4-5");
107                         Assert.AreEqual (false, rt.IsAbstract, "#B4-6");
108                         Assert.AreEqual ("System.String", rt.FullName, "#B4-7");
109
110                         rt = new ResourceType (typeof (string), ResourceTypeKind.EntityType, null, "System", "String", true);
111                         Assert.AreEqual (typeof (string), rt.InstanceType, "#B5-1");
112                         Assert.AreEqual (ResourceTypeKind.EntityType, rt.ResourceTypeKind, "#B5-2");
113                         Assert.AreEqual (null, rt.BaseType, "#B5-3");
114                         Assert.AreEqual ("System", rt.Namespace, "#B5-4");
115                         Assert.AreEqual ("String", rt.Name, "#B5-5");
116                         Assert.AreEqual (true, rt.IsAbstract, "#B5-6");
117                         Assert.AreEqual ("System.String", rt.FullName, "#B5-7");
118                 }
119
120                 [Test]
121                 public void CanReflectOnInstanceType ()
122                 {
123                         var rt = new ResourceType (typeof (string), ResourceTypeKind.EntityType, null, "System", "String", true);
124                         Assert.AreEqual (true, rt.CanReflectOnInstanceType, "#A1-1");
125                         rt.CanReflectOnInstanceType = false;
126                         Assert.AreEqual (false, rt.CanReflectOnInstanceType, "#A1-2");
127
128                         rt = new ResourceType (typeof (ResourceTypeTest), ResourceTypeKind.ComplexType, null, "MonoTests.System.Data.Services.Providers", "ResourceTypeTest", true);
129                         Assert.AreEqual (true, rt.CanReflectOnInstanceType, "#A2-1");
130                         rt.CanReflectOnInstanceType = false;
131                         Assert.AreEqual (false, rt.CanReflectOnInstanceType, "#A2-2");
132                 }
133         }
134 }
135 #endif