public void Delete_NodeWithChildren_DeletedByCascade() { // Arrange var treeContext = new DbTreeContext(); var root = new TreeNode { Id = Guid.NewGuid() }; var node1 = new TreeNode { Id = Guid.NewGuid(), ParentId = root.Id }; var node2 = new TreeNode { Id = Guid.NewGuid(), ParentId = node1.Id }; treeContext.Tree.Add(root.Id, root); treeContext.Tree.Add(node1.Id, node1); treeContext.Tree.Add(node2.Id, node2); var dbTreeRepository = new DbTreeRepository(treeContext); // Act dbTreeRepository.Delete(root); // Assert Assert.That(treeContext.Tree[root.Id].IsDeleted, Is.True); Assert.That(treeContext.Tree[node1.Id].IsDeleted, Is.True); Assert.That(treeContext.Tree[node2.Id].IsDeleted, Is.True); }
public void Delete_NodeWithoutChildren_SetNodeDeleted() { // Arrange var treeContext = new DbTreeContext(); var root = new TreeNode { Id = Guid.NewGuid() }; treeContext.Tree.Add(root.Id, root); var dbTreeRepository = new DbTreeRepository(treeContext); // Act dbTreeRepository.Delete(root); // Assert Assert.That(treeContext.Tree[root.Id].IsDeleted, Is.True); }
public void Delete_NodeInAddedState_StateDoesNotChange() { // Arrange var treeContext = new DbTreeContext(); var root = new TreeNode { Id = Guid.NewGuid(), State = NodeState.Added }; treeContext.Tree.Add(root.Id, root); var dbTreeRepository = new DbTreeRepository(treeContext); // Act dbTreeRepository.Delete(root); // Assert Assert.That(treeContext.Tree[root.Id].State, Is.EqualTo(NodeState.Added)); Assert.That(treeContext.Tree[root.Id].IsDeleted, Is.True); }
public void Delete_NodeHasAnotherValue_ValueChanges() { // Arrange const string CHANGED_VALUE = "changed"; var treeContext = new DbTreeContext(); var root = new TreeNode { Id = Guid.NewGuid(), State = NodeState.Unchanged, Value = "unchanged" }; treeContext.Tree.Add(root.Id, root); var dbTreeRepository = new DbTreeRepository(treeContext); // Act dbTreeRepository.Delete(new TreeNode { Id = root.Id, IsDeleted = true, Value = CHANGED_VALUE }); // Assert Assert.That(root.Value, Is.EqualTo(CHANGED_VALUE)); }