public async Task GetRowsPendingInsertion() { // Setup: // ... Create a session with a proper query and metadata EditSession s = await GetBasicSession(); // ... Add a row creation s.CreateRow(); // If: I ask for the rows including the new rows EditRow[] rows = await s.GetRows(0, 6); // Then: // ... I should get back 6 rows Assert.Equal(6, rows.Length); // ... The last row should reflect that there's a new row var updatedRow = rows[5]; Assert.Equal(EditRow.EditRowState.DirtyInsert, updatedRow.State); // ... The other rows should be clean for (int i = 0; i < rows.Length - 1; i++) { Assert.Equal(EditRow.EditRowState.Clean, rows[i].State); } }
public async Task CreateRowDefaultTest() { // Setup: // ... We will have 3 columns DbColumnWrapper[] cols = { new DbColumnWrapper(new TestDbColumn("col1")), // No default new DbColumnWrapper(new TestDbColumn("col2")), // Has default (defined below) new DbColumnWrapper(new TestDbColumn("filler")) // Filler column so we can use the common code }; // ... Metadata provider will return 3 columns EditColumnMetadata[] metas = { new EditColumnMetadata // No default { DefaultValue = null, EscapedName = cols[0].ColumnName }, new EditColumnMetadata // Has default { DefaultValue = "default", EscapedName = cols[1].ColumnName }, new EditColumnMetadata { EscapedName = cols[2].ColumnName } }; var etm = new EditTableMetadata { Columns = metas, EscapedMultipartName = "tbl", IsMemoryOptimized = false }; etm.Extend(cols); // ... Create a result set var q = await Common.GetQuery(cols.Cast <DbColumn>().ToArray(), false); // ... Create a session from all this EditSession s = await Common.GetCustomSession(q, etm); // If: I add a row to the session, on a table that has defaults var result = s.CreateRow(); // Then: // ... Result should not be null, new row ID should be > 0 Assert.NotNull(result); Assert.True(result.NewRowId > 0); // ... There should be 3 default values (3 columns) Assert.NotEmpty(result.DefaultValues); Assert.Equal(3, result.DefaultValues.Length); // ... There should be specific values for each kind of default Assert.Null(result.DefaultValues[0]); Assert.Equal("default", result.DefaultValues[1]); }
public async Task CreateRowSuccess() { // Setup: Create a session with a proper query and metadata Query q = QueryExecution.Common.GetBasicExecutedQuery(); ResultSet rs = q.Batches[0].ResultSets[0]; EditTableMetadata etm = Common.GetCustomEditTableMetadata(rs.Columns.Cast <DbColumn>().ToArray()); EditSession s = await Common.GetCustomSession(q, etm); // If: I add a row to the session EditCreateRowResult result = s.CreateRow(); // Then: // ... The new ID should be equal to the row count Assert.Equal(rs.RowCount, result.NewRowId); // ... The next row ID should have been incremented Assert.Equal(rs.RowCount + 1, s.NextRowId); // ... There should be a new row create object in the cache Assert.Contains(result.NewRowId, s.EditCache.Keys); Assert.IsType <RowCreate>(s.EditCache[result.NewRowId]); // ... The default values should be returned (we will test this in depth below) Assert.NotEmpty(result.DefaultValues); }
public async Task CreateRowAddFailure() { // NOTE: This scenario should theoretically never occur, but is tested for completeness // Setup: // ... Create a session with a proper query and metadata Query q = QueryExecution.Common.GetBasicExecutedQuery(); ResultSet rs = q.Batches[0].ResultSets[0]; EditTableMetadata etm = Common.GetCustomEditTableMetadata(rs.Columns.Cast <DbColumn>().ToArray()); EditSession s = await Common.GetCustomSession(q, etm); // ... Add a mock edit to the edit cache to cause the .TryAdd to fail var mockEdit = new Mock <RowEditBase>().Object; s.EditCache[rs.RowCount] = mockEdit; // If: I create a row in the session // Then: // ... An exception should be thrown Assert.Throws <InvalidOperationException>(() => s.CreateRow()); // ... The mock edit should still exist Assert.Equal(mockEdit, s.EditCache[rs.RowCount]); // ... The next row ID should not have changes Assert.Equal(rs.RowCount, s.NextRowId); }
public void CreateRowNotInitialized() { // Setup: // ... Create a session without initializing Mock <IEditMetadataFactory> emf = new Mock <IEditMetadataFactory>(); EditSession s = new EditSession(emf.Object); // If: I ask to create a row without initializing // Then: I should get an exception Assert.Throws <InvalidOperationException>(() => s.CreateRow()); }
public async Task GetRowsAllNew() { // Setup: // ... Create a session with a query and metadata EditSession s = await GetBasicSession(); // ... Add a few row creations s.CreateRow(); s.CreateRow(); s.CreateRow(); // If: I ask for the rows included the new rows EditRow[] rows = await s.GetRows(5, 5); // Then: // ... I should get back 3 rows back Assert.Equal(3, rows.Length); // ... All the rows should be new Assert.All(rows, r => Assert.Equal(EditRow.EditRowState.DirtyInsert, r.State)); }