Example #1
0
        public void ValidateJob_ThrowsExceptionBlankPass()
        {
            string expectedInnerError    = "Remote Filesystem selected but credentials were invalid.";
            FindDuplicateOptions options = new FindDuplicateOptions()
            {
                Domain            = "",
                HashLimit         = 0,
                IsLocalFileSystem = false,
                Pass = "",
                User = "******",
                Path = @".\"
            };
            FindDuplicatesJob   testJob        = new FindDuplicatesJob(options);
            Mock <IFileHelpers> fileHelperMock = new Moq.Mock <IFileHelpers>();
            DuplicateFinder     sut            = new DuplicateFinder(fileHelperMock.Object);

            try
            {
                sut.ValidateJob(testJob);
                Assert.Fail("Should have thrown an argument exception");
            }
            catch (ArgumentException ex)
            {
                Assert.True(ex.Message.Contains(expectedInnerError));
                Assert.Pass();
            }
        }
Example #2
0
        public void ValidateJob_ThrowsExceptionBlankUser()
        {
            FindDuplicateOptions options = new FindDuplicateOptions()
            {
                Domain            = "",
                HashLimit         = 0,
                IsLocalFileSystem = false,
                Pass = "******",
                User = "",
                Path = @".\"
            };
            FindDuplicatesJob   testJob        = new FindDuplicatesJob(options);
            Mock <IFileHelpers> fileHelperMock = new Moq.Mock <IFileHelpers>();
            DuplicateFinder     sut            = new DuplicateFinder(fileHelperMock.Object);

            try
            {
                sut.ValidateJob(testJob);
                Assert.Fail("Should have thrown an argument exception");
            }
            catch (ArgumentException ex)
            {
                Assert.Pass();
            }
        }
Example #3
0
        public void WalkFilePaths_ThrowsOnInvalidPath()
        {
            FindDuplicateOptions options = new FindDuplicateOptions()
            {
                Domain            = "",
                HashLimit         = 0,
                IsLocalFileSystem = true,
                Pass = "",
                User = "",
                Path = @".\"
            };
            FindDuplicatesJob testJob            = new FindDuplicatesJob(options);
            string            expectedInnerError = "unanticipated error";

            var         filesystemMock = new Moq.Mock <IFileSystem>();
            FileHelpers sut            = new FileHelpers(filesystemMock.Object);

            filesystemMock
            .Setup(x => x.Directory.GetFiles(testJob.Options.Path, It.IsAny <string>(),
                                             It.IsAny <System.IO.SearchOption>())).Throws(new Exception(expectedInnerError));

            try
            {
                sut.WalkFilePaths(testJob);
                Assert.Fail("If WalkFilePaths throws, there isn't anything we can do to recover. Should have thrown but did not.");
            }
            catch (Exception ex)
            {
                Assert.True(ex.Message.Contains(expectedInnerError));
                Assert.Pass();
            }
        }
Example #4
0
        public void WalkFilePaths_ReturnsExpectedArray()
        {
            FindDuplicateOptions options = new FindDuplicateOptions()
            {
                Domain            = "",
                HashLimit         = 0,
                IsLocalFileSystem = true,
                Pass = "",
                User = "",
                Path = @".\"
            };
            FindDuplicatesJob testJob = new FindDuplicatesJob(options);

            string[] testFiles = new[] { @"C:\BOOTNXT",
                                         @"C:\hiberfil.sys",
                                         @"C:\pagefile.sys",
                                         @"C:\windows-version.txt" };

            var         filesystemMock = new Moq.Mock <IFileSystem>();
            FileHelpers sut            = new FileHelpers(filesystemMock.Object);

            filesystemMock.Setup(x => x.Directory.GetFiles(testJob.Options.Path, It.IsAny <string>(), It.IsAny <System.IO.SearchOption>())).Returns(testFiles);

            string[] actualResult = sut.WalkFilePaths(testJob);
            Assert.AreEqual(testFiles, actualResult);
        }
Example #5
0
 public void Setup()
 {
     _options = new FindDuplicateOptions()
     {
         Domain            = "",
         HashLimit         = 0,
         IsLocalFileSystem = true,
         Pass = "",
         User = "",
         Path = @".\"
     };
     _testJob = new FindDuplicatesJob(_options);
 }
Example #6
0
        public void ValidateJob_IgnoresUserPassLocal()
        {
            FindDuplicateOptions options = new FindDuplicateOptions()
            {
                Domain            = "",
                HashLimit         = 0,
                IsLocalFileSystem = true,
                Pass = "",
                User = "",
                Path = @".\"
            };
            FindDuplicatesJob   testJob        = new FindDuplicatesJob(options);
            Mock <IFileHelpers> fileHelperMock = new Moq.Mock <IFileHelpers>();
            DuplicateFinder     sut            = new DuplicateFinder(fileHelperMock.Object);

            sut.ValidateJob(testJob);
        }
        private string Write196_FindDuplicateOptions(FindDuplicateOptions v)
        {
            switch (v)
            {
                case FindDuplicateOptions.SameName:
                    return "SameName";

                case FindDuplicateOptions.SameSize:
                    return "SameSize";

                case FindDuplicateOptions.SameContent:
                    return "SameContent";
            }
            return XmlSerializationWriter.FromEnum((long) v, new string[] { "SameName", "SameSize", "SameContent" }, new long[] { 1L, 2L, 4L }, "Nomad.FileSystem.Virtual.FindDuplicateOptions");
        }