public AddItem ( IExplorerItem itemToAdd, System.Guid workSpaceId ) : IExplorerRepositoryResult | ||
itemToAdd | IExplorerItem | |
workSpaceId | System.Guid | |
Результат | IExplorerRepositoryResult |
public void ServerExplorerRepository_AddItem_VerifyNullThrowsException() { //------------Setup for test-------------------------- var factory = new Mock<IExplorerItemFactory>(); var dir = new Mock<IDirectory>(); var catalogue = new Mock<IResourceCatalog>(); // ReSharper disable ObjectCreationAsStatement var sync = new Mock<IExplorerRepositorySync>(); var repo = new ServerExplorerRepository(catalogue.Object, factory.Object, dir.Object, sync.Object, new Mock<IServerVersionRepository>().Object, new FileWrapper()); var res = repo.AddItem(null, Guid.NewGuid()); Assert.AreEqual(res.Status, ExecStatus.Fail); Assert.AreEqual(res.Message, "Item to add was null"); // ReSharper restore ObjectCreationAsStatement }
public void ServerExplorerRepository_CreateItem_ValidFolder_ExpectCreatedFolder() { //------------Setup for test-------------------------- var catalogue = new Mock<IResourceCatalog>(); var factory = new Mock<IExplorerItemFactory>(); var sync = new Mock<IExplorerRepositorySync>(); sync.Setup(m => m.AddItemMessage(It.IsAny<IExplorerItem>())).Verifiable(); var dir = new Mock<IDirectory>(); dir.Setup(a => a.Exists(It.IsAny<string>())).Returns(false); dir.Setup(a => a.CreateIfNotExists(It.IsAny<string>())); var serverExplorerRepository = new ServerExplorerRepository(catalogue.Object, factory.Object, dir.Object, sync.Object, new Mock<IServerVersionRepository>().Object, new FileWrapper()); var item = new ServerExplorerItem("a", Guid.NewGuid(), ResourceType.Folder, null, Permissions.DeployFrom, "/bob/dave"); //------------Execute Test--------------------------- var result = serverExplorerRepository.AddItem(item, Guid.NewGuid()); //------------Assert Results------------------------- Assert.AreEqual(result.Message, ""); Assert.AreEqual(result.Status, ExecStatus.Success); dir.Verify(a => a.Exists(It.IsAny<string>())); dir.Verify(a => a.CreateIfNotExists(It.IsAny<string>())); sync.Verify(m => m.AddItemMessage(It.IsAny<IExplorerItem>()), Times.Once()); }
public void ServerExplorerRepository_CreateItem_FileSystemException_ExpectErrorMessageFromException() { //------------Setup for test-------------------------- var catalogue = new Mock<IResourceCatalog>(); var factory = new Mock<IExplorerItemFactory>(); var dir = new Mock<IDirectory>(); dir.Setup(a => a.Exists(It.IsAny<string>())).Returns(false); dir.Setup(a => a.CreateIfNotExists(It.IsAny<string>())).Throws(new FileNotFoundException("bobe")); var sync = new Mock<IExplorerRepositorySync>(); var serverExplorerRepository = new ServerExplorerRepository(catalogue.Object, factory.Object, dir.Object, sync.Object, new Mock<IServerVersionRepository>().Object, new FileWrapper()); var item = new ServerExplorerItem("a", Guid.NewGuid(), ResourceType.Folder, null, Permissions.DeployFrom, "/bob/dave"); //------------Execute Test--------------------------- var result = serverExplorerRepository.AddItem(item, Guid.NewGuid()); //------------Assert Results------------------------- Assert.AreEqual(result.Message, "bobe"); Assert.AreEqual(result.Status, ExecStatus.Fail); dir.Verify(a => a.Exists(It.IsAny<string>())); dir.Verify(a => a.CreateIfNotExists(It.IsAny<string>())); }
public void ServerExplorerRepository_CreateItem_InvalidItemType_ExpectErrorResult() { //------------Setup for test-------------------------- var catalogue = new Mock<IResourceCatalog>(); var factory = new Mock<IExplorerItemFactory>(); var dir = new Mock<IDirectory>(); dir.Setup(a => a.Exists(It.IsAny<string>())).Returns(false); var sync = new Mock<IExplorerRepositorySync>(); sync.Setup(m => m.AddItemMessage(It.IsAny<IExplorerItem>())).Verifiable(); var serverExplorerRepository = new ServerExplorerRepository(catalogue.Object, factory.Object, dir.Object, sync.Object, new Mock<IServerVersionRepository>().Object, new FileWrapper()); var item = new ServerExplorerItem("a", Guid.NewGuid(), ResourceType.ReservedService, null, Permissions.DeployFrom, "/bob/dave"); //------------Execute Test--------------------------- var result = serverExplorerRepository.AddItem(item, Guid.NewGuid()); //------------Assert Results------------------------- Assert.AreEqual(result.Message, "Only user resources can be added from this repository"); Assert.AreEqual(result.Status, ExecStatus.Fail); sync.Verify(m => m.AddItemMessage(It.IsAny<IExplorerItem>()), Times.Never()); }