示例#1
0
        public void PairShouldCorrectlyMergeSameFileInfos()
        {
            var          pcMock           = SetupBasicPairCreatorMock();
            var          infoComparerMock = SetupBasicInfoComparerMock();
            var          pairer           = new InfoPairer(pcMock.Object, infoComparerMock.Object);
            const string path             = "path";
            var          fileInfo1        = new FileInfoCollector.FileInformations()
            {
                FilePath = path, Hash = "hash1"
            };
            var fileInfo2 = new FileInfoCollector.FileInformations()
            {
                FilePath = path, Hash = "hash2"
            };
            List <FileInfoCollector.FileInformations> input1 = new List <FileInfoCollector.FileInformations>()
            {
                fileInfo1
            };
            List <FileInfoCollector.FileInformations> input2 = new List <FileInfoCollector.FileInformations>()
            {
                fileInfo2
            };;

            var result = pairer.Pair(input1, input2);

            Assert.IsInstanceOfType(result, typeof(List <InfoPair>));
            Assert.IsTrue(result.Count == 1);
            Assert.AreEqual(result[0].NewFileHash, fileInfo1.Hash);
            Assert.AreEqual(result[0].OldFileHash, fileInfo2.Hash);
        }
示例#2
0
        public void PairShouldReturnNewListIfEmptyInputs()
        {
            var pcMock           = SetupBasicPairCreatorMock();
            var infoComparerMock = SetupBasicInfoComparerMock();
            var pairer           = new InfoPairer(pcMock.Object, infoComparerMock.Object);
            List <FileInfoCollector.FileInformations> input1 = new List <FileInfoCollector.FileInformations>();
            List <FileInfoCollector.FileInformations> input2 = new List <FileInfoCollector.FileInformations>();

            var result = pairer.Pair(input1, input2);

            Assert.IsInstanceOfType(result, typeof(List <InfoPair>));
            Assert.IsTrue(result.Count == 0);
        }
示例#3
0
        public void PairShouldCorrectlyPairRightOnlyInput()
        {
            var pcMock           = SetupBasicPairCreatorMock();
            var infoComparerMock = SetupBasicInfoComparerMock();
            var pairer           = new InfoPairer(pcMock.Object, infoComparerMock.Object);
            var fileInfo         = new FileInfoCollector.FileInformations()
            {
                FilePath = "path", Hash = "hash"
            };
            List <FileInfoCollector.FileInformations> input1 = new List <FileInfoCollector.FileInformations>();
            List <FileInfoCollector.FileInformations> input2 = new List <FileInfoCollector.FileInformations>()
            {
                fileInfo
            };

            var result = pairer.Pair(input1, input2);

            Assert.IsInstanceOfType(result, typeof(List <InfoPair>));
            Assert.IsTrue(result.Count == 1);
            Assert.AreEqual(result[0].OldFileHash, fileInfo.Hash);
            Assert.AreEqual(result[0].NewFileHash, null);
        }
示例#4
0
        public OutputReport Run(string path)
        {
            OutputReport report;

            try
            {
                var logFileNameProvider           = new DefaultLogFileNameProvider();
                var logFileRemover                = new LogFileItemRemover(logFileNameProvider);
                var currentFileInfo               = new FileInfoCollector(_fsl).CollectFileInfos(path);
                var currentFileInfoWithoutLogFile = logFileRemover.Remove(currentFileInfo);
                try
                {
                    var fileInfoFromLog = new LogInfoGatherer(_fsl, logFileNameProvider).GetFileInfoLogFromPath(path);
                    var fileInfoFromLogWithouLogFile = logFileRemover.Remove(fileInfoFromLog);
                    var pairedFileInfos =
                        new InfoPairer(new PairCreator(new FilenamePicker()), new CompareFileInfoOnPath()).Pair(
                            currentFileInfoWithoutLogFile, fileInfoFromLogWithouLogFile);
                    var fileModificationsList =
                        new FileModificationsListCreator(new ModificationClassificator()).CalculateFileModifications(
                            pairedFileInfos);
                    var fileModificationsListWithoutUnmodified = new UnmodifiedRemover().AlterList(fileModificationsList);
                    report = new FileModificationsReport(fileModificationsListWithoutUnmodified,
                                                         new ModificationItemToStringConverterUsingToString(), new HtmlLineBreaker());
                }
                catch (LfgLogFileDoesntExistException)
                {
                    report = new NewDirectoryReport();
                }
                new LogFileWriter(_fsl, new LogFileLinesFileInfoConverter(new LogLinesToFileInfoConverter()),
                                  logFileNameProvider).WriteLog(currentFileInfoWithoutLogFile, path);
            }
            catch (Exception ex) when(ex is FilesystemLayerException)
            {
                report = new ErrorMessageReport(ex.Message);
            }
            return(report);
        }