public void DsfDropBoxDownloadActivity_PerformExecution_ContainsNotFile_ExpectException()
        {
            //-----------------------Arrange----------------------------
            var mockDropboxClient         = new Mock <IDropboxClient>();
            var mockDropboxClientFactory  = new Mock <IDropboxClientFactory>();
            var mockDropboxSingleExecutor = new Mock <IDropboxSingleExecutor <IDropboxResult> >();
            var mockDownloadResponse      = new Mock <IDownloadResponse <FileMetadata> >();
            var mockFile = new Mock <IFile>();

            mockDownloadResponse.Setup(o => o.Response).Returns(new Mock <FileMetadata>().Object);
            mockDropboxClient.Setup(o => o.DownloadAsync(It.IsAny <DownloadArg>())).Returns(() => { var t = new Task <IDownloadResponse <FileMetadata> >(() => mockDownloadResponse.Object); t.Start(); return(t); });
            mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);
            mockDropboxSingleExecutor.Setup(o => o.ExecuteTask(It.IsAny <IDropboxClient>())).Returns(new DropboxFailureResult(new Exception("test error: not_file!")));

            var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object)
            {
                DropboxFile        = mockFile.Object,
                MockSingleExecutor = mockDropboxSingleExecutor,
            };

            var dictionary = new Dictionary <string, string>
            {
                { "ToPath", @"C:\Users\temp\testToPath\" },
                { "FromPath", @"C:\Users\temp" }
            };

            //-----------------------Act--------------------------------
            //-----------------------Assert-----------------------------
            Assert.ThrowsException <Exception>(() => dsfDropBoxDownloadActivity.TestPerformExecution(dictionary));
            dsfDropBoxDownloadActivity.Dispose();
        }
        public void DsfDropBoxDownloadActivity_PerformExecution_ExpectException()
        {
            //-----------------------Arrange----------------------------
            var mockDropboxClient         = new Mock <IDropboxClient>();
            var mockDropboxClientFactory  = new Mock <IDropboxClientFactory>();
            var mockDropboxSingleExecutor = new Mock <IDropboxSingleExecutor <IDropboxResult> >();
            var mockDownloadResponse      = new Mock <IDownloadResponse <FileMetadata> >();
            var mockFile = new Mock <IFile>();

            mockDownloadResponse.Setup(o => o.Response).Returns(new Mock <FileMetadata>().Object);

            mockDropboxClient.Setup(o => o.DownloadAsync(It.IsAny <DownloadArg>())).Returns(() => { var t = new Task <IDownloadResponse <FileMetadata> >(() => mockDownloadResponse.Object); t.Start(); return(t); });
            mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);
            mockDropboxSingleExecutor.Setup(o => o.ExecuteTask(It.IsAny <IDropboxClient>())).Returns(new DropboxFailureResult(new Exception("test error!")));

            using (var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object)
            {
                DropboxFile = mockFile.Object,
                MockSingleExecutor = mockDropboxSingleExecutor
            })
            {
                var dictionary = new Dictionary <string, string>
                {
                    { "ToPath", @"C:\Users\temp\testToPath\" },
                    { "FromPath", @"C:\Users\temp" }
                };

                try
                {
                    dsfDropBoxDownloadActivity.TestPerformExecution(dictionary);
                    Assert.Fail("Expected exception");
                } catch (Exception e)
                {
                    Assert.AreEqual("test error!", e.Message);
                }
            }
        }
        public void DsfDropBoxDownloadActivity_PerformExecution_ExpectSuccess()
        {
            //-----------------------Arrange----------------------------
            var mockDropboxClient        = new Mock <IDropboxClient>();
            var mockDropboxClientFactory = new Mock <IDropboxClientFactory>();
            var mockDownloadResponse     = new Mock <IDownloadResponse <FileMetadata> >();
            var mockFile = new Mock <IFile>();

            using (var task = new Task <IDownloadResponse <FileMetadata> >(() => mockDownloadResponse.Object))
            {
                mockDownloadResponse.Setup(o => o.Response).Returns(new Mock <FileMetadata>().Object);
                task.Start();
                mockDropboxClient.Setup(o => o.DownloadAsync(It.IsAny <DownloadArg>())).Returns(() => { var t = new Task <IDownloadResponse <FileMetadata> >(() => mockDownloadResponse.Object); t.Start(); return(t); });
                mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);

                using (var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object)
                {
                    DropboxFile = mockFile.Object
                })
                {
                    var dictionary = new Dictionary <string, string>
                    {
                        { "ToPath", "TestToPath" },
                        { "FromPath", @"C:\Users\temp" }
                    };
                    //-----------------------Act--------------------------------
                    var list = dsfDropBoxDownloadActivity.TestPerformExecution(dictionary);
                    //-----------------------Assert-----------------------------
                    mockDownloadResponse.VerifyAll();
                    mockDropboxClient.VerifyAll();
                    mockDropboxClientFactory.VerifyAll();
                    mockFile.VerifyAll();
                    Assert.AreEqual(1, list.Count);
                    Assert.AreEqual("Success", list[0]);
                }
            }
        }