Exemplo n.º 1
0
        private static void BuildFeatureCompareResultExistInOneFolderOnly(IEnumerable<string> notExistInOtherDir,
            List<DirectoryInfo> featureFolderList,
            CompareResult compareResult,
            bool isFirstFolder)
        {
            foreach (var feature in notExistInOtherDir)
            {
                var folder = featureFolderList.First(x => x.Name == feature);
                var featureCompareResult = new FeatureFolderCompareResult();
                featureCompareResult.FeatureFolderName = folder.Name;
                featureCompareResult.FeatureFolderFullName = folder.FullName;
                featureCompareResult.Status = isFirstFolder
                    ? FolderCompareStatus.FirstFolderOnly
                    : FolderCompareStatus.SecondFolderOnly;

                var files = folder.GetFiles("*.json").ToList();
                foreach (var fileInfo in files)
                {
                    var fileCompareResult = new DataFileCompareResult();
                    fileCompareResult.FileName = fileInfo.Name;
                    fileCompareResult.FullName = fileInfo.FullName;
                    fileCompareResult.Status = isFirstFolder
                        ? FileCompareStatus.FirstFolderOnly
                        : FileCompareStatus.SecondFolderOnly;

                    featureCompareResult.ListDataFileCompareResult.Add(fileCompareResult);
                }

                compareResult.ListFeatureFolderCompareResult.Add(featureCompareResult);
            }
        }
Exemplo n.º 2
0
        private static void BuildFileCompareResultExistInOneFolderOnly(IEnumerable<string> fileNotExistInOtherFolder,
            FileInfo[] fileInFolder
            , FeatureFolderCompareResult featureCompareResult,
            bool isFirstFolder)
        {
            foreach (var fileName in fileNotExistInOtherFolder)
            {
                var fileInfo = fileInFolder.First(x => x.Name == fileName);
                var fileCompareResult = new DataFileCompareResult();
                fileCompareResult.FileName = fileName;
                fileCompareResult.FullName = fileInfo.FullName;
                fileCompareResult.Status = isFirstFolder
                    ? FileCompareStatus.FirstFolderOnly
                    : FileCompareStatus.SecondFolderOnly;

                featureCompareResult.ListDataFileCompareResult.Add(fileCompareResult);
            }
        }
Exemplo n.º 3
0
        private static void CompareFileContent(FileInfo[] filesInFirstFolder, string fileName, FileInfo[] filesInSecondFolder,
            FeatureFolderCompareResult featureCompareResult)
        {
            //compare file content with just read content as string and compare string
            var file1 = filesInFirstFolder.First(x => x.Name == fileName);
            var file2 = filesInSecondFolder.First(x => x.Name == fileName);

            var fileContent1 = File.ReadAllText(file1.FullName);
            var fileContent2 = File.ReadAllText(file2.FullName);

            // Compare the JSON versions of the file
            var json1 = JsonConvert.DeserializeObject(fileContent1) as JToken;
            var json2 = JsonConvert.DeserializeObject(fileContent2) as JToken;

            // To compare strings, use:
            // if (String.CompareOrdinal(fileContent1, fileContent2) != 0)

            if (!JToken.DeepEquals(json1, json2))
            {
                //content is different
                var fileCompareResult = new DataFileCompareResult();
                fileCompareResult.FileName = fileName;
                fileCompareResult.Status = FileCompareStatus.DifferentContent;

                featureCompareResult.ListDataFileCompareResult.Add(fileCompareResult);
            }
        }
Exemplo n.º 4
0
        private static FeatureFolderCompareResult CompareFeatureFolders(string dirName, List<DirectoryInfo> firstFeatureFolderList,
            List<DirectoryInfo> secondFeatureFolderList)
        {
            var featureCompareResult = new FeatureFolderCompareResult();
            featureCompareResult.FeatureFolderName = dirName;
            featureCompareResult.Status = FolderCompareStatus.BothFolder;

            //list all files in first folder
            var filesInFirstFolder = firstFeatureFolderList.First(x => x.Name == dirName).GetFiles("*.json");
            //list all files in second folder
            var filesInSecondFolder = secondFeatureFolderList.First(x => x.Name == dirName).GetFiles("*.json");

            var fileNameInFirstFolder = filesInFirstFolder.Select(x => x.Name).ToList();
            var fileNameInSecondFolder = filesInSecondFolder.Select(x => x.Name).ToList();

            var fileNotExistInFirstFolder = fileNameInSecondFolder.Except(fileNameInFirstFolder);
            var fileNotExistInSecondFolder = fileNameInFirstFolder.Except(fileNameInSecondFolder);

            BuildFileCompareResultExistInOneFolderOnly(fileNotExistInFirstFolder, filesInSecondFolder, featureCompareResult,
                false);
            BuildFileCompareResultExistInOneFolderOnly(fileNotExistInSecondFolder, filesInFirstFolder, featureCompareResult,
                true);

            var fileExistInBothDir = fileNameInFirstFolder.Intersect(fileNameInSecondFolder);
            foreach (var fileName in fileExistInBothDir)
            {
                CompareFileContent(filesInFirstFolder, fileName, filesInSecondFolder, featureCompareResult);
            }
            return featureCompareResult;
        }