public void I_Cannot_Add_Duplicate_Column_Value_Pair() { var columnDefaults = new ColumnDefaults(); var columnDefault = new KeyValuePair <string, object>("Hello", "World"); columnDefaults.AddDefault(columnDefault); columnDefaults.AddDefault(columnDefault); }
public void InsertDataWithNullsWikiExample() { // Setup the Database Tester object using the MS SQL implementation var connectionstring = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=tempdb;Integrated Security=SSPI;"; VulcanAnalytics.DBTester.DatabaseTester tester = new VulcanAnalytics.DBTester.MsSqlDatabaseTester(connectionstring); // Create a table to insert data into tester.ExecuteStatementWithoutResult("drop table if exists [dbo].[TestPerson];"); tester.ExecuteStatementWithoutResult("create table [dbo].[TestPerson]([TestId] int, [Name] varchar(255), [ModifiedDate] datetime, [ModifiedBy] sysname);"); // Set the defaults for the insert var defaults = new ColumnDefaults(); defaults.AddDefault(new KeyValuePair <string, object>("ModifiedBy", "DarrenComeau")); // Parameters for InsertData method var schemaName = "dbo"; var tableName = "TestPerson"; var columns = new string[] { "TestId", "Name", "ModifiedDate" }; var data = new object[] { new Object[] { 1, "Joe", "2018-09-28T12:49:13.576" }, new Object[] { 2, null, "2018-10-01T18:31:29.256" } }; // Call the Insertdata method to insert the rows tester.InsertData(schemaName, tableName, columns, data, defaults); }
public void Inserting_Defaults_Correctly_Handles_Single_Quotes() { var expectedValue = "Hello, 'World'."; var schemaName = "dbo"; var tableName = "testtable"; DropAndCreateTestTable(schemaName, tableName, "[col1manual] int, [col2withdefault] varchar(200)"); var columns = new string[] { "col1manual" }; var data = new object[] { new object[] { 1 } }; var defaults = new ColumnDefaults(); defaults.AddDefault(new KeyValuePair <string, object>("col2withdefault", expectedValue)); tester.InsertData(schemaName, tableName, columns, data, defaults); var results = tester.ExecuteStatementWithResult(string.Format("select * from {0}.{1};", schemaName, tableName)); var actualValue = results.Tables[0].Rows[0]["col2withdefault"]; Assert.AreEqual(expectedValue, actualValue); }
public void I_Can_Insert_Several_Rows_With_Defaults_And_No_Other_Data() { var expectedCount = 5; var schemaName = "dbo"; var tableName = "testtable"; DropAndCreateTestTable(schemaName, tableName, "[col1manual] int, [col2withdefault] varchar(200)"); var columns = new string[0]; var data = new object[] { null, null, null, null, null }; var defaults = new ColumnDefaults(); defaults.AddDefault(new KeyValuePair <string, object>("col2withdefault", "defaultvalue")); tester.InsertData(schemaName, tableName, columns, data, defaults); var results = tester.ExecuteStatementWithResult(string.Format("select * from {0}.{1};", schemaName, tableName)); var actualCount = results.Tables[0].Rows.Count; Assert.AreEqual(expectedCount, actualCount); }
public void Data_Specified_For_A_Column_Overrides_The_Default_Data() { var expectedValue = "Hello, World."; var schemaName = "dbo"; var tableName = "testtable"; DropAndCreateTestTable(schemaName, tableName, "[col1manual] int, [col2withdefault] varchar(200)"); var columns = new string[] { "col1manual", "col2withdefault" }; var data = new object[] { new object[] { 1, expectedValue } }; var defaults = new ColumnDefaults(); defaults.AddDefault(new KeyValuePair <string, object>("col2withdefault", "Column's default value")); tester.InsertData(schemaName, tableName, columns, data, defaults); var results = tester.ExecuteStatementWithResult(string.Format("select * from {0}.{1};", schemaName, tableName)); var actualValue = results.Tables[0].Rows[0]["col2withdefault"]; Assert.AreEqual(expectedValue, actualValue); }
public void ColumnDefaults_When_Assigned_Is_Not_Empty() { var columnDefaults = new ColumnDefaults(); columnDefaults.AddDefault(new KeyValuePair <string, object>("Hello", "World")); Assert.IsFalse(columnDefaults.IsEmpty); }
public void I_Can_Add_And_Retrieve_A_Column_Value_Pair() { var columnDefaults = new ColumnDefaults(); var columnDefault = new KeyValuePair <string, object>("Hello", "World"); columnDefaults.AddDefault(columnDefault); foreach (var defaultColumn in columnDefaults) { Assert.AreEqual(columnDefault, defaultColumn); } }
public void I_Receive_An_Error_When_No_Rows_Supplied_Even_With_Defaults() { var schemaName = "dbo"; var tableName = "testtable"; DropAndCreateTestTable(schemaName, tableName, "[col1manual] int, [col2withdefault] varchar(200)"); var columns = new string[] { "col1manual" }; var data = new object[0]; var defaults = new ColumnDefaults(); defaults.AddDefault(new KeyValuePair <string, object>("col2withdefault", "defaultvalue")); tester.InsertData(schemaName, tableName, columns, data, defaults); }
public void I_Can_Loop_Over_All_Defaults() { var expectedCount = 4; var columnDefaults = new ColumnDefaults(); var i = 0; while (i < expectedCount) { var keyString = string.Format("Hello {0}", i); columnDefaults.AddDefault(new KeyValuePair <string, object>(keyString, "World")); i++; } var actualCount = 0; foreach (var columnDefault in columnDefaults) { actualCount++; } Assert.AreEqual(expectedCount, actualCount); }