mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-07 01:25:41 -05:00
Implicit Revert Row Cleanup Logic (#297)
This change enhances the way that edit/updateCell and edit/revertCell operations are performed. ## **THE API BREAKING CHANGES**: * edit/updateCell now returns an EditCell (a DbCellValue with a dirty flag) and a row dirty flag. * edit/revertCell now returns an EditCell (a DbCellValue with a dirty flag) and a row dirty flag. If by setting the value of a cell via edit/updateCell the row no longer has any edits (an "implicit revert"), the entire row's edit will be removed from the cache. Additionally, if by requesting edit/revert all the pending edits for a row are removed, the entire row's edit will be removed from the cache. This will prevent issues where committing will generate an invalid script because it has no pending changes. * Adding EditCell class Returning EditCell with EditUpdateCellResult * Adding code that will remove a row update if the row is clean after a cell update * Adding code that will return an EditCell and row dirty flag when a cell is reverted. If the row is reverted by the cell revert, the pending update will be removed * Comments for edit cell * Changes as per pull request comments
This commit is contained in:
@@ -627,6 +627,30 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.RevertCell(0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RevertCellRowRevert()
|
||||
{
|
||||
// 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.RevertCell(It.IsAny<int>()))
|
||||
.Returns(new EditRevertCellResult {IsRowDirty = false});
|
||||
s.EditCache[0] = mockEdit.Object;
|
||||
|
||||
// If: I update a cell that will return an implicit revert
|
||||
s.RevertCell(0, 0);
|
||||
|
||||
// Then:
|
||||
// ... Set cell should have been called on the mock update once
|
||||
mockEdit.Verify(e => e.RevertCell(0), Times.Once);
|
||||
|
||||
// ... The mock update should no longer be in the edit cache
|
||||
Assert.Empty(s.EditCache);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Update Cell Tests
|
||||
@@ -653,7 +677,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... 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>()));
|
||||
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
|
||||
@@ -681,6 +706,32 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.IsType<RowUpdate>(s.EditCache[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region SubSet Tests
|
||||
|
||||
Reference in New Issue
Block a user