public async Task SetCellImplicitRowRevertTests() { // Setup: Create a fake column to update DbColumn[] columns = Common.GetColumns(true); ResultSet rs = await Common.GetResultSet(columns, true); EditTableMetadata etm = Common.GetStandardMetadata(columns); // If: // ... I add updates to one cell in the row RowUpdate ru = new RowUpdate(0, rs, etm); ru.SetCell(1, "qqq"); // ... Then I update the cell to its original value var eucr = ru.SetCell(1, (string)rs.GetRow(0)[1].RawObject); // Then: // ... An edit cell should have been returned Assert.NotNull(eucr); Assert.NotNull(eucr.Cell); // ... The old value should be returned Assert.Equal(rs.GetRow(0)[1].DisplayValue, eucr.Cell.DisplayValue); Assert.False(eucr.Cell.IsNull); // ... The cell should be clean Assert.False(eucr.Cell.IsDirty); // ... The row should be clean Assert.False(eucr.IsRowDirty); // TODO: Make sure that the script and command things will return null }
public async Task RevertCellThatWasSet() { // Setup: // ... Create a row update var columns = Common.GetColumns(false); var rs = await Common.GetResultSet(columns, false); var etm = Common.GetStandardMetadata(columns); RowUpdate ru = new RowUpdate(0, rs, etm); ru.SetCell(0, "qqq"); ru.SetCell(1, "qqq"); // If: I attempt to revert a cell that was set EditRevertCellResult result = ru.RevertCell(0); // Then: // ... We should get a result back Assert.NotNull(result); // ... We should get the original value back // @TODO: Check for a default value when we support it Assert.NotNull(result.Cell); Assert.Equal(rs.GetRow(0)[0].DisplayValue, result.Cell.DisplayValue); // ... The row should be dirty still Assert.True(result.IsRowDirty); // ... The cell should no longer be set Assert.DoesNotContain(0, ru.cellUpdates.Keys); }
public async Task SetCell() { // Setup: Create a row update RowUpdate ru = await GetStandardRowUpdate(); // If: I set a cell that can be updated EditUpdateCellResult eucr = ru.SetCell(0, "col1"); // Then: // ... A edit cell was returned Assert.NotNull(eucr); Assert.NotNull(eucr.Cell); // ... The new value we provided should be returned Assert.Equal("col1", eucr.Cell.DisplayValue); Assert.False(eucr.Cell.IsNull); // ... The row is still dirty Assert.True(eucr.IsRowDirty); // ... The cell should be dirty Assert.True(eucr.Cell.IsDirty); // ... There should be a cell update in the cell list Assert.Contains(0, ru.cellUpdates.Keys); Assert.NotNull(ru.cellUpdates[0]); }
public async Task RevertCellRevertsRow() { // Setup: // ... Create a row update var data = new Common.TestDbColumnsWithTableMetadata(false, false, 0, 0); var rs = await Common.GetResultSet(data.DbColumns, false); RowUpdate ru = new RowUpdate(0, rs, data.TableMetadata); ru.SetCell(0, "qqq"); // If: I attempt to revert a cell that was set EditRevertCellResult result = ru.RevertCell(0); // Then: // ... We should get a result back Assert.NotNull(result); // ... We should get the original value back // @TODO: Check for a default value when we support it Assert.NotNull(result.Cell); Assert.Equal(rs.GetRow(0)[0].DisplayValue, result.Cell.DisplayValue); // ... The row should now be reverted Assert.False(result.IsRowDirty); // ... The cell should no longer be set Assert.DoesNotContain(0, ru.cellUpdates.Keys); }
[InlineData(100)] // Way too large value public async Task SetCellOutOfRange(int columnId) { // Setup: Generate a row create RowUpdate ru = await GetStandardRowUpdate(); // If: I attempt to set a cell on a column that is out of range, I should get an exception Assert.Throws <ArgumentOutOfRangeException>(() => ru.SetCell(columnId, string.Empty)); }
public void SetCellHasCorrections() { // Setup: // ... Generate a result set with a single binary column DbColumn[] cols = { new TestDbColumn { DataType = typeof(byte[]), DataTypeName = "binary" } }; object[][] rows = { new object[] { new byte[] { 0x00 } } }; var testResultSet = new TestResultSet(cols, rows); var testReader = new TestDbDataReader(new[] { testResultSet }); var rs = new ResultSet(0, 0, MemoryFileSystem.GetFileStreamFactory()); rs.ReadResultToEnd(testReader, CancellationToken.None).Wait(); // ... Generate the metadata var etm = Common.GetStandardMetadata(cols); // ... Create the row update RowUpdate ru = new RowUpdate(0, rs, etm); // If: I set a cell in the newly created row to something that will be corrected EditUpdateCellResult eucr = ru.SetCell(0, "1000"); // Then: // ... A edit cell was returned Assert.NotNull(eucr); Assert.NotNull(eucr.Cell); // ... The value we used won't be returned Assert.NotEmpty(eucr.Cell.DisplayValue); Assert.NotEqual("1000", eucr.Cell.DisplayValue); Assert.False(eucr.Cell.IsNull); // ... The cell should be dirty Assert.True(eucr.Cell.IsDirty); // ... The row is still dirty Assert.True(eucr.IsRowDirty); // ... There should be a cell update in the cell list Assert.Contains(0, ru.cellUpdates.Keys); Assert.NotNull(ru.cellUpdates[0]); }
public async Task SetCellImplicitRevertTest() { // Setup: Create a fake table to update DbColumn[] columns = Common.GetColumns(true); ResultSet rs = await Common.GetResultSet(columns, true); EditTableMetadata etm = Common.GetStandardMetadata(columns); // If: // ... I add updates to all the cells in the row RowUpdate ru = new RowUpdate(0, rs, etm); Common.AddCells(ru, true); // ... Then I update a cell back to it's old value var eucr = ru.SetCell(1, (string)rs.GetRow(0)[1].RawObject); // Then: // ... A edit cell was returned Assert.NotNull(eucr); Assert.NotNull(eucr.Cell); // ... The new value we provided should be returned Assert.Equal(rs.GetRow(0)[1].DisplayValue, eucr.Cell.DisplayValue); Assert.False(eucr.Cell.IsNull); // ... The cell should be clean Assert.False(eucr.Cell.IsDirty); // ... The row is still dirty Assert.True(eucr.IsRowDirty); // ... It should be formatted as an update script Regex r = new Regex(@"UPDATE .+ SET (.*) WHERE"); var m = r.Match(ru.GetScript()); // ... It should have 2 updates string updates = m.Groups[1].Value; string[] updateSplit = updates.Split(','); Assert.Equal(2, updateSplit.Length); Assert.All(updateSplit, s => Assert.Equal(2, s.Split('=').Length)); }
public async Task GetEditRow() { // Setup: Create a row update with a cell set var columns = Common.GetColumns(false); var rs = await Common.GetResultSet(columns, false); var etm = Common.GetStandardMetadata(columns); RowUpdate ru = new RowUpdate(0, rs, etm); ru.SetCell(0, "foo"); // If: I attempt to get an edit row DbCellValue[] cells = rs.GetRow(0).ToArray(); EditRow er = ru.GetEditRow(cells); // Then: // ... The state should be dirty Assert.True(er.IsDirty); Assert.Equal(EditRow.EditRowState.DirtyUpdate, er.State); // ... The ID should be the same as the one provided Assert.Equal(0, er.Id); // ... The row should match the cells that were given, except for the updated cell Assert.Equal(cells.Length, er.Cells.Length); for (int i = 1; i < cells.Length; i++) { DbCellValue originalCell = cells[i]; DbCellValue outputCell = er.Cells[i]; Assert.Equal(originalCell.DisplayValue, outputCell.DisplayValue); Assert.Equal(originalCell.IsNull, outputCell.IsNull); // Note: No real need to check the RawObject property } // ... The updated cell should match what it was set to and be dirty EditCell newCell = er.Cells[0]; Assert.Equal("foo", newCell.DisplayValue); Assert.False(newCell.IsNull); Assert.True(newCell.IsDirty); }