Ejemplo n.º 1
0
        public async Task GetVerifyQuery()
        {
            // Setup: Create a row update and set the first row cell to have values
            // ... other than "1" for testing purposes (simulated select query result).
            Common.TestDbColumnsWithTableMetadata data = new Common.TestDbColumnsWithTableMetadata(false, false, 0, 0);
            var rs = await Common.GetResultSet(data.DbColumns, false);

            RowUpdate ru = new RowUpdate(0, rs, data.TableMetadata);

            object[][] rows =
            {
                new object[] { "2", "0", "0" },
            };
            var testResultSet = new TestResultSet(data.DbColumns, rows);
            var newRowReader  = new TestDbDataReader(new[] { testResultSet }, false);
            await ru.ApplyChanges(newRowReader);

            // ... Create a row delete.
            RowDelete rd           = new RowDelete(0, rs, data.TableMetadata);
            int       expectedKeys = 3;

            // If: I generate a verify command
            String verifyCommand = rd.GetVerifyScript();

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

            // ... It should be formatted into an where script
            string regexTest = @"SELECT COUNT \(\*\) FROM (.+) WHERE (.+)";
            Regex  r         = new Regex(regexTest);
            var    m         = r.Match(verifyCommand);

            Assert.True(m.Success);

            // ... There should be a table
            string tbl = m.Groups[1].Value;

            Assert.Equal(data.TableMetadata.EscapedMultipartName, tbl);

            // ... There should be as many where components as there are keys
            string[] whereComponents = m.Groups[2].Value.Split(new[] { "AND" }, StringSplitOptions.None);
            Assert.Equal(expectedKeys, whereComponents.Length);

            // ... Mock db connection for building the command
            var mockConn = new TestSqlConnection(new[] { testResultSet });

            // If: I attempt to get a command for a simulated delete of a row with duplicates.
            // Then: The Command will throw an exception as it detects there are
            // ... 2 or more rows with the same value in the simulated query results data.
            Assert.Throws <EditDataDeleteException>(() => rd.GetCommand(mockConn));
        }
Ejemplo n.º 2
0
        public async Task ApplyChangesNullReader()
        {
            // Setup:
            // ... Create a row update (no cell updates needed)
            var data = new Common.TestDbColumnsWithTableMetadata(false, true, 0, 0);
            var rs   = await Common.GetResultSet(data.DbColumns, true);

            RowUpdate ru = new RowUpdate(0, rs, data.TableMetadata);

            // If: I  ask for the changes to be applied with a null db reader
            // Then: I should get an exception
            await Assert.ThrowsAsync <ArgumentNullException>(() => ru.ApplyChanges(null));
        }
Ejemplo n.º 3
0
        public async Task ApplyChangesNullReader()
        {
            // Setup:
            // ... Create a row update (no cell updates needed)
            var columns = Common.GetColumns(true);
            var rs      = await Common.GetResultSet(columns, true);

            var       etm = Common.GetStandardMetadata(columns);
            RowUpdate ru  = new RowUpdate(0, rs, etm);

            // If: I  ask for the changes to be applied with a null db reader
            // Then: I should get an exception
            await Assert.ThrowsAsync <ArgumentNullException>(() => ru.ApplyChanges(null));
        }
Ejemplo n.º 4
0
        public async Task ApplyChanges(bool includeIdentity)
        {
            // Setup:
            // ... Create a row update (no cell updates needed)
            var data = new Common.TestDbColumnsWithTableMetadata(false, includeIdentity, 0, 0);
            var rs   = await Common.GetResultSet(data.DbColumns, includeIdentity);

            RowUpdate ru = new RowUpdate(0, rs, data.TableMetadata);
            long      oldBytesWritten = rs.totalBytesWritten;

            // ... Setup a db reader for the result of an update
            var newRowReader = Common.GetNewRowDataReader(data.DbColumns, includeIdentity);

            // If: I ask for the change to be applied
            await ru.ApplyChanges(newRowReader);

            // Then:
            // ... The result set should have the same number of rows as before
            Assert.Equal(1, rs.RowCount);
            Assert.True(oldBytesWritten < rs.totalBytesWritten);
        }