static string DetermineAndCreateResultPathIfNotExistant(PackageDescription description)
        {
            var resultFile = String.Format("{0}-{1}...{2}.html", description.PackageId, description.Versions.LeftVersion, description.Versions.RightVersion);

            var rootPath = Environment.GetEnvironmentVariable("HOME"); // TODO: use AzureEnvironment

            if (rootPath != null)
            {
                rootPath = Path.Combine(rootPath, @".\site\wwwroot");
            }
            else
            {
                rootPath = Environment.GetEnvironmentVariable("APICOMPARER_WWWROOT", EnvironmentVariableTarget.User);
            }

            if (String.IsNullOrEmpty(rootPath))
            {
                throw new Exception("No root path could be found. If in development please set the `APICOMPARER_WWWROOT` env variable to the root folder of the webproject");
            }

            var directoryPath = Path.Combine(rootPath, "Comparisons");

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            var resultPath = Path.Combine(directoryPath, resultFile);
            return resultPath;
        }
        static string DetermineAndCreateResultPathIfNotExistant(PackageDescription description)
        {
            var resultFile = $"{description.PackageId}-{description.Versions.LeftVersion}...{description.Versions.RightVersion}.html";

            var rootPath = Environment.GetEnvironmentVariable("HOME"); // TODO: use AzureEnvironment

            if (rootPath != null)
            {
                rootPath = Path.Combine(rootPath, @".\site\wwwroot");
            }
            else
            {
                rootPath = Environment.GetEnvironmentVariable("APICOMPARER_WWWROOT", EnvironmentVariableTarget.User);
            }

            if (string.IsNullOrEmpty(rootPath))
            {
                throw new Exception("No root path could be found. If in development please set the `APICOMPARER_WWWROOT` env variable to the root folder of the webproject");
            }

            var directoryPath = Path.Combine(rootPath, "Comparisons");

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            var resultPath = Path.Combine(directoryPath, resultFile);

            return(resultPath);
        }
        public void ReportFailure(PackageDescription packageDescription, Exception exception)
        {
            var resultPath = DetermineAndCreateResultPathIfNotExistant(packageDescription);

            File.WriteAllText(resultPath, $"{packageDescription.PackageId} comparison between {packageDescription.Versions.LeftVersion} and {packageDescription.Versions.RightVersion} has failed with the following error: {exception.Message}");
            RemoveTemporaryWorkFiles(resultPath);
        }
        public CompareSet[] Create(PackageDescription description)
        {
            var nugetDownloader = new NuGetDownloader(description.PackageId, new List<string> { "https://www.nuget.org/api/v2" });

            var leftTargets = nugetDownloader.DownloadAndExtractVersion(description.Versions.LeftVersion)
                .ToList();

            var rightTargets = nugetDownloader.DownloadAndExtractVersion(description.Versions.RightVersion)
                .ToList();

            return CompareSets.Create(leftTargets, rightTargets).ToArray();
        }
Exemple #5
0
        public CompareSet[] Create(PackageDescription description)
        {
            var nugetDownloader = new NuGetDownloader(description.PackageId, new List <string>
            {
                "https://www.nuget.org/api/v2"
            });

            var leftTargets = nugetDownloader.DownloadAndExtractVersion(description.Versions.LeftVersion)
                              .ToList();

            var rightTargets = nugetDownloader.DownloadAndExtractVersion(description.Versions.RightVersion)
                               .ToList();

            return(CompareSets.Create(leftTargets, rightTargets).ToArray());
        }
        public void Report(PackageDescription description, DiffedCompareSet[] diffedCompareSets)
        {
            var resultPath = DetermineAndCreateResultPathIfNotExistant(description);

            using (var fileStream = File.OpenWrite(resultPath))
            using (var into = new StreamWriter(fileStream))
            {
                var formatter = new APIUpgradeToHtmlFormatter();
                formatter.Render(into, description, diffedCompareSets);

                @into.Flush();
                @into.Close();
                fileStream.Close();
            }
            RemoveTemporaryWorkFiles(resultPath);
        }
        public void TestComplianceLibLog()
        {
            var formatter = new APIUpgradeToHtmlFormatter();
            var writer = new StringWriter();
            var packageDescription = new PackageDescription
            {
                PackageId = "LibLog",
                Versions = new VersionPair("3.0.0", "4.1.1")
            };
            var compareSetCreator = new CompareSetCreator();
            var sets = compareSetCreator.Create(packageDescription);
            var compareSetDiffer = new CompareSetDiffer();
            var diff = compareSetDiffer.Diff(sets);

            formatter.Render(writer, packageDescription, diff);

            Approvals.VerifyHtml(writer.ToString());
        }
        public void AppccelerateEventBrokerNoChanges()
        {
            var formatter = new APIUpgradeToHtmlFormatter();
            var writer = new StringWriter();
            var packageDescription = new PackageDescription
            {
                PackageId = "Appccelerate.EventBroker",
                Versions = new VersionPair("3.1.0", "3.15.0")
            };
            var compareSetCreator = new CompareSetCreator();
            var sets = compareSetCreator.Create(packageDescription);
            var compareSetDiffer = new CompareSetDiffer();
            var diff = compareSetDiffer.Diff(sets);

            formatter.Render(writer, packageDescription, diff);

            Approvals.VerifyHtml(writer.ToString());
        }
        public void Report(PackageDescription description, DiffedCompareSet[] diffedCompareSets)
        {
            var resultPath = DetermineAndCreateResultPathIfNotExistant(description);

            using (var fileStream = File.OpenWrite(resultPath))
            {
                using (var into = new StreamWriter(fileStream))
                {
                    var formatter = new APIUpgradeToHtmlFormatter();
                    formatter.Render(into, description, diffedCompareSets);

                    @into.Flush();
                    @into.Close();
                    fileStream.Close();
                }
            }
            RemoveTemporaryWorkFiles(resultPath);
        }
        private string HtmlDiff(string packageName, string fromVersion, string untilVersion)
        {
            using (var writer = new StringWriter())
            {
                var formatter = new APIUpgradeToHtmlFormatter();

                var packageDescription = new PackageDescription
                {
                    PackageId = packageName,
                    Versions = new VersionPair(fromVersion, untilVersion)
                };

                var compareSetCreator = new CompareSetCreator();
                var sets = compareSetCreator.Create(packageDescription);
                var compareSetDiffer = new CompareSetDiffer();
                var diff = compareSetDiffer.Diff(sets);

                formatter.Render(writer, packageDescription, diff);

                return writer.ToString();
            }
        }