5 // Copyright (c) 2009 Novell, Inc.
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
28 using System.Collections;
\r
29 using System.Collections.Generic;
\r
30 using System.Collections.ObjectModel;
\r
33 using System.Reflection;
\r
36 using System.Data.Linq;
\r
37 using System.Data.Linq.Mapping;
\r
39 using DbLinq.Data.Linq;
\r
40 using DbLinq.Data.Linq.Mapping;
\r
44 using NUnit.Framework;
\r
46 namespace DbLinqTest {
\r
49 public class MsSqlDataContextTest : DataContextTestBase
\r
51 static MsSqlDataContextTest()
\r
54 // Make sure this assembly has a ref to DbLinq.SqlServer.dll.
\r
55 var dummy = new DbLinq.SqlServer.SqlServerSqlProvider();
\r
59 protected override DataContext CreateDataContext()
\r
61 return new DataContext (new NullConnection (), new AttributeMappingSource ());
\r
64 protected override string People(string firstName)
\r
66 return string.Format(
\r
67 "SELECT [first_name], [last_name]{0}" +
\r
68 "FROM [people]{0}" +
\r
69 "WHERE ([first_name] = '" + firstName + "')",
\r
70 Environment.NewLine); ;
\r
73 protected override string People(string firstName, string lastName)
\r
75 return People(firstName) + " AND ([last_name] = '" + lastName + "')";
\r
78 protected override string People(string firstName, string lastName, int skip, int take)
\r
80 return string.Format("SELECT *{0}" +
\r
82 " SELECT [first_name], [last_name]{0}" +
\r
84 " ROW_NUMBER() OVER(ORDER BY [first_name], [last_name]{0}" +
\r
85 ") AS [__ROW_NUMBER]{0}" +
\r
86 " FROM [people]{0}" +
\r
87 "WHERE ([first_name] = '{1}') AND ([last_name] = '{2}') ) AS [t0]{0}" +
\r
88 "WHERE [__ROW_NUMBER] BETWEEN {3}+1 AND {3}+{4}{0}" +
\r
89 "ORDER BY [__ROW_NUMBER]",
\r
90 Environment.NewLine, firstName, lastName, skip, take);
\r
96 var oldLog = Context.Log;
\r
97 var log = new StringWriter();
\r
101 (from p in Context.GetTable<Person>()
\r
106 catch (NotSupportedException)
\r
108 Console.WriteLine("# logfile=\n{0}", log.ToString());
\r
109 var expected = string.Format("SELECT COUNT(*){0}" +
\r
110 "FROM [people]{0}" +
\r
112 Environment.NewLine);
\r
113 Assert.IsTrue(log.ToString().Contains(expected));
\r
115 catch (Exception e)
\r
117 Assert.Fail("# ExecuteCommand: Got exception {0}", e.ToString());
\r
121 Context.Log = oldLog;
\r