public async Task GetRowsPendingUpdate() { // Setup: // ... Create a session with a proper query and metadata EditSession s = await GetBasicSession(); // ... Add a cell update to it s.UpdateCell(1, 0, "foo"); // If: I ask for 3 rows from the session, skipping the first, including the updated one EditRow[] rows = await s.GetRows(1, 3); // Then: // ... I should get back 3 rows Assert.Equal(3, rows.Length); // ... The first row should reflect that there is an update pending // (More in depth testing is done in the RowUpdate class tests) var updatedRow = rows[0]; Assert.Equal(EditRow.EditRowState.DirtyUpdate, updatedRow.State); Assert.Equal("foo", updatedRow.Cells[0].DisplayValue); // ... The other rows should be clean for (int i = 1; i < rows.Length; i++) { Assert.Equal(EditRow.EditRowState.Clean, rows[i].State); } }
public async Task UpdateCellRowRevert() { // Setup: // ... Create a session with a proper query and metadata EditSession s = await GetBasicSession(); // ... Add a edit that we will say the edit was reverted if we update a cell var mockEdit = new Mock <RowEditBase>(); mockEdit.Setup(e => e.SetCell(It.IsAny <int>(), It.IsAny <string>())) .Returns(new EditUpdateCellResult { IsRowDirty = false }); s.EditCache[0] = mockEdit.Object; // If: I update a cell that will return an implicit revert s.UpdateCell(0, 0, null); // Then: // ... Set cell should have been called on the mock update once mockEdit.Verify(e => e.SetCell(0, null), Times.Once); // ... The mock update should no longer be in the edit cache Assert.Empty(s.EditCache); }
public void UpdateCellNotInitialized() { // Setup: // ... Create a session without initializing Mock <IEditMetadataFactory> emf = new Mock <IEditMetadataFactory>(); EditSession s = new EditSession(emf.Object); // If: I ask to update a cell without initializing // Then: I should get an exception Assert.Throws <InvalidOperationException>(() => s.UpdateCell(0, 0, "")); }
public async Task UpdateCellNew() { // Setup: // ... Create a session with a proper query and metadata EditSession s = await GetBasicSession(); // If: I update a cell on a row that does not have a pending edit s.UpdateCell(0, 0, ""); // Then: // ... A new update row edit should have been added to the cache Assert.Contains(0, s.EditCache.Keys); Assert.IsType <RowUpdate>(s.EditCache[0]); }
public async Task UpdateCellExisting() { // Setup: // ... Create a session with a proper query and metadata EditSession s = await GetBasicSession(); // ... Add a mock edit to the edit cache to cause the .TryAdd to fail var mockEdit = new Mock <RowEditBase>(); mockEdit.Setup(e => e.SetCell(It.IsAny <int>(), It.IsAny <string>())) .Returns(new EditUpdateCellResult { IsRowDirty = true }); s.EditCache[0] = mockEdit.Object; // If: I update a cell on a row that already has a pending edit s.UpdateCell(0, 0, null); // Then: // ... The mock update should still be in the cache // ... And it should have had set cell called on it Assert.Contains(mockEdit.Object, s.EditCache.Values); }