public void StudioResourceRepository_DeleteItem_ItemParentNull_Exception() { //------------Setup for test-------------------------- var _propertyChangedCalled = false; var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>(); mockExplorerResourceRepository.Setup(m => m.DeleteItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>())) .Returns(new ExplorerRepositoryResult(ExecStatus.Success, "Success")) .Verifiable(); var environmentId = Guid.NewGuid(); var workflowId = Guid.NewGuid(); var folderID = Guid.NewGuid(); SetupEnvironmentRepo(environmentId); var mockVersionRepository = new Mock<IVersionRepository>(); var repository = new StudioResourceRepository(GetTestData(workflowId.ToString(), folderID: folderID), environmentId, _invoke) { GetVersionProxy = id => mockVersionRepository.Object, GetExplorerProxy = id => mockExplorerResourceRepository.Object }; var folderItem = repository.FindItemById(folderID); ExplorerItemModel item = folderItem.Parent as ExplorerItemModel; // ReSharper disable PossibleNullReferenceException item.PropertyChanged += (sender, args) => // ReSharper restore PossibleNullReferenceException { if(args.PropertyName == "ChildrenCount") { _propertyChangedCalled = true; } }; //------------Execute Test--------------------------- ExplorerItemModel explorerItemModel = new ExplorerItemModel(); repository.DeleteItem(explorerItemModel); //------------Assert Results------------------------- Assert.IsFalse(_propertyChangedCalled); }
public void StudioResourceRepository_DeleteVersion_TwoItemsReturned_ItemsAttachedToParent() { //------------Setup for test-------------------------- var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>(); var mockVersionRepository = new Mock<IVersionRepository>(); var v1 = new Mock<IVersionInfo>(); v1.Setup(v => v.VersionNumber).Returns("1"); var v2 = new Mock<IVersionInfo>(); v2.Setup(v => v.VersionNumber).Returns("2"); mockVersionRepository.Setup(m => m.DeleteVersion(It.IsAny<Guid>(), It.IsAny<string>())) .Returns(new List<IExplorerItem> { new ServerExplorerItem { ResourceType = ResourceType.WebService, DisplayName = "v2 2012-10-10 Save", ResourceId = Guid.NewGuid(), Permissions = Permissions.View, VersionInfo = v1.Object }, new ServerExplorerItem { ResourceType = ResourceType.WebService, DisplayName = "v1 2012-10-10 Save", ResourceId = Guid.NewGuid(), Permissions = Permissions.View , VersionInfo = v2.Object } }) .Verifiable(); var superWFId = Guid.NewGuid(); var parent = new ServerExplorerItem { ResourceType = ResourceType.WorkflowService, DisplayName = "SuperWF", ResourceId = superWFId, Permissions = Permissions.Contribute, ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER" }; SetupEnvironmentRepo(Guid.Empty); var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke) { GetVersionProxy = id => mockVersionRepository.Object, GetExplorerProxy = id => mockExplorerResourceRepository.Object, GetCurrentEnvironment = () => Guid.Empty }; var versionInfo = new VersionInfo { DateTimeStamp = DateTime.Now, Reason = "Rollback", ResourceId = superWFId, User = "", VersionId = Guid.NewGuid(), VersionNumber = "3" }; //------------Execute Test--------------------------- repo.DeleteVersion(versionInfo, Guid.Empty); //------------Assert Results------------------------- var actual = repo.FindItemById(superWFId); Assert.AreEqual(2, actual.Children.Count); mockVersionRepository.Verify(m => m.DeleteVersion(It.IsAny<Guid>(), It.IsAny<string>()), Times.Once()); }
public void StudioResourceRepository_HideHistory_ClearsChildren() { //------------Setup for test-------------------------- var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>(); var mockVersionRepository = new Mock<IVersionRepository>(); var superWFId = Guid.NewGuid(); var parent = new ServerExplorerItem { ResourceType = ResourceType.WorkflowService, DisplayName = "SuperWF", ResourceId = superWFId, Permissions = Permissions.Contribute, ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER", Children = new List<IExplorerItem> { new ServerExplorerItem{ ResourceType = ResourceType.WebService, DisplayName = "v2 2012-10-10 Save", ResourceId = Guid.NewGuid(), Permissions = Permissions.View }, new ServerExplorerItem{ ResourceType = ResourceType.WebService, DisplayName = "v2 2012-10-10 Save", ResourceId = Guid.NewGuid(), Permissions = Permissions.View } } }; SetupEnvironmentRepo(Guid.Empty); var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke) { GetVersionProxy = id => mockVersionRepository.Object, GetExplorerProxy = id => mockExplorerResourceRepository.Object, GetCurrentEnvironment = () => Guid.Empty }; //------------Execute Test--------------------------- repo.HideVersionHistory(Guid.Empty, superWFId); //------------Assert Results------------------------- var actual = repo.FindItemById(superWFId); Assert.AreEqual(0, actual.Children.Count); }
public void StudioResourceRepository_ShowVersionHistory_NoItemsReturned_InfoItemAttachedToParent() { //------------Setup for test-------------------------- var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>(); var mockVersionRepository = new Mock<IVersionRepository>(); mockVersionRepository.Setup(m => m.GetVersions(It.IsAny<Guid>())).Returns(new List<IExplorerItem>()); var superWFId = Guid.NewGuid(); var parent = new ServerExplorerItem { ResourceType = ResourceType.WorkflowService, DisplayName = "SuperWF", ResourceId = superWFId, Permissions = Permissions.Contribute, ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER" }; SetupEnvironmentRepo(Guid.Empty); var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke) { GetVersionProxy = id => mockVersionRepository.Object, GetExplorerProxy = id => mockExplorerResourceRepository.Object, GetCurrentEnvironment = () => Guid.Empty }; //------------Execute Test--------------------------- repo.ShowVersionHistory(Guid.Empty, superWFId); //------------Assert Results------------------------- var actual = repo.FindItemById(superWFId); Assert.AreEqual(1, actual.Children.Count); Assert.AreEqual("There is no version history to display", actual.Children[0].DisplayName); }
public void StudioResourceRepository_FindItemByID_ItemDoesNotExist_ShouldReturnNull() { //------------Setup for test-------------------------- var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>(); var environmentId = Guid.NewGuid(); var workflowId = Guid.NewGuid(); SetupEnvironmentRepo(environmentId); var mockVersionRepository = new Mock<IVersionRepository>(); var repository = new StudioResourceRepository(GetTestData(workflowId.ToString()), environmentId, _invoke) { GetVersionProxy = id => mockVersionRepository.Object, GetExplorerProxy = id => mockExplorerResourceRepository.Object }; //------------Execute Test--------------------------- var findItemById = repository.FindItemById(Guid.NewGuid()); //------------Assert Results------------------------- Assert.IsNull(findItemById); }
public void StudioResourceRepository_FindItemByID_ItemExists_ShouldReturnItem() { //------------Setup for test-------------------------- var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>(); mockExplorerResourceRepository.Setup(m => m.RenameItem(It.IsAny<IExplorerItem>(), It.IsAny<string>(), It.IsAny<Guid>())).Verifiable(); var environmentId = Guid.NewGuid(); var workflowId = Guid.NewGuid(); SetupEnvironmentRepo(environmentId); var mockVersionRepository = new Mock<IVersionRepository>(); var repository = new StudioResourceRepository(GetTestData(workflowId.ToString()), environmentId, _invoke) { GetVersionProxy = id => mockVersionRepository.Object, GetExplorerProxy = id => mockExplorerResourceRepository.Object }; //------------Execute Test--------------------------- var findItemById = repository.FindItemById(workflowId); //------------Assert Results------------------------- Assert.IsNotNull(findItemById); }