DataServiceProviderMethodsTest.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // DataServiceProviderMethods.cs
  3. //
  4. // Author:
  5. // Marek Habersack <[email protected]>
  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. #if NET_4_0
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Data.Services.Providers;
  30. using NUnit.Framework;
  31. using MonoTests.Common;
  32. namespace MonoTests.System.Data.Services.Providers
  33. {
  34. [TestFixture]
  35. public class DataServiceProviderMethodsTest
  36. {
  37. [Test]
  38. public void TypeIs ()
  39. {
  40. var rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
  41. AssertExtensions.Throws<NotImplementedException> (() => {
  42. DataServiceProviderMethods.TypeIs ("test", rt);
  43. }, "#A1");
  44. AssertExtensions.Throws<NotImplementedException> (() => {
  45. DataServiceProviderMethods.TypeIs (null, null);
  46. }, "#A2");
  47. }
  48. [Test]
  49. public void Convert ()
  50. {
  51. var rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
  52. AssertExtensions.Throws<NotImplementedException> (() => {
  53. DataServiceProviderMethods.Convert ("test", rt);
  54. }, "#A1");
  55. AssertExtensions.Throws<NotImplementedException> (() => {
  56. DataServiceProviderMethods.Convert (null, null);
  57. }, "#A2");
  58. }
  59. [Test]
  60. public void GetSequenceValue ()
  61. {
  62. var rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
  63. var rp = new ResourceProperty ("Length", ResourcePropertyKind.ComplexType, rt);
  64. AssertExtensions.Throws<NotImplementedException> (() => {
  65. DataServiceProviderMethods.GetSequenceValue<string> ("test", rp);
  66. }, "#A1");
  67. AssertExtensions.Throws<NotImplementedException> (() => {
  68. DataServiceProviderMethods.GetSequenceValue<string> (null, null);
  69. }, "#A2");
  70. }
  71. [Test]
  72. public void GetValue ()
  73. {
  74. var rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
  75. var rp = new ResourceProperty ("Length", ResourcePropertyKind.ComplexType, rt);
  76. AssertExtensions.Throws<NotImplementedException> (() => {
  77. DataServiceProviderMethods.GetValue ("test", rp);
  78. }, "#A1");
  79. AssertExtensions.Throws<NotImplementedException> (() => {
  80. DataServiceProviderMethods.GetValue (null, null);
  81. }, "#A2");
  82. }
  83. [Test]
  84. public void Compare_String_String ()
  85. {
  86. Assert.AreEqual (1, DataServiceProviderMethods.Compare ("right", "left"), "#A1");
  87. Assert.AreEqual (0, DataServiceProviderMethods.Compare ("right", "right"), "#A2");
  88. Assert.AreEqual (0, DataServiceProviderMethods.Compare (String.Empty, String.Empty), "#A3");
  89. Assert.AreEqual (-1, DataServiceProviderMethods.Compare ("left", "right"), "#A4");
  90. Assert.AreEqual (-1, DataServiceProviderMethods.Compare (null, "right"), "#A5");
  91. Assert.AreEqual (1, DataServiceProviderMethods.Compare ("right", null), "#A6");
  92. Assert.AreEqual (0, DataServiceProviderMethods.Compare ((string)null, (string)null), "#A7");
  93. }
  94. [Test]
  95. public void Compare_Bool_Bool ()
  96. {
  97. Assert.AreEqual (-1, DataServiceProviderMethods.Compare (false, true), "#A1");
  98. Assert.AreEqual (0, DataServiceProviderMethods.Compare (false, false), "#A2");
  99. Assert.AreEqual (1, DataServiceProviderMethods.Compare (true, false), "#A3");
  100. Assert.AreEqual (0, DataServiceProviderMethods.Compare (true, true), "#A4");
  101. }
  102. [Test]
  103. public void Compare_NullableBool_NullableBool ()
  104. {
  105. Assert.AreEqual (-1, DataServiceProviderMethods.Compare ((bool?) false, (bool?) true), "#A1");
  106. Assert.AreEqual (0, DataServiceProviderMethods.Compare ((bool?) false, (bool?) false), "#A2");
  107. Assert.AreEqual (1, DataServiceProviderMethods.Compare ((bool?) true, (bool?) false), "#A3");
  108. Assert.AreEqual (0, DataServiceProviderMethods.Compare ((bool?) true, (bool?) true), "#A4");
  109. Assert.AreEqual (1, DataServiceProviderMethods.Compare ((bool?) false, null), "#B1");
  110. Assert.AreEqual (1, DataServiceProviderMethods.Compare ((bool?) true, null), "#B2");
  111. Assert.AreEqual (-1, DataServiceProviderMethods.Compare (null, (bool?)false), "#B3");
  112. Assert.AreEqual (-1, DataServiceProviderMethods.Compare (null, (bool?) true), "#B4");
  113. Assert.AreEqual (0, DataServiceProviderMethods.Compare ((bool?) null, (bool?) null), "#B5");
  114. }
  115. [Test]
  116. public void Compare_Guid_Guid ()
  117. {
  118. var guid1 = new Guid ("bdec809c-f8c5-4bc9-8b56-fb34a12a3e1c");
  119. var guid2 = new Guid ("898b2fe2-3530-4f56-85de-79344e59a90f");
  120. Assert.AreEqual (1, DataServiceProviderMethods.Compare (guid1, guid2), "#A1");
  121. Assert.AreEqual (0, DataServiceProviderMethods.Compare (guid1, guid1), "#A2");
  122. Assert.AreEqual (-1, DataServiceProviderMethods.Compare (guid2, guid1), "#A3");
  123. guid1 = new Guid ("00000000-0000-0000-0000-000000000000");
  124. guid2 = new Guid ("00000000-0000-0000-0000-000000000001");
  125. Assert.AreEqual (-1, DataServiceProviderMethods.Compare (guid1, guid2), "#B1");
  126. Assert.AreEqual (1, DataServiceProviderMethods.Compare (guid2, guid1), "#B2");
  127. }
  128. [Test]
  129. public void Compare_NullableGuid_NullableGuid ()
  130. {
  131. var guid1 = new Guid ("bdec809c-f8c5-4bc9-8b56-fb34a12a3e1c");
  132. var guid2 = new Guid ("898b2fe2-3530-4f56-85de-79344e59a90f");
  133. Assert.AreEqual (1, DataServiceProviderMethods.Compare (guid1, guid2), "#A1");
  134. Assert.AreEqual (0, DataServiceProviderMethods.Compare (guid1, guid1), "#A2");
  135. Assert.AreEqual (-1, DataServiceProviderMethods.Compare (guid2, guid1), "#A3");
  136. guid1 = new Guid ("00000000-0000-0000-0000-000000000000");
  137. guid2 = new Guid ("00000000-0000-0000-0000-000000000001");
  138. Assert.AreEqual (-1, DataServiceProviderMethods.Compare (guid1, guid2), "#B1");
  139. Assert.AreEqual (1, DataServiceProviderMethods.Compare (guid2, guid1), "#B2");
  140. Assert.AreEqual (1, DataServiceProviderMethods.Compare ((Guid?)guid1, (Guid?)null), "#C1");
  141. Assert.AreEqual (0, DataServiceProviderMethods.Compare ((Guid?)null, (Guid?)null), "#C2");
  142. Assert.AreEqual (-1, DataServiceProviderMethods.Compare ((Guid?) null, (Guid?)guid1), "#C3");
  143. }
  144. }
  145. }
  146. #endif