コード例 #1
0
        protected void AssertDocumentNodeMatchesBaseline(RazorCodeDocument codeDocument)
        {
            var document         = codeDocument.GetDocumentIntermediateNode();
            var baselineFilePath = GetBaselineFilePath(codeDocument, ".ir.txt");

            if (GenerateBaselines)
            {
                var baselineFullPath = Path.Combine(TestProjectRoot, baselineFilePath);
                Directory.CreateDirectory(Path.GetDirectoryName(baselineFullPath));
                WriteBaseline(IntermediateNodeSerializer.Serialize(document), baselineFullPath);

                return;
            }

            var irFile = TestFile.Create(baselineFilePath, GetType().Assembly);

            if (!irFile.Exists())
            {
                throw new XunitException($"The resource {baselineFilePath} was not found.");
            }

            // Normalize newlines by splitting into an array.
            var baseline = irFile.ReadAllText().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            IntermediateNodeVerifier.Verify(document, baseline);
        }
コード例 #2
0
        protected void AssertDocumentNodeMatchesBaseline(DocumentIntermediateNode document)
        {
            if (FileName == null)
            {
                var message = $"{nameof(AssertDocumentNodeMatchesBaseline)} should only be called from an integration test ({nameof(FileName)} is null).";
                throw new InvalidOperationException(message);
            }

            var baselineFileName = Path.ChangeExtension(FileName, ".ir.txt");

            if (GenerateBaselines)
            {
                var baselineFullPath = Path.Combine(TestProjectRoot, baselineFileName);
                File.WriteAllText(baselineFullPath, IntermediateNodeSerializer.Serialize(document));
                return;
            }

            var irFile = TestFile.Create(baselineFileName, GetType().GetTypeInfo().Assembly);

            if (!irFile.Exists())
            {
                throw new XunitException($"The resource {baselineFileName} was not found.");
            }

            var baseline = irFile.ReadAllText().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            IntermediateNodeVerifier.Verify(document, baseline);
        }