public void GetChangeToken_WatchesFilesUnderAreaRoot() { // Arrange var fileProvider = new Mock <IFileProvider>(); fileProvider.Setup(f => f.Watch(It.IsAny <string>())) .Returns(Mock.Of <IChangeToken>()); var accessor = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider.Object); var fileSystem = new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment); var templateEngine = new RazorTemplateEngine( RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine, fileSystem); var options = Options.Create(new RazorPagesOptions { AllowAreas = true }); var razorViewEngineOptions = Options.Create(new RazorViewEngineOptions { AllowRecompilingViewsOnFileChange = true }); var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options, razorViewEngineOptions); // Act var changeToken = changeProvider.GetChangeToken(); // Assert fileProvider.Verify(f => f.Watch("/Areas/**/*.cshtml")); }
public void GetChangeToken_WatchesViewImportsOutsidePagesRoot_WhenAreaFeatureIsDisabled() { // Arrange var fileProvider = new TestFileProvider(); var accessor = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider); var fileSystem = new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment); var templateEngine = new RazorTemplateEngine( RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine, fileSystem); templateEngine.Options.ImportsFileName = "_ViewImports.cshtml"; var options = Options.Create(new RazorPagesOptions { AllowAreas = false }); var razorViewEngineOptions = Options.Create(new RazorViewEngineOptions { AllowRecompilingViewsOnFileChange = true }); var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options, razorViewEngineOptions); // Act & Assert var compositeChangeToken = Assert.IsType <CompositeChangeToken>(changeProvider.GetChangeToken()); Assert.Collection(compositeChangeToken.ChangeTokens, changeToken => Assert.Same(fileProvider.GetChangeToken("/_ViewImports.cshtml"), changeToken), changeToken => Assert.Same(fileProvider.GetChangeToken("/Pages/**/*.cshtml"), changeToken)); }
public void GetChangeToken_DoesNotWatch_WhenOptionIsReset() { // Arrange var fileProvider = new Mock <IFileProvider>(MockBehavior.Strict); var accessor = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider.Object); var fileSystem = new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment); var templateEngine = new RazorTemplateEngine( RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine, fileSystem); templateEngine.Options.ImportsFileName = "_ViewImports.cshtml"; var options = Options.Create(new RazorPagesOptions()); var razorViewEngineOptions = Options.Create(new RazorViewEngineOptions()); var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options, razorViewEngineOptions); // Act & Assert var compositeChangeToken = Assert.IsType <NullChangeToken>(changeProvider.GetChangeToken()); fileProvider.Verify(f => f.Watch(It.IsAny <string>()), Times.Never()); }