public void TestDerivedTableWrapsWithParens() { var table = new SqlDerivedTable("SELECT * FROM [Foo]"); var args = new SqlBuildArguments(); var writer = new SqlTextWriter(); args.AssignAlias(table); ((ISqlTable)table).Render(writer, args); Assert.IsTrue(string.Equals(writer.ToString(), "(SELECT * FROM [Foo]) AS [" + args.TableName(table) + "]")); }
public void TestQueryBuilderAsSqlStatementRendersParametersToArgs() { var conn = new MockConnection(); var query = new DbQueryBuilder("SELECT * FROM dbo.TableName WHERE Foo=@Foo", conn); query.Parameters.Add(new DbParameterValue() { ParameterName = "@Foo", DbType = System.Data.DbType.Int32, Size = 4, Value = 123 }); var args = new SqlBuildArguments(); var writer = new SqlTextWriter(); ((ISqlStatementElement)query).Render(writer, args); Assert.AreEqual(1, args.Parameters.Count); Assert.AreEqual("SELECT * FROM (SELECT * FROM dbo.TableName WHERE Foo=@Foo) AS [t0]", writer.ToString()); }
public void TestDerivedTableRemovesSemicolons() { var table = new SqlDerivedTable("SELECT * FROM [Foo];"); var args = new SqlBuildArguments(); var writer = new SqlTextWriter(); args.AssignAlias(table); ((ISqlTable)table).Render(writer, args); Assert.AreEqual("(SELECT * FROM [Foo]) AS [" + args.TableName(table) + "]", writer.ToString()); }