PageRenderTime 55ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/mcs/class/System.Data.Linq/Test/SqlServer/MsSqlDataContextTest.cs

http://github.com/mono/mono
C# | 127 lines | 93 code | 10 blank | 24 comment | 0 complexity | c88b7c8795fa72756fa93422202130f5 MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, Unlicense, Apache-2.0
  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.Collections;
  28. using System.Collections.Generic;
  29. using System.Collections.ObjectModel;
  30. using System.IO;
  31. using System.Linq;
  32. using System.Reflection;
  33. #if MONO_STRICT
  34. using System.Data.Linq;
  35. using System.Data.Linq.Mapping;
  36. #else
  37. using DbLinq.Data.Linq;
  38. using DbLinq.Data.Linq.Mapping;
  39. #endif
  40. using DbLinq.Null;
  41. using NUnit.Framework;
  42. namespace DbLinqTest {
  43. [TestFixture]
  44. public class MsSqlDataContextTest : DataContextTestBase
  45. {
  46. static MsSqlDataContextTest()
  47. {
  48. #if !MONO_STRICT
  49. // Make sure this assembly has a ref to DbLinq.SqlServer.dll.
  50. var dummy = new DbLinq.SqlServer.SqlServerSqlProvider();
  51. #endif
  52. }
  53. protected override DataContext CreateDataContext()
  54. {
  55. return new DataContext (new NullConnection (), new AttributeMappingSource ());
  56. }
  57. protected override string People(string firstName)
  58. {
  59. return string.Format(
  60. "SELECT [t0].[first_name] AS [FirstName], [t0].[last_name] AS [LastName]{0}" +
  61. "FROM [people] AS [t0]{0}" +
  62. "WHERE [t0].[first_name] = @p0",
  63. Environment.NewLine);
  64. }
  65. protected override string People(string firstName, string lastName)
  66. {
  67. return string.Format(
  68. "SELECT [t0].[first_name] AS [FirstName], [t0].[last_name] AS [LastName]{0}" +
  69. "FROM [people] AS [t0]{0}" +
  70. "WHERE ([t0].[last_name] = @p0) AND ([t0].[first_name] = @p1)",
  71. Environment.NewLine);
  72. }
  73. protected override string People(string firstName, string lastName, int skip, int take)
  74. {
  75. return string.Format("SELECT [t1].[first_name] AS [FirstName], [t1].[last_name] AS [LastName]{0}" +
  76. "FROM ({0}" +
  77. " SELECT ROW_NUMBER() OVER (ORDER BY [t0].[first_name], [t0].[last_name]) AS [ROW_NUMBER], [t0].[first_name], [t0].[last_name]{0}" +
  78. " FROM [people] AS [t0]{0}" +
  79. " WHERE ([t0].[last_name] = @p0) AND ([t0].[first_name] = @p1){0}" +
  80. " ) AS [t1]{0}" +
  81. "WHERE [t1].[ROW_NUMBER] BETWEEN @p2 + 1 AND @p2 + @p3{0}" +
  82. "ORDER BY [t1].[ROW_NUMBER]",
  83. Environment.NewLine, firstName, lastName, skip, take);
  84. }
  85. [Test]
  86. public void Count()
  87. {
  88. var oldLog = Context.Log;
  89. var log = new StringWriter();
  90. try
  91. {
  92. Context.Log = log;
  93. (from p in Context.GetTable<Person>()
  94. orderby p.LastName
  95. select p)
  96. .Count();
  97. }
  98. catch (NotSupportedException)
  99. {
  100. Console.WriteLine("# logfile=\n{0}", log.ToString());
  101. var expected = string.Format("SELECT COUNT(*) AS [value]{0}" +
  102. "FROM [people] AS [t0]{0}" +
  103. "--",
  104. Environment.NewLine);
  105. StringAssert.Contains (expected, log.ToString());
  106. }
  107. catch (Exception e)
  108. {
  109. Assert.Fail("# ExecuteCommand: Got exception {0}", e.ToString());
  110. }
  111. finally
  112. {
  113. Context.Log = oldLog;
  114. }
  115. }
  116. }
  117. }