public void RollbackTo_CollectionModificationInvalidatesViewModel_RollbackValidatesViewModel() { var project1Title = "Title of project1"; var project1 = CreateProject(project1Title); EmployeeVM.InitializeFrom(CreateEmployee(projects: project1)); EmployeeVM.Revalidate(); Assert.IsTrue(EmployeeVM.IsValid); var rollbackPoint = EmployeeVM.UndoManager.GetRollbackPoint(); var project2 = CreateProject(project1Title); var project2VM = new ProjectVM(); project2VM.InitializeFrom(project2); EmployeeVM.Projects.Add(project2VM); Assert.IsFalse(EmployeeVM.IsValid); EmployeeVM.UndoManager.RollbackTo(rollbackPoint); Assert.IsTrue(EmployeeVM.IsValid); }
public void MultipleRollbackTo_WithMultipleRollbackPoints_RestoresRollbackPoints() { // Arrange var originalCustomer1Name = "Customer1"; var customer1 = CreateCustomer(originalCustomer1Name); var customer2 = CreateCustomer(); var originalProject1Title = "Project1"; var projects = new Project[] { CreateProject(originalProject1Title, customer1), CreateProject("Project2", customer2) }; var originalEmployeeName = "Name"; var employee = CreateEmployee(name: originalEmployeeName, projects: projects); EmployeeVM.InitializeFrom(employee); ProjectVM[] expectedProjectVMColl = EmployeeVM.Projects.ToArray(); // Act - Assert var employeeVMRollbackPoint = EmployeeVM.UndoManager.GetRollbackPoint(); var newProject = new ProjectVM(); newProject.InitializeFrom(new Project()); EmployeeVM.Projects.Add(newProject); EmployeeVM.Name = "ModifiedName"; ((IViewModel)EmployeeVM).Kernel.Refresh(); var project1VM = EmployeeVM .Projects .Single(x => x.Title == originalProject1Title); var projectVMRollbackPoint = project1VM.UndoManager.GetRollbackPoint(); project1VM.Title = "ModifiedTitle"; var customerVMRollbackPoint = project1VM.Customer.UndoManager.GetRollbackPoint(); project1VM.Customer.Name = "ModifiedName"; project1VM.Customer.UndoManager.RollbackTo(customerVMRollbackPoint); Assert.AreEqual(project1VM.Customer.Name, originalCustomer1Name); project1VM.UndoManager.RollbackTo(projectVMRollbackPoint); Assert.AreEqual(project1VM.Title, originalProject1Title); EmployeeVM.Projects.RemoveAt(0); EmployeeVM.Projects.Clear(); EmployeeVM.UndoManager.RollbackTo(employeeVMRollbackPoint); Assert.AreEqual(originalEmployeeName, EmployeeVM.Name); CollectionAssert.AreEqual(expectedProjectVMColl, EmployeeVM.Projects); }