PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/System.Data.Linq/src/DbLinq/Test/Providers/DataContextTestBase.cs

https://github.com/ekovalenko-softheme/mono
C# | 158 lines | 111 code | 22 blank | 25 comment | 2 complexity | c81d01571f5c04afda81288cabc75c08 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, Unlicense
  1. #region MIT license
  2. //
  3. // MIT license
  4. //
  5. // Copyright (c) 2009 Novell, Inc.
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. //
  25. #endregion
  26. using System;
  27. using System.Data;
  28. using System.Data.Common;
  29. // using System.Data.Linq;
  30. using System.Data.Linq.Mapping;
  31. using System.Linq;
  32. using System.IO;
  33. #if MONO_STRICT
  34. using System.Data.Linq;
  35. #else
  36. using DbLinq.Data.Linq;
  37. #endif
  38. using NUnit.Framework;
  39. using DbLinq.Null;
  40. namespace DbLinqTest {
  41. public abstract class DataContextTestBase
  42. {
  43. DataContext context;
  44. protected DataContext Context {
  45. get { return context; }
  46. }
  47. [SetUp]
  48. public void SetUp()
  49. {
  50. context = CreateDataContext();
  51. }
  52. protected abstract DataContext CreateDataContext();
  53. [TearDown]
  54. public void TearDown()
  55. {
  56. context = null;
  57. }
  58. [Test]
  59. public void ExecuteCommand()
  60. {
  61. context.Log = new StringWriter ();
  62. try
  63. {
  64. context.ExecuteCommand("SomeCommand", 1, 2, 3);
  65. }
  66. catch (NotSupportedException)
  67. {
  68. }
  69. catch (Exception e)
  70. {
  71. Assert.Fail("# ExecuteCommand: Got exception {0}", e.ToString());
  72. }
  73. Console.WriteLine ("# ExecuteCommand: Log={0}", context.Log);
  74. }
  75. [Test]
  76. public void ExecuteQuery()
  77. {
  78. context.Log = new StringWriter ();
  79. try
  80. {
  81. context.ExecuteQuery(typeof(Person), "select * from people", 1, 2, 3);
  82. }
  83. catch (NotSupportedException)
  84. {
  85. }
  86. catch (Exception e)
  87. {
  88. Assert.Fail("# ExecuteQuery: unexpected exception: {0}", e.ToString());
  89. }
  90. Console.WriteLine ("# ExecuteQuery: Log={0}", context.Log);
  91. }
  92. [Test]
  93. public void ExecuteQueryTResult()
  94. {
  95. context.Log = new StringWriter ();
  96. try
  97. {
  98. context.ExecuteQuery<Person>("select * from people", 1, 2, 3);
  99. }
  100. catch (NotSupportedException)
  101. {
  102. }
  103. catch (Exception)
  104. {
  105. Assert.Fail();
  106. }
  107. Console.WriteLine ("# ExecuteQueryTResult: Log={0}", context.Log);
  108. }
  109. [Test]
  110. public void GetChangeSet()
  111. {
  112. // TODO
  113. context.GetChangeSet();
  114. }
  115. protected abstract string People(string firstName);
  116. protected abstract string People(string firstName, string lastName);
  117. protected abstract string People(string firstName, string lastName, int skip, int take);
  118. [Test]
  119. public void GetCommand()
  120. {
  121. var foos =
  122. from p in context.GetTable<Person>()
  123. where p.FirstName == "foo"
  124. select p;
  125. var cmd = context.GetCommand(foos);
  126. Assert.AreEqual(People("foo"), cmd.CommandText);
  127. foos = foos.Where(p => p.LastName == "bar");
  128. var cmd2 = context.GetCommand(foos);
  129. Assert.IsFalse(object.ReferenceEquals(cmd, cmd2));
  130. Assert.AreEqual(People("foo", "bar"), cmd2.CommandText);
  131. foos = foos.Skip(1).Take(2);
  132. cmd = context.GetCommand(foos);
  133. Assert.AreEqual(People("foo", "bar", 1, 2), cmd.CommandText);
  134. }
  135. }
  136. }