public void Should_Handle_Generating_Inserts_For_A_Dynamic_ExpandoObject() { // Arrange const string createSchemaSql = @" DROP TABLE IF EXISTS Customer; CREATE TABLE IF NOT EXISTS Customer ( CustomerId INT NOT NULL AUTO_INCREMENT, FirstName NVARCHAR(120) NOT NULL, LastName NVARCHAR(120) NOT NULL, DateOfBirth DATETIME NOT NULL, PRIMARY KEY ( CustomerId ) ); "; Sequelocity.GetDatabaseCommand(ConnectionStringsNames.MySqlConnectionString) .SetCommandText(createSchemaSql) .ExecuteNonQuery(); dynamic newCustomer = new ExpandoObject(); newCustomer.FirstName = "Clark"; newCustomer.LastName = "Kent"; newCustomer.DateOfBirth = DateTime.Parse("06/18/1938"); // Act var databaseCommand = Sequelocity.GetDatabaseCommand(ConnectionStringsNames.MySqlConnectionString); databaseCommand = DatabaseCommandExtensions.GenerateInsertForMySql(databaseCommand, newCustomer, "Customer"); var customerId = databaseCommand .ExecuteScalar <int>(); const string selectCustomerQuery = @" SELECT CustomerId, FirstName, LastName, DateOfBirth FROM Customer; "; var customer = Sequelocity.GetDatabaseCommand(ConnectionStringsNames.MySqlConnectionString) .SetCommandText(selectCustomerQuery) .ExecuteToObject <Customer>(); // Assert Assert.That(customerId == 1); Assert.That(customer.CustomerId == 1); Assert.That(customer.FirstName == newCustomer.FirstName); Assert.That(customer.LastName == newCustomer.LastName); Assert.That(customer.DateOfBirth == newCustomer.DateOfBirth); }
public void Should_Handle_Generating_Inserts_For_A_Dynamic_Object() { // Arrange const string createSchemaSql = @" CREATE TABLE IF NOT EXISTS Customer ( CustomerId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, FirstName NVARCHAR(120) NOT NULL, LastName NVARCHAR(120) NOT NULL, DateOfBirth DATETIME NOT NULL );"; var dbConnection = Sequelocity.CreateDbConnection(ConnectionStringsNames.SqliteInMemoryDatabaseConnectionString); new DatabaseCommand(dbConnection) .SetCommandText(createSchemaSql) .ExecuteNonQuery(true); dynamic newCustomer = new ExpandoObject(); newCustomer.FirstName = "Clark"; newCustomer.LastName = "Kent"; newCustomer.DateOfBirth = DateTime.Parse("06/18/1938"); // Act var databaseCommand = new DatabaseCommand(dbConnection); databaseCommand = DatabaseCommandExtensions.GenerateInsertForSQLite(databaseCommand, newCustomer, "[Customer]"); var customerId = databaseCommand .ExecuteScalar(true) .ToInt(); const string selectCustomerQuery = @" SELECT CustomerId, FirstName, LastName, DateOfBirth FROM Customer; "; var customer = new DatabaseCommand(dbConnection) .SetCommandText(selectCustomerQuery) .ExecuteToObject <Customer>(); // Assert Assert.That(customerId == 1); Assert.That(customer.CustomerId == 1); Assert.That(customer.FirstName == newCustomer.FirstName); Assert.That(customer.LastName == newCustomer.LastName); Assert.That(customer.DateOfBirth == newCustomer.DateOfBirth); }
public void Should_Handle_Generating_Inserts_For_A_Dynamic_Object() { // Arrange const string createSchemaSql = @" IF ( EXISTS ( SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'Customer' ) ) BEGIN DROP TABLE Customer END IF ( NOT EXISTS ( SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'Customer') ) BEGIN CREATE TABLE Customer ( CustomerId INT NOT NULL IDENTITY(1,1) PRIMARY KEY, FirstName NVARCHAR(120) NOT NULL, LastName NVARCHAR(120) NOT NULL, DateOfBirth DATETIME NOT NULL ); END "; Sequelocity.GetDatabaseCommand(ConnectionStringsNames.SqlServerConnectionString) .SetCommandText(createSchemaSql) .ExecuteNonQuery(); dynamic newCustomer = new ExpandoObject(); newCustomer.FirstName = "Clark"; newCustomer.LastName = "Kent"; newCustomer.DateOfBirth = DateTime.Parse("06/18/1938"); // Act var databaseCommand = Sequelocity.GetDatabaseCommand(ConnectionStringsNames.SqlServerConnectionString); databaseCommand = DatabaseCommandExtensions.GenerateInsertForSqlServer(databaseCommand, newCustomer, "[Customer]"); var customerId = databaseCommand .ExecuteScalar <int>(); const string selectCustomerQuery = @" SELECT CustomerId, FirstName, LastName, DateOfBirth FROM Customer; "; var customer = Sequelocity.GetDatabaseCommand(ConnectionStringsNames.SqlServerConnectionString) .SetCommandText(selectCustomerQuery) .ExecuteToObject <Customer>(); // Assert Assert.That(customerId == 1); Assert.That(customer.CustomerId == 1); Assert.That(customer.FirstName == newCustomer.FirstName); Assert.That(customer.LastName == newCustomer.LastName); Assert.That(customer.DateOfBirth == newCustomer.DateOfBirth); }