コード例 #1
0
        public async Task GetScriptTest(bool isMemoryOptimized)
        {
            // Setup: Create a fake table to update
            var       data = new Common.TestDbColumnsWithTableMetadata(isMemoryOptimized, true, 0, 0);
            ResultSet rs   = await Common.GetResultSet(data.DbColumns, true);

            // If: I ask for a script to be generated for update
            RowUpdate ru = new RowUpdate(0, rs, data.TableMetadata);

            Common.AddCells(ru, 1);
            string script = ru.GetScript();

            // Then:
            // ... The script should not be null
            Assert.NotNull(script);

            // ... It should be formatted as an update script
            string regexString = isMemoryOptimized
                ? @"UPDATE (.+) WITH \(SNAPSHOT\) SET (.*) WHERE .+"
                : @"UPDATE (.+) SET (.*) WHERE .+";
            Regex r = new Regex(regexString);
            var   m = r.Match(script);

            Assert.True(m.Success);

            // ... It should have 3 updates
            string tbl     = m.Groups[1].Value;
            string updates = m.Groups[2].Value;

            string[] updateSplit = updates.Split(',');
            Assert.Equal(data.TableMetadata.EscapedMultipartName, tbl);
            Assert.Equal(3, updateSplit.Length);
            Assert.All(updateSplit, s => Assert.Equal(2, s.Split('=').Length));
        }
コード例 #2
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));
        }