Exemple #1
0
        public static void Verify(string text)
        {
            var writer = new ApprovalTextWriter(text);
            var namer  = new ApprovalNamer();

            Approvals.Verify(writer, namer, Approvals.GetReporter());
        }
Exemple #2
0
        private void Approve(CommandDocumentation model, CommandLineHelpConfiguration?configuration = null)
        {
            var pathProvider = new DefaultCommandLineHelpPathProvider();
            var documentSet  = new DocumentSet <IDocument>();

            configuration ??= new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            var commandPage = new CommandPage(documentSet, pathProvider, model, configuration);

            // add dummy application page and command page itself to document set
            // because command page will create a link to the application page
            // which would fail otherwise
            documentSet.Add(pathProvider.GetPath(model.Application), new TextDocument());
            documentSet.Add(pathProvider.GetPath(model), commandPage);

            var doc = commandPage.GetDocument();

            Assert.NotNull(doc);

            var markdown = doc.ToString();

            var writer = new ApprovalTextWriter(markdown);

            Approvals.Verify(writer, new ApprovalNamer(relativeOutputDirectory: "../../../_referenceResults"), Approvals.GetReporter());
        }
            public static void ApprovePublicApi(Assembly assembly)
            {
                var publicApi     = ApiGenerator.GeneratePublicApi(assembly, new ApiGeneratorOptions());
                var writer        = new ApprovalTextWriter(publicApi, "cs");
                var approvalNamer = new AssemblyPathNamer(assembly.Location);

                Approvals.Verify(writer, approvalNamer, Approvals.GetReporter());
            }
Exemple #4
0
        public void TestDetectUtf8ByteOrderMark()
        {
            var with    = PathUtilities.GetAdjacentFile("FileWithUtf8ByteOrderMark.txt");
            var without = PathUtilities.GetAdjacentFile("FileWithoutUtf8ByteOrderMark.txt");

            Assert.IsTrue(ApprovalTextWriter.IsUft8ByteOrderMarkPresent(with));
            Assert.IsFalse(ApprovalTextWriter.IsUft8ByteOrderMarkPresent(without));
        }
Exemple #5
0
        public void GeneratePublicApiDescription()
        {
            Assembly assembly      = typeof(Fail).Assembly;
            var      publicApi     = assembly.GeneratePublicApi();
            var      writer        = new ApprovalTextWriter(publicApi, "txt");
            var      approvalNamer = new AssemblyPathNamer(assembly);

            Approvals.Verify(writer, approvalNamer, Approvals.GetReporter());
        }
Exemple #6
0
        public void Assembly_must_not_have_unapproved_API_changes()
        {
            // ARRANGE
            var assembly = typeof(Badge).Assembly;

            // ACT
            var publicApi = ApiGenerator.GeneratePublicApi(assembly, options: null);

            // ASSERT
            var writer = new ApprovalTextWriter(publicApi);

            Approvals.Verify(writer, new UnitTestFrameworkNamer(), Approvals.GetReporter());
        }
Exemple #7
0
        protected void Approve(TModel model, ApiReferenceConfiguration?configuration = null)
        {
            configuration ??= new ConfigurationProvider().GetDefaultApiReferenceConfiguration();

            var page = CreatePage(model, configuration);

            var doc = page.GetDocument();

            Assert.NotNull(doc);
            var writer = new ApprovalTextWriter(doc.ToString());

            Approvals.Verify(writer, new ApprovalNamer(GetType().Name, relativeOutputDirectory: "../../_referenceResults"), Approvals.GetReporter());
        }
Exemple #8
0
        protected void Approve(ApplicationChangeLog changeLog, ChangeLogConfiguration?configuration = null)
        {
            var sut = GetTemplateInstance(configuration ?? ChangeLogConfigurationLoader.GetDefaultConfiguration());

            using (var temporaryDirectory = new TemporaryDirectory())
            {
                var outputPath = Path.Combine(temporaryDirectory, "changelog.md");
                sut.SaveChangeLog(changeLog, outputPath);

                Assert.True(File.Exists(outputPath));

                var output = File.ReadAllText(outputPath);

                var writer = new ApprovalTextWriter(output);
                Approvals.Verify(writer, new ApprovalNamer(GetType().Name), Approvals.GetReporter());
            }
        }
Exemple #9
0
        private void Approve(SingleCommandApplicationDocumentation model, CommandLineHelpConfiguration?configuration = null)
        {
            var pathProvider = new DefaultCommandLineHelpPathProvider();
            var documentSet  = new DocumentSet <IDocument>();

            configuration ??= new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            var applicationPage = new SingleCommandApplicationPage(documentSet, pathProvider, model, configuration);

            documentSet.Add(pathProvider.GetPath(model), applicationPage);

            var doc = applicationPage.GetDocument();

            Assert.NotNull(doc);
            var writer = new ApprovalTextWriter(doc.ToString());

            Approvals.Verify(writer, new ApprovalNamer(relativeOutputDirectory: "../../../_referenceResults"), Approvals.GetReporter());
        }
Exemple #10
0
        public static void ApprovePublicApi(string assemblyPath)
        {
            var assemblyResolver = new DefaultAssemblyResolver();

            assemblyResolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath));

            var readSymbols = File.Exists(Path.ChangeExtension(assemblyPath, ".pdb"));
            var asm         = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters(ReadingMode.Deferred)
            {
                ReadSymbols      = readSymbols,
                AssemblyResolver = assemblyResolver,
            });

            var publicApi     = PublicApiGenerator.CreatePublicApiForAssembly(asm);
            var writer        = new ApprovalTextWriter(publicApi, "cs");
            var approvalNamer = new AssemblyPathNamer(assemblyPath);

            ApprovalTests.Approvals.Verify(writer, approvalNamer, ApprovalTests.Approvals.GetReporter());
        }
Exemple #11
0
        public void MakeBadge_returns_expected_svg(
            BadgeStyle style,
            [CombinatorialValues("Hello")] string leftText,
            [CombinatorialValues("World")] string rightText,
            [CombinatorialValues("yellow", "red")] string color,
            [CombinatorialValues(null, "", "blue")] string labelColor,
            [CombinatorialValues(null, "http://example.com")] string leftLink,
            [CombinatorialValues(null, "http://github.com")] string rightLink)
        {
            var testId = GetTestCaseFileName(style, leftText, rightText, color, labelColor, leftLink, rightLink);

            var leftUri  = leftLink != null ? new Uri(leftLink) : null;
            var rightUri = rightLink != null ? new Uri(rightLink) : null;

            var badge  = Badge.MakeBadge(style, leftText, rightText, color, labelColor, leftUri, rightUri);
            var writer = new ApprovalTextWriter(GetBadgeHtml(badge, style, leftText, rightText, color, labelColor, leftLink, rightLink), "html");

            Approvals.Verify(writer, new ApprovalNamer(testId), Approvals.GetReporter());
        }
Exemple #12
0
        protected void Approve(string testCaseName)
        {
            var writer = new ApprovalTextWriter(LoadOutput(), "html");

            Approvals.Verify(writer, new ApprovalNamer(testCaseName), Approvals.GetReporter());
        }