Exemple #1
0
        public void Should_Add_Parameters_To_The_DbCommand_And_To_The_Insert_Statement()
        {
            // Arrange
            var customer = new DbCommandExtensionsTests.GenerateInsertForSqlServerTests.CustomerWithFields {
                FirstName = "Clark", LastName = "Kent", DateOfBirth = DateTime.Parse("06/18/1938")
            };

            var databaseCommand = TestHelpers.GetDatabaseCommand();

            // Act
            databaseCommand = databaseCommand.GenerateInsertForSQLite(customer, "[Person]");

            // Visual Assertion
            Trace.WriteLine(databaseCommand.DbCommand.CommandText);

            // Assert
            var parameters = databaseCommand.DbCommand.Parameters.Cast <DbParameter>().ToList();

            Assert.That(parameters.FirstOrDefault(x => x.ParameterName.Contains("@FirstName")).Value.ToString() == customer.FirstName);
            Assert.That(parameters.FirstOrDefault(x => x.ParameterName.Contains("@LastName")).Value.ToString() == customer.LastName);
            Assert.That(parameters.FirstOrDefault(x => x.ParameterName.Contains("@DateOfBirth")).Value.ToString() == customer.DateOfBirth.ToString());

            Assert.That(databaseCommand.DbCommand.CommandText.Contains("@FirstName"));
            Assert.That(databaseCommand.DbCommand.CommandText.Contains("@LastName"));
            Assert.That(databaseCommand.DbCommand.CommandText.Contains("@DateOfBirth"));
        }
        public void Should_Add_The_Type_Name_When_No_Table_Name_Is_Supplied()
        {
            // Arrange
            var customer = new DbCommandExtensionsTests.GenerateInsertForSqlServerTests.CustomerWithFields { FirstName = "Clark", LastName = "Kent", DateOfBirth = DateTime.Parse( "06/18/1938" ) };

            var databaseCommand = TestHelpers.GetDatabaseCommand();

            // Act
            databaseCommand = databaseCommand.GenerateInsertForSQLite( customer );

            // Visual Assertion
            Trace.WriteLine( databaseCommand.DbCommand.CommandText );

            // Assert
            Assert.That( databaseCommand.DbCommand.CommandText.Contains( "[CustomerWithFields]" ) );
        }
        public void Should_Generate_An_Insert_Statement_When_Passed_An_Instance_Of_An_Class_With_Fields()
        {
            // Arrange
            var customer = new DbCommandExtensionsTests.GenerateInsertForSqlServerTests.CustomerWithFields { FirstName = "Clark", LastName = "Kent", DateOfBirth = DateTime.Parse( "06/18/1938" ) };

            var databaseCommand = TestHelpers.GetDatabaseCommand();

            // Act
            databaseCommand = databaseCommand.GenerateInsertForSQLite( customer );

            // Visual Assertion
            Trace.WriteLine( databaseCommand.DbCommand.CommandText );

            // Assert
            Assert.NotNull( databaseCommand.DbCommand.CommandText );
            Assert.That( databaseCommand.DbCommand.CommandText.Contains( "INSERT" ) );
        }
Exemple #4
0
        public void Should_Use_The_Supplied_Table_Name_In_The_Insert_Statement()
        {
            // Arrange
            var customer = new DbCommandExtensionsTests.GenerateInsertForSqlServerTests.CustomerWithFields {
                FirstName = "Clark", LastName = "Kent", DateOfBirth = DateTime.Parse("06/18/1938")
            };

            var databaseCommand = TestHelpers.GetDatabaseCommand();

            // Act
            databaseCommand = databaseCommand.GenerateInsertForSQLite(customer, "[Person]");

            // Visual Assertion
            Trace.WriteLine(databaseCommand.DbCommand.CommandText);

            // Assert
            Assert.That(databaseCommand.DbCommand.CommandText.Contains("[Person]"));
        }
Exemple #5
0
        public void Should_Generate_An_Insert_Statement_When_Passed_An_Instance_Of_An_Class_With_Fields()
        {
            // Arrange
            var customer = new DbCommandExtensionsTests.GenerateInsertForSqlServerTests.CustomerWithFields {
                FirstName = "Clark", LastName = "Kent", DateOfBirth = DateTime.Parse("06/18/1938")
            };

            var databaseCommand = TestHelpers.GetDatabaseCommand();

            // Act
            databaseCommand = databaseCommand.GenerateInsertForSQLite(customer);

            // Visual Assertion
            Trace.WriteLine(databaseCommand.DbCommand.CommandText);

            // Assert
            Assert.NotNull(databaseCommand.DbCommand.CommandText);
            Assert.That(databaseCommand.DbCommand.CommandText.Contains("INSERT"));
        }
        public void Should_Add_Parameters_To_The_DbCommand_And_To_The_Insert_Statement()
        {
            // Arrange
            var customer = new DbCommandExtensionsTests.GenerateInsertForSqlServerTests.CustomerWithFields { FirstName = "Clark", LastName = "Kent", DateOfBirth = DateTime.Parse( "06/18/1938" ) };

            var databaseCommand = TestHelpers.GetDatabaseCommand();

            // Act
            databaseCommand = databaseCommand.GenerateInsertForSQLite( customer, "[Person]" );

            // Visual Assertion
            Trace.WriteLine( databaseCommand.DbCommand.CommandText );

            // Assert
            var parameters = databaseCommand.DbCommand.Parameters.Cast<DbParameter>().ToList();

            Assert.That( parameters.FirstOrDefault( x => x.ParameterName.Contains( "@FirstName" ) ).Value.ToString() == customer.FirstName );
            Assert.That( parameters.FirstOrDefault( x => x.ParameterName.Contains( "@LastName" ) ).Value.ToString() == customer.LastName );
            Assert.That( parameters.FirstOrDefault( x => x.ParameterName.Contains( "@DateOfBirth" ) ).Value.ToString() == customer.DateOfBirth.ToString() );
            
            Assert.That( databaseCommand.DbCommand.CommandText.Contains( "@FirstName" ) );
            Assert.That( databaseCommand.DbCommand.CommandText.Contains( "@LastName" ) );
            Assert.That( databaseCommand.DbCommand.CommandText.Contains( "@DateOfBirth" ) );
        }