// ReSharper disable InconsistentNaming public void MainViewmodel_UnitTest_DeleteUnassignedResource_ResourceRepositoryDeleteResourceCalled() // ReSharper restore InconsistentNaming { //Isolate delete unassigned resource as a functional unit CreateFullExportsAndVm(); SetupForDelete(); var unassignedResource = new Mock<IContextualResourceModel>(); var repo = new Mock<IResourceRepository>(); var env = new Mock<IEnvironmentModel>(); unassignedResource.Setup(res => res.Category).Returns(string.Empty); unassignedResource.Setup(resource => resource.Environment).Returns(env.Object); repo.Setup(repository => repository.DeleteResource(unassignedResource.Object)).Returns(MakeMsg("<DataList>Success</DataList>")).Verifiable(); env.Setup(environment => environment.ResourceRepository).Returns(repo.Object); var msg = new DeleteResourcesMessage(new List<IContextualResourceModel> { unassignedResource.Object }, "", false); //Run delete command MainViewModel.Handle(msg); //Assert resource deleted from repository repo.Verify(repository => repository.DeleteResource(unassignedResource.Object), Times.Once(), "Deleting an unassigned resource does not delete from resource repository"); }
public void DeleteResourceWithDeclineExpectsDependencyServiceCalled() { CreateFullExportsAndVm(); SetupForDelete(); PopupController.Setup(s => s.Show()).Returns(MessageBoxResult.No); var msg = new DeleteResourcesMessage(new List<IContextualResourceModel> { FirstResource.Object }, "", false); MainViewModel.Handle(msg); ResourceRepo.Verify(s => s.HasDependencies(FirstResource.Object), Times.Never()); }
public void DeleteResourceWithNullResourceExpectsNoPoupShown() { CreateFullExportsAndVm(); SetupForDelete(); var msg = new DeleteResourcesMessage(null, "", false); MainViewModel.Handle(msg); PopupController.Verify(s => s.Show(), Times.Never()); }
public void DeleteResourceExpectThatFilterIsNotUpdatedIfNoFilterExists() { CreateFullExportsAndVm(); SetupForDelete(); PopupController.Setup(s => s.Show()).Returns(MessageBoxResult.No); var msg = new DeleteResourcesMessage(new List<IContextualResourceModel> { FirstResource.Object }, "", false); var repo = MainViewModel.ExplorerViewModel.NavigationViewModel; PrivateObject p = new PrivateObject(repo, new PrivateType(typeof(NavigationViewModelBase))); p.SetField("_studioResourceRepository", MockStudioResourceRepository.Object); p.SetField("_searchFilter", ""); MainViewModel.Handle(msg); MockStudioResourceRepository.Verify(a => a.Filter(It.IsAny<Func<IExplorerItemModel, bool>>()), Times.Never()); }
public void MainViewModel_HandleDeleteResourceMessage_WhenHasNullResource_PerformsAction() { //------------Setup for test-------------------------- CreateFullExportsAndVm(); SetupForDelete(); PopupController.Setup(s => s.Show()).Returns(MessageBoxResult.Yes); var _actionInvoked = false; var msg = new DeleteResourcesMessage(null, "", true, () => { _actionInvoked = true; }); //------------Execute Test--------------------------- MainViewModel.Handle(msg); //------------Assert Results------------------------- Assert.IsFalse(_actionInvoked); }
public void MainViewModel_HandleDeleteResourceMessage_WhenHasActionDeclined_PerformsAction() { //------------Setup for test-------------------------- CreateFullExportsAndVm(); SetupForDelete(); PopupController.Setup(s => s.Show()).Returns(MessageBoxResult.No); var _actionInvoked = false; var msg = new DeleteResourcesMessage(new List<IContextualResourceModel> { FirstResource.Object }, "", false, () => { _actionInvoked = true; }); //------------Execute Test--------------------------- MainViewModel.Handle(msg); //------------Assert Results------------------------- Assert.IsTrue(_actionInvoked); }
public void MainViewModel_HandleDeleteResourceMessage_WhenHasActionNotDeclined_PerformsAction() { //------------Setup for test-------------------------- CreateFullExportsAndVm(); SetupForDelete(); var _actionInvoked = false; var msg = new DeleteResourcesMessage(new List<IContextualResourceModel> { FirstResource.Object }, "", true, () => { _actionInvoked = true; }); //------------Execute Test--------------------------- MainViewModel.Handle(msg); //------------Assert Results------------------------- Assert.IsFalse(_actionInvoked); }
public void DeleteResourceConfirmedExpectContextRemoved() { CreateFullExportsAndVm(); SetupForDelete(); var msg = new DeleteResourcesMessage(new List<IContextualResourceModel> { FirstResource.Object }, ""); MainViewModel.Handle(msg); ResourceRepo.Verify(s => s.HasDependencies(FirstResource.Object), Times.Once()); }