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

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

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

            try
            {
                stringBuilder = resourceService.Execute(new Dictionary <string, StringBuilder>
                {
                    { "ResourceID", new StringBuilder(guid) },
                    { "NewResourceName", new StringBuilder("NewName") },
                    { "destinatioPath", new StringBuilder("NewName") },
                }, workScpace.Object);
            }
            catch (Exception ex)
            {
                resourceCatalog.Verify(catalog => catalog.DuplicateResource(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>()));
                var serializer     = new Dev2JsonSerializer();
                var executeMessage = serializer.Deserialize <ExecuteMessage>(stringBuilder);
                Assert.IsTrue(executeMessage.HasError);
                Assert.AreEqual("ResourceId is required", executeMessage.Message);
                Assert.AreEqual("Catalog Error", ex.Message);
            }
        }
        public void Execute_GivenResourcePayLoad_ShouldExctactPayLoad()
        {
            const string guid = "7B71D6B8-3E11-4726-A7A0-AC924977D6E5";
            //---------------Set up test pack-------------------
            var resourceCatalog = new Mock <IResourceCatalog>();
            var resource        = new Mock <IExplorerItem>();

            resourceCatalog.Setup(catalog => catalog.DuplicateResource(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new ResourceCatalogDuplicateResult
            {
                DuplicatedItems = new List <IExplorerItem> {
                    resource.Object
                }
            });
            var workScpace      = new Mock <IWorkspace>();
            var resourceService = new DuplicateResourceService(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") },
                { "destinationPath", new StringBuilder("NewName") },
            }, workScpace.Object);

            //---------------Test Result -----------------------
            resourceCatalog.Verify(catalog => catalog.DuplicateResource(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>()));
            Assert.IsNotNull(stringBuilder);
        }
        public void Execute_GivenMissingResourceId_ShouldReturnFailure()
        {
            //---------------Set up test pack-------------------
            var resourceCatalog = new Mock <IResourceCatalog>();
            var resource        = new Mock <IExplorerItem>();

            resourceCatalog.Setup(catalog => catalog.DuplicateResource(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new ResourceCatalogDuplicateResult
            {
                DuplicatedItems = new List <IExplorerItem> {
                    resource.Object
                }
            });
            var workScpace      = new Mock <IWorkspace>();
            var resourceService = new DuplicateResourceService(resourceCatalog.Object);

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

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

            //---------------Test Result -----------------------
            resourceCatalog.Verify(catalog => catalog.DuplicateResource(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            var serializer     = new Dev2JsonSerializer();
            var executeMessage = serializer.Deserialize <ExecuteMessage>(stringBuilder);

            Assert.IsTrue(executeMessage.HasError);
            Assert.AreEqual("ResourceId is required", executeMessage.Message.ToString());
        }