public void GetFileInfo_SampleHtmlInputShouldMatchExpected(string testName)
        {
            var inputText    = TestFileSource.ReadEmbeddedTextFile("HtmlRewriter", $"{testName}_input.html");
            var expectedText = TestFileSource.ReadEmbeddedTextFile("HtmlRewriter", $"{testName}_expected.html");

            mockFileProvider.SetFileInfo("index.html", inputText);
            mockHttpContextAccessor.PathBase = "/path/to/";

            var options = new UrlRewriteSpaStaticFilesOptions
            {
                SourcePathBase = "./",
            };

            using var urlRewriteFileProvider = new UrlRewriteFileProvider(mockFileProvider, mockHttpContextAccessor, options);
            var actual = urlRewriteFileProvider.GetFileInfo("index.html");

            Assert.Equal("index.html", actual.Name);
            Assert.True(actual.Exists);

            using var actualReadStream = actual.CreateReadStream();
            using var actualReader     = new StreamReader(actualReadStream);
            var actualText = actualReader.ReadToEnd();

            Assert.Equal(expectedText, actualText);

            Assert.Null(actual.PhysicalPath);
            Assert.True(actual.LastModified > MockFileProvider.DefaultModifiedTime);
            Assert.Equal(actual.Length, Encoding.UTF8.GetBytes(expectedText).Length);
        }
Пример #2
0
        public void Rewrite_SampleInputShouldMatchExpected(string testName)
        {
            var input    = TestFileSource.ReadEmbeddedTextFile("HtmlRewriter", $"{testName}_input.html");
            var expected = TestFileSource.ReadEmbeddedTextFile("HtmlRewriter", $"{testName}_expected.html");

            var actual = rewriter.Rewrite(input, sourcePathBase: "./", targetPathBase: "/path/to/");

            Assert.Equal(expected, actual);
        }
Пример #3
0
        public void Rewrite_SampleInputShouldMatchExpected_WhenUpdateBaseElementHrefOnly(string testName)
        {
            var input    = TestFileSource.ReadEmbeddedTextFile("HtmlRewriter", $"{testName}_input.html");
            var expected = TestFileSource.ReadEmbeddedTextFile("HtmlRewriter", $"{testName}_expected_baseonly.html");

            rewriter.UpdateBaseElementHrefOnly = true;
            var actual = rewriter.Rewrite(input, sourcePathBase: "./", targetPathBase: "/path/to/");

            Assert.Equal(expected, actual);
        }