public async Task SetCellNoChange() { // Setup: Generate a row create RowCreate rc = await GetStandardRowCreate(); // If: I set a cell in the newly created row to something that doesn't need changing const string updateValue = "1"; EditUpdateCellResult eucr = rc.SetCell(0, updateValue); // Then: // ... The returned value should be equal to what we provided Assert.NotNull(eucr); Assert.NotNull(eucr.Cell); Assert.Equal(updateValue, eucr.Cell.DisplayValue); Assert.False(eucr.Cell.IsNull); // ... The returned value should be dirty Assert.NotNull(eucr.Cell.IsDirty); // ... The row should still be dirty Assert.True(eucr.IsRowDirty); // ... There should be a cell update in the cell list Assert.NotNull(rc.newCells[0]); }
public async Task SetCellNull() { // Setup: Generate a row create var data = new Common.TestDbColumnsWithTableMetadata(false, false, 0, 3); var rs = await Common.GetResultSet(data.DbColumns, false); var rc = new RowCreate(100, rs, data.TableMetadata); // If: I set a cell in the newly created row to null const string nullValue = "NULL"; EditUpdateCellResult eucr = rc.SetCell(0, nullValue); // Then: // ... The returned value should be equal to what we provided Assert.NotNull(eucr); Assert.NotNull(eucr.Cell); Assert.Equal(nullValue, eucr.Cell.DisplayValue); Assert.True(eucr.Cell.IsNull); // ... The returned value should be dirty Assert.NotNull(eucr.Cell.IsDirty); // ... The row should still be dirty Assert.True(eucr.IsRowDirty); // ... There should be a cell update in the cell list Assert.NotNull(rc.newCells[0]); }
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 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 SetCellHasCorrections() { // Setup: // ... Generate a result set with a single binary column DbColumn[] cols = { new TestDbColumn { DataType = typeof(byte[]), DataTypeName = "binary" } }; object[][] rows = {}; var testResultSet = new TestResultSet(cols, rows); var testReader = new TestDbDataReader(new[] { testResultSet }, false); var rs = new ResultSet(0, 0, MemoryFileSystem.GetFileStreamFactory()); await rs.ReadResultToEnd(testReader, CancellationToken.None); // ... Generate the metadata var etm = Common.GetCustomEditTableMetadata(cols); // ... Create the row create RowCreate rc = new RowCreate(100, rs, etm); // If: I set a cell in the newly created row to something that will be corrected EditUpdateCellResult eucr = rc.SetCell(0, "1000"); // Then: // ... The returned value should be equal to what we provided Assert.NotNull(eucr); Assert.NotNull(eucr.Cell); Assert.NotEqual("1000", eucr.Cell.DisplayValue); Assert.False(eucr.Cell.IsNull); // ... The returned value should be dirty Assert.NotNull(eucr.Cell.IsDirty); // ... The row should still be dirty Assert.True(eucr.IsRowDirty); // ... There should be a cell update in the cell list Assert.NotNull(rc.newCells[0]); }
/// <summary> /// Performs an update to a specific cell in a row. If the row has not already been /// initialized with a record in the update cache, one is created. /// </summary> /// <exception cref="InvalidOperationException">If adding a new update row fails</exception> /// <exception cref="ArgumentOutOfRangeException"> /// If the row that is requested to be edited is beyond the rows in the results and the /// rows that are being added. /// </exception> /// <param name="rowId">The internal ID of the row to edit</param> /// <param name="columnId">The ordinal of the column to edit in the row</param> /// <param name="newValue">The new string value of the cell to update</param> public EditUpdateCellResult UpdateCell(long rowId, int columnId, string newValue) { ThrowIfNotInitialized(); // Sanity check to make sure that the row ID is in the range of possible values if (rowId >= NextRowId || rowId < 0) { throw new ArgumentOutOfRangeException(nameof(rowId), SR.EditDataRowOutOfRange); } // Attempt to get the row that is being edited, create a new update object if one // doesn't exist // NOTE: This *must* be done as a lambda. RowUpdate creation requires that the row // exist in the result set. We only want a new RowUpdate to be created if the edit // doesn't already exist in the cache RowEditBase editRow = EditCache.GetOrAdd(rowId, key => new RowUpdate(rowId, associatedResultSet, objectMetadata)); // Update the row EditUpdateCellResult result = editRow.SetCell(columnId, newValue); CleanupEditIfRowClean(rowId, result); return(result); }
public async Task SetCellNull() { // Setup: Generate a row create RowCreate rc = await GetStandardRowCreate(); // If: I set a cell in the newly created row to null EditUpdateCellResult eucr = rc.SetCell(0, "NULL"); // Then: // ... The returned value should be equal to what we provided Assert.NotNull(eucr); Assert.NotNull(eucr.Cell); Assert.NotEmpty(eucr.Cell.DisplayValue); Assert.True(eucr.Cell.IsNull); // ... The returned value should be dirty Assert.NotNull(eucr.Cell.IsDirty); // ... The row should still be dirty Assert.True(eucr.IsRowDirty); // ... There should be a cell update in the cell list Assert.NotNull(rc.newCells[0]); }