Exemplo n.º 1
0
        public void Dev2FTPProvider_ListFilesInDirectory_ExpectedException()
        {
            const string path = "path";
            var          mockActivityIOPath = new Mock <IActivityIOPath>();

            mockActivityIOPath.Setup(activityIOPath => activityIOPath.Path).Returns(path);

            var dev2FTPProvider = new Dev2FTPProvider(null);

            try
            {
                dev2FTPProvider.ListFilesInDirectory(mockActivityIOPath.Object);
                Assert.Fail("Code should have caused an exception to be thrown");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Object reference not set to an instance of an object. : [path]", ex.Message);
            }
        }
Exemplo n.º 2
0
        public void Dev2FTPProvider_ListFilesInDirectory()
        {
            const string path                = "path";
            const string userName            = "******";
            const string password            = "******";
            const bool   isNotCertVerifiable = false;
            const bool   enableSsl           = false;
            const string privateKeyFile      = "privateKeyFile";
            const string tmpDirData          = "tmpDirData";
            const string path1               = "\\test";
            const string path2               = "\\testnew";
            var          extractList         = new List <string> {
                path1, path2
            };

            var mockActivityIOPath = new Mock <IActivityIOPath>();

            mockActivityIOPath.Setup(activityIOPath => activityIOPath.PathType).Returns(Interfaces.Enums.enActivityIOPathType.FTP);
            mockActivityIOPath.Setup(activityIOPath => activityIOPath.Path).Returns(path);
            mockActivityIOPath.Setup(activityIOPath => activityIOPath.Username).Returns(userName);
            mockActivityIOPath.Setup(activityIOPath => activityIOPath.Password).Returns(password);
            mockActivityIOPath.Setup(activityIOPath => activityIOPath.IsNotCertVerifiable).Returns(isNotCertVerifiable);
            mockActivityIOPath.Setup(activityIOPath => activityIOPath.PrivateKeyFile).Returns(privateKeyFile);

            var mockImplementation = new Mock <IImplementation>();

            mockImplementation.Setup(implementation => implementation.EnableSsl(mockActivityIOPath.Object)).Returns(enableSsl);
            mockImplementation.Setup(implementation => implementation.ExtendedDirList(path, userName, password, enableSsl, isNotCertVerifiable, privateKeyFile)).Returns(tmpDirData);
            mockImplementation.Setup(implementation => implementation.ExtractList(tmpDirData, It.IsAny <Func <string, bool> >()))
            .Callback <string, Func <string, bool> >((string payload, Func <string, bool> matchFunc) => {
                Assert.IsFalse(matchFunc("<dir>"));
                Assert.IsTrue(matchFunc("ftp:\\testfile.txt"));
                matchFunc(payload);
            })
            .Returns(extractList);
            mockImplementation.Setup(implementation => implementation.BuildValidPathForFtp(mockActivityIOPath.Object, path1)).Returns(path1);
            mockImplementation.Setup(implementation => implementation.BuildValidPathForFtp(mockActivityIOPath.Object, path2)).Returns(path2);

            var dev2FTPProvider    = new Dev2FTPProvider(mockImplementation.Object);
            var foldersInDirectory = dev2FTPProvider.ListFilesInDirectory(mockActivityIOPath.Object);

            Assert.AreEqual(2, foldersInDirectory.Count);

            Assert.IsFalse(foldersInDirectory[0].IsNotCertVerifiable);
            Assert.AreEqual(password, foldersInDirectory[0].Password);
            Assert.AreEqual(path1, foldersInDirectory[0].Path);
            Assert.AreEqual(Interfaces.Enums.enActivityIOPathType.FileSystem, foldersInDirectory[0].PathType);
            Assert.AreEqual(privateKeyFile, foldersInDirectory[0].PrivateKeyFile);
            Assert.AreEqual(userName, foldersInDirectory[0].Username);

            Assert.IsFalse(foldersInDirectory[1].IsNotCertVerifiable);
            Assert.AreEqual(password, foldersInDirectory[1].Password);
            Assert.AreEqual(path2, foldersInDirectory[1].Path);
            Assert.AreEqual(Interfaces.Enums.enActivityIOPathType.FileSystem, foldersInDirectory[1].PathType);
            Assert.AreEqual(privateKeyFile, foldersInDirectory[1].PrivateKeyFile);
            Assert.AreEqual(userName, foldersInDirectory[1].Username);

            mockImplementation.Verify(implementation => implementation.EnableSsl(mockActivityIOPath.Object), Times.Once);
            mockImplementation.Verify(implementation => implementation.ExtendedDirList(path, userName, password, enableSsl, isNotCertVerifiable, privateKeyFile), Times.Once);
            mockImplementation.Verify(implementation => implementation.ExtractList(tmpDirData, It.IsAny <Func <string, bool> >()), Times.Once);
            mockImplementation.Verify(implementation => implementation.BuildValidPathForFtp(mockActivityIOPath.Object, path1), Times.Once);
        }