public void DsfDropBoxDownloadActivity_OverwriteFile_Same_Object_Is_Equal()
        {
            //---------------Set up test pack-------------------
            var uniqueId = Guid.NewGuid().ToString();

            var mockDropboxClient        = new Mock <IDropboxClient>();
            var mockDropboxClientFactory = new Mock <IDropboxClientFactory>();

            mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);

            using (var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object)
            {
                UniqueID = uniqueId,
                Result = "A"
            })
            {
                dsfDropBoxDownloadActivity.SetupDropboxClient("");

                var dsfDropBoxDownloadActivityOther = new TestDsfDropBoxDownloadActivity {
                    UniqueID = uniqueId, Result = "A"
                };
                //---------------Assert Precondition----------------
                Assert.IsTrue(dsfDropBoxDownloadActivity.Equals(dsfDropBoxDownloadActivityOther));
                //---------------Execute Test ----------------------
                dsfDropBoxDownloadActivity.OverwriteFile      = true;
                dsfDropBoxDownloadActivityOther.OverwriteFile = true;
                var @equals = dsfDropBoxDownloadActivity.Equals(dsfDropBoxDownloadActivityOther);
                //---------------Test Result -----------------------
                Assert.IsTrue(@equals);
            }
        }
        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_ExecuteTool_FromPath_IsNullOrEmpty_VerifyMethodCall_3Times_ExpectTrue()
        {
            //-----------------------Arrange----------------------------
            var mockDSFDataObject = new Mock <IDSFDataObject>();

            mockDSFDataObject.Setup(o => o.Environment.AddError(It.IsAny <string>()));

            var mockDropboxClient        = new Mock <IDropboxClient>();
            var mockDropboxClientFactory = new Mock <IDropboxClientFactory>();

            mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);

            using (var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object)
            {
                FromPath = null,
                ToPath = null
            })
            {
                dsfDropBoxDownloadActivity.SetupDropboxClient("");
                //-----------------------Act--------------------------------
                dsfDropBoxDownloadActivity.TestExecuteTool(mockDSFDataObject.Object, 0);
                //-----------------------Assert-----------------------------
                mockDSFDataObject.Verify(o => o.Environment.AddError(It.IsAny <string>()), Times.Exactly(3));
            }
        }
        public void DsfDropBoxDownloadActivity_GetHashCode_PropertiesNull_IsNull_ExpectTrue()
        {
            var mockDropboxClient = new Mock <IDropboxClient>();

            var mockDropboxClientFactory = new Mock <IDropboxClientFactory>();

            mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);
            //-----------------------Arrange----------------------------
            using (var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object))
            {
                //-----------------------Act--------------------------------
                dsfDropBoxDownloadActivity.SetupDropboxClient("");
                //-----------------------Assert-----------------------------
                Assert.IsNotNull(dsfDropBoxDownloadActivity.GetHashCode());
            }
        }
        public void DsfDropBoxDownloadActivity_GetDebugOutputs_ExecutionEnvironment_IsNull_ExpectFalse()
        {
            var mockDropboxClient        = new Mock <IDropboxClient>();
            var mockDropboxClientFactory = new Mock <IDropboxClientFactory>();

            mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);

            //-----------------------Arrange----------------------------
            using (var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object))
            {
                //-----------------------Act--------------------------------
                dsfDropBoxDownloadActivity.SetupDropboxClient("");
                //-----------------------Assert-----------------------------
                Assert.AreEqual(0, dsfDropBoxDownloadActivity.GetDebugInputs(null, 0).Count);
            }
        }
        public void DsfDropBoxDownloadActivity_Equals_IsNull_ExpectFalse()
        {
            var mockDropboxClient        = new Mock <IDropboxClient>();
            var mockDropboxClientFactory = new Mock <IDropboxClientFactory>();

            mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);

            //-----------------------Arrange----------------------------
            using (var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object))
            {
                //-----------------------Act--------------------------------
                dsfDropBoxDownloadActivity.SetupDropboxClient("");
                //-----------------------Assert-----------------------------
                Assert.IsFalse(dsfDropBoxDownloadActivity.Equals(null));
            }
        }
        public void DsfDropBoxDownloadActivity_ObjectEquals_IsTrue_ExpectTrue()
        {
            //-----------------------Arrange----------------------------
            var obj = new object();

            var mockDropboxClient        = new Mock <IDropboxClient>();
            var mockDropboxClientFactory = new Mock <IDropboxClientFactory>();

            mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);

            using (var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object))
            {
                dsfDropBoxDownloadActivity.SetupDropboxClient("");
                obj = dsfDropBoxDownloadActivity;
                //-----------------------Act--------------------------------
                //-----------------------Assert-----------------------------
                Assert.IsTrue(dsfDropBoxDownloadActivity.Equals(obj));
            }
        }
        public void DsfDropBoxDownloadActivity_LocalPathManager_SetProperty_AreEqual_ExpectTrue()
        {
            //-----------------------Arrange----------------------------
            var mockLocalPathManager = new Mock <ILocalPathManager>();

            var mockDropboxClient        = new Mock <IDropboxClient>();
            var mockDropboxClientFactory = new Mock <IDropboxClientFactory>();

            mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);

            //-----------------------Act--------------------------------
            using (var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object)
            {
                LocalPathManager = mockLocalPathManager.Object
            })
            {
                dsfDropBoxDownloadActivity.SetupDropboxClient("");
                //-----------------------Assert-----------------------------
                Assert.AreEqual(mockLocalPathManager.Object, dsfDropBoxDownloadActivity.LocalPathManager);
            }
        }
        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]);
                }
            }
        }
        public void DsfDropBoxDownloadActivity_GetState_ReturnsStateVariable()
        {
            //---------------Set up test pack-------------------
            var uniqueId       = Guid.NewGuid();
            var selectedSource = new MockOAuthSource(uniqueId);

            var mockDropboxClient        = new Mock <IDropboxClient>();
            var mockDropboxClientFactory = new Mock <IDropboxClientFactory>();

            mockDropboxClientFactory.Setup(o => o.New(It.IsAny <string>(), It.IsAny <HttpClient>())).Returns(mockDropboxClient.Object);

            //------------Setup for test--------------------------
            using (var dsfDropBoxDownloadActivity = new TestDsfDropBoxDownloadActivity(mockDropboxClientFactory.Object)
            {
                SelectedSource = selectedSource,
                FromPath = "Path_From",
                ToPath = "Path_To",
                OverwriteFile = false,
                Result = "Downloaded"
            })
            {
                dsfDropBoxDownloadActivity.SetupDropboxClient("");

                //------------Execute Test---------------------------
                var stateItems = dsfDropBoxDownloadActivity.GetState();
                Assert.AreEqual(5, stateItems.Count());

                var expectedResults = new[]
                {
                    new StateVariable
                    {
                        Name  = "SelectedSource.ResourceID",
                        Type  = StateVariable.StateType.Input,
                        Value = uniqueId.ToString()
                    },
                    new StateVariable
                    {
                        Name  = "FromPath",
                        Type  = StateVariable.StateType.Input,
                        Value = "Path_From"
                    },
                    new StateVariable
                    {
                        Name  = "ToPath",
                        Type  = StateVariable.StateType.Input,
                        Value = "Path_To"
                    },
                    new StateVariable
                    {
                        Name  = "OverwriteFile",
                        Type  = StateVariable.StateType.Input,
                        Value = "False"
                    },
                    new StateVariable
                    {
                        Name  = "Result",
                        Type  = StateVariable.StateType.Output,
                        Value = "Downloaded"
                    }
                };

                var iter = dsfDropBoxDownloadActivity.GetState().Select(
                    (item, index) => new
                {
                    value       = item,
                    expectValue = expectedResults[index]
                }
                    );

                //------------Assert Results-------------------------
                foreach (var entry in iter)
                {
                    Assert.AreEqual(entry.expectValue.Name, entry.value.Name);
                    Assert.AreEqual(entry.expectValue.Type, entry.value.Type);
                    Assert.AreEqual(entry.expectValue.Value, entry.value.Value);
                }
            }
        }