public async Task GetScript(bool includeIdentity) { // Setup: Generate the parameters for the row create const long rowId = 100; DbColumn[] columns = Common.GetColumns(includeIdentity); ResultSet rs = await Common.GetResultSet(columns, includeIdentity); EditTableMetadata etm = Common.GetStandardMetadata(columns); // If: I ask for a script to be generated without an identity column RowCreate rc = new RowCreate(rowId, rs, etm); Common.AddCells(rc, includeIdentity); string script = rc.GetScript(); // Then: // ... The script should not be null, Assert.NotNull(script); // ... It should be formatted as an insert script Regex r = new Regex(@"INSERT INTO (.+)\((.*)\) VALUES \((.*)\)"); var m = r.Match(script); Assert.True(m.Success); // ... It should have 3 columns and 3 values (regardless of the presence of an identity col) string tbl = m.Groups[1].Value; string cols = m.Groups[2].Value; string vals = m.Groups[3].Value; Assert.Equal(etm.EscapedMultipartName, tbl); Assert.Equal(3, cols.Split(',').Length); Assert.Equal(3, vals.Split(',').Length); }
public async Task GetScriptMissingCell() { // Setup: Generate the parameters for the row create RowCreate rc = await GetStandardRowCreate(); // If: I ask for a script to be generated without setting any values // Then: An exception should be thrown for missing cells Assert.Throws <InvalidOperationException>(() => rc.GetScript()); }
public async Task GetScriptMissingCell(bool includeIdentity, int defaultCols, int nullableCols, int valuesToSkipSetting) { // Setup: Generate the parameters for the row create var data = new Common.TestDbColumnsWithTableMetadata(false, includeIdentity, defaultCols, nullableCols); var rs = await Common.GetResultSet(data.DbColumns, includeIdentity); RowCreate rc = new RowCreate(100, rs, data.TableMetadata); // If: I ask for a script to be generated without setting any values // Then: An exception should be thrown for missing cells Assert.Throws <InvalidOperationException>(() => rc.GetScript()); }
public async Task GetScript(bool includeIdentity, int colsWithDefaultConstraints, int colsThatAllowNull, int valuesToSkipSetting, RegexExpectedOutput expectedOutput) { // Setup: // ... Generate the parameters for the row create Common.TestDbColumnsWithTableMetadata data = new Common.TestDbColumnsWithTableMetadata(false, includeIdentity, colsWithDefaultConstraints, colsThatAllowNull); ResultSet rs = await Common.GetResultSet(data.DbColumns, includeIdentity); // ... Create a row create and set the appropriate number of cells RowCreate rc = new RowCreate(100, rs, data.TableMetadata); Common.AddCells(rc, valuesToSkipSetting); // If: I ask for the script for the row insert string script = rc.GetScript(); // Then: // ... The script should not be null Assert.NotNull(script); // ... The script should match the expected regex output ValidateScriptAgainstRegex(script, expectedOutput); }