Esempio n. 1
0
        public void InsertWithDeclarationAsParameter()
        {
            string expectedQuery = @"
                INSERT [TestTable] (Title, CreationDate)
                VALUES(
                    @TestTable_Title,
                    SYSUTCDATETIME()
                )
            ";
            Dictionary <string, object> expectedParameters = new Dictionary <string, object> {
                { "TestTable_Title", "testTitle" },
            };

            TSqlBuilder builder = new TSqlBuilder();

            InsertDeclaration <TestTable> insertDecalration = new InsertDeclaration <TestTable>();

            insertDecalration.Set(f => f.Title, "testTitle");
            insertDecalration.Set(f => f.CreationDate, TSqlStatement.SysUtcDateTimeCall);

            builder.Insert <TestTable>(insertDecalration);

            TSqlQuery actualQuery = builder.CompileQuery();

            Assert.AreEqual(NormalizeSqlQuery(expectedQuery), NormalizeSqlQuery(actualQuery.Query));
            CollectionAssert.AreEquivalent(expectedParameters, actualQuery.Parameters);
        }