DataServiceProviderMethodsTest.cs 6.9 KB

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