public void Execute_GivenMissingDestinationPath_ShouldReturnFailure()
        {
            //---------------Set up test pack-------------------
            var resourceCatalog = new Mock <IResourceCatalog>();

            resourceCatalog.Setup(catalog => catalog.DuplicateFolder(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(new ResourceCatalogDuplicateResult()
            {
                Message = "Hi"
            });
            var workScpace = new Mock <IWorkspace>();
            DuplicateFolderService resourceService = new DuplicateFolderService(resourceCatalog.Object);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(resourceService);
            //---------------Execute Test ----------------------
            StringBuilder stringBuilder = new StringBuilder();

            try
            {
                stringBuilder = resourceService.Execute(new Dictionary <string, StringBuilder>
                {
                    { "ResourceID", new StringBuilder(Guid.NewGuid().ToString()) },
                }, workScpace.Object);
            }
            catch (Exception ex)
            {
                resourceCatalog.Verify(catalog => catalog.DuplicateFolder(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()));
                var serializer     = new Dev2JsonSerializer();
                var executeMessage = serializer.Deserialize <ExecuteMessage>(stringBuilder);
                Assert.IsTrue(executeMessage.HasError);
                Assert.AreEqual("Destination Paths not specified", executeMessage.Message.ToString());
                Assert.AreEqual("Destination Paths not specified", ex.Message);
            }
        }
        public void Execute_GivenCatalogThrowsException_ShouldReturnFailureAndCatalogException()
        {
            //---------------Set up test pack-------------------
            var resourceCatalog = new Mock <IResourceCatalog>();

            resourceCatalog.Setup(catalog => catalog.DuplicateFolder(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()))
            .Throws(new Exception("Catalog Error"));
            var                    workScpace      = new Mock <IWorkspace>();
            const string           guid            = "7B71D6B8-3E11-4726-A7A0-AC924977D6E5";
            DuplicateFolderService resourceService = new DuplicateFolderService(resourceCatalog.Object);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(resourceService);
            //---------------Execute Test ----------------------
            StringBuilder stringBuilder = new StringBuilder();

            try
            {
                stringBuilder = resourceService.Execute(new Dictionary <string, StringBuilder>
                {
                    { "ResourceID", new StringBuilder(guid) },
                    { "destinatioPath", new StringBuilder("NewName") },
                }, workScpace.Object);
            }
            catch (Exception ex)
            {
                resourceCatalog.Verify(catalog => catalog.DuplicateFolder(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()), Times.Never);
                var serializer     = new Dev2JsonSerializer();
                var executeMessage = serializer.Deserialize <ExecuteMessage>(stringBuilder);
                Assert.IsTrue(executeMessage.HasError);
                Assert.AreEqual("NewResourceName required", executeMessage.Message);
                Assert.AreEqual("Catalog Error", ex.Message);
            }
        }
        public void Execute_GivenNullSourcePath_ReturnsException()
        {
            //---------------Set up test pack-------------------
            var resourceCatalog = new Mock <IResourceCatalog>();
            var duplicatedItems = new List <IExplorerItem> {
                new ServerExplorerItem("test1", Guid.NewGuid(), "Folder", new List <IExplorerItem>(), Permissions.Contribute, "")
            };

            resourceCatalog.Setup(catalog => catalog.DuplicateFolder(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(new ResourceCatalogDuplicateResult {
                Message = "Hi", DuplicatedItems = duplicatedItems
            });
            var          workScpace      = new Mock <IWorkspace>();
            const string guid            = "7B71D6B8-3E11-4726-A7A0-AC924977D6E5";
            var          resourceService = new DuplicateFolderService(resourceCatalog.Object);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(resourceService);
            //---------------Execute Test ----------------------

            var execute = resourceService.Execute(new Dictionary <string, StringBuilder>
            {
                { "ResourceID", new StringBuilder(guid) },
                { "NewResourceName", new StringBuilder("NewName") },
                { "destinationPath", new StringBuilder("NewName") }
            }, workScpace.Object);
            //---------------Test Result -----------------------
            var serializer     = new Dev2JsonSerializer();
            var executeMessage = serializer.Deserialize <ExecuteMessage>(execute);

            Assert.IsNotNull(executeMessage);
            Assert.IsTrue(executeMessage.HasError);
        }
        public void Execute_GivenResourcePayLoad_ShouldExctactPayLoad()
        {
            //---------------Set up test pack-------------------
            var resourceCatalog = new Mock <IResourceCatalog>();
            var duplicatedItems = new List <IExplorerItem> {
                new ServerExplorerItem("test1", Guid.NewGuid(), "Folder", new List <IExplorerItem>(), Permissions.Contribute, "")
            };

            resourceCatalog.Setup(catalog => catalog.DuplicateFolder(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(new ResourceCatalogDuplicateResult {
                Message = "Hi", DuplicatedItems = duplicatedItems
            });
            var                    workScpace      = new Mock <IWorkspace>();
            const string           guid            = "7B71D6B8-3E11-4726-A7A0-AC924977D6E5";
            DuplicateFolderService resourceService = new DuplicateFolderService(resourceCatalog.Object);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(resourceService);
            //---------------Execute Test ----------------------

            var stringBuilder = resourceService.Execute(new Dictionary <string, StringBuilder>
            {
                { "ResourceID", new StringBuilder(guid) },
                { "NewResourceName", new StringBuilder("NewName") },
                { "sourcePath", new StringBuilder("NewName") },
                { "destinationPath", new StringBuilder("NewName") },
            }, workScpace.Object);

            //---------------Test Result -----------------------
            resourceCatalog.Verify(catalog => catalog.DuplicateFolder(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()));
            var serializer     = new Dev2JsonSerializer();
            var executeMessage = serializer.Deserialize <ResourceCatalogDuplicateResult>(stringBuilder);

            Assert.AreEqual(ExecStatus.Success, executeMessage.Status);
            Assert.AreEqual("Hi", executeMessage.Message);
            CollectionAssert.AreEqual(duplicatedItems, executeMessage.DuplicatedItems);
        }