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 RevertCellThatWasSet(int defaultCols)
        {
            // Setup:
            // ... Generate the parameters for the row create
            Common.TestDbColumnsWithTableMetadata data = new Common.TestDbColumnsWithTableMetadata(false, false, defaultCols, 0);
            ResultSet rs = await Common.GetResultSet(data.DbColumns, false);

            RowCreate rc = new RowCreate(100, rs, data.TableMetadata);

            rc.SetCell(0, "1");

            // If: I attempt to revert a cell that was set
            EditRevertCellResult result = rc.RevertCell(0);

            // Then:
            // ... We should get a result back
            Assert.NotNull(result);

            // ... We should get back an edit cell with a value based on the default value
            string expectedDisplayValue = defaultCols > 0 ? Common.DefaultValue : string.Empty;

            Assert.NotNull(result.Cell);
            Assert.Equal(expectedDisplayValue, result.Cell.DisplayValue);
            Assert.False(result.Cell.IsNull);    // TODO: Modify to support null defaults

            // ... The row should be dirty
            Assert.True(result.IsRowDirty);

            // ... The cell should no longer be set
            Assert.Null(rc.newCells[0]);
        }
        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 GetEditRowWithAdditions()
        {
            // Setp: Generate a row create with a cell added to it
            RowCreate rc = await GetStandardRowCreate();

            const string setValue = "foo";

            rc.SetCell(0, setValue);

            // If: I request an edit row from the row create
            EditRow er = rc.GetEditRow(null);

            // Then:
            // ... The row should not be null and contain the same number of cells as columns
            Assert.NotNull(er);
            Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);

            // ... The row should not be clean
            Assert.True(er.IsDirty);
            Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);

            // ... The row should have a single non-empty cell at the beginning that is dirty
            Assert.Equal(setValue, er.Cells[0].DisplayValue);
            Assert.False(er.Cells[0].IsNull);
            Assert.True(er.Cells[0].IsDirty);

            // ... The rest of the cells should be blank, but dirty
            for (int i = 1; i < er.Cells.Length; i++)
            {
                EditCell ec = er.Cells[i];
                Assert.Equal(string.Empty, ec.DisplayValue);
                Assert.False(ec.IsNull);
                Assert.True(ec.IsDirty);
            }
        }
        [InlineData(100)]       // Way too large value
        public async Task SetCellOutOfRange(int columnId)
        {
            // Setup: Generate a row create
            RowCreate rc = await GetStandardRowCreate();

            // If: I attempt to set a cell on a column that is out of range, I should get an exception
            Assert.Throws <ArgumentOutOfRangeException>(() => rc.SetCell(columnId, string.Empty));
        }
Exemple #6
0
        /// <summary>
        /// Creates a new row update and adds it to the update cache
        /// </summary>
        /// <exception cref="InvalidOperationException">If inserting into cache fails</exception>
        /// <returns>The internal ID of the newly created row</returns>
        public EditCreateRowResult CreateRow()
        {
            ThrowIfNotInitialized();

            // Create a new row ID (atomically, since this could be accesses concurrently)
            long newRowId = NextRowId++;

            // Create a new row create update and add to the update cache
            RowCreate newRow = new RowCreate(newRowId, associatedResultSet, objectMetadata);

            if (!EditCache.TryAdd(newRowId, newRow))
            {
                // Revert the next row ID
                NextRowId--;
                throw new InvalidOperationException(SR.EditDataFailedAddRow);
            }

            // Set the default values of the row if we know them
            string[] defaultValues = new string[objectMetadata.Columns.Length];
            for (int i = 0; i < objectMetadata.Columns.Length; i++)
            {
                EditColumnMetadata col = objectMetadata.Columns[i];

                // If the column is calculated, return the calculated placeholder as the display value
                if (col.IsCalculated.HasTrue())
                {
                    defaultValues[i] = SR.EditDataComputedColumnPlaceholder;
                }
                else
                {
                    if (col.DefaultValue != null)
                    {
                        newRow.SetCell(i, col.DefaultValue);
                    }
                    defaultValues[i] = col.DefaultValue;
                }
            }

            EditCreateRowResult output = new EditCreateRowResult
            {
                NewRowId      = newRowId,
                DefaultValues = defaultValues
            };

            return(output);
        }
        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]);
        }
        public async Task RevertCellThatWasSet()
        {
            // Setup: Generate the row create
            RowCreate rc = await GetStandardRowCreate();

            rc.SetCell(0, "1");

            // If: I attempt to revert a cell that was set
            EditRevertCellResult result = rc.RevertCell(0);

            // Then:
            // ... We should get a result back
            Assert.NotNull(result);

            // ... We should get a null cell back
            // @TODO: Check for a default value when we support it
            Assert.Null(result.Cell);

            // ... The row should be dirty
            Assert.True(result.IsRowDirty);

            // ... The cell should no longer be set
            Assert.Null(rc.newCells[0]);
        }
        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]);
        }