Esempio n. 1
0
        public void GetChangeToken_WatchesFilesUnderCustomAreaRoot(string rootDirectory)
        {
            // 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 templateEngine = new RazorTemplateEngine(
                RazorEngine.Create(),
                new FileProviderRazorProject(accessor, _hostingEnvironment));
            var options = Options.Create(new RazorPagesOptions
            {
                AllowAreas        = true,
                AreaRootDirectory = rootDirectory,
            });
            var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);

            // Act
            var changeToken = changeProvider.GetChangeToken();

            // Assert
            fileProvider.Verify(f => f.Watch("/areas-base-dir/**/*.cshtml"));
        }
        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"));
        }
Esempio n. 3
0
        public void GetChangeToken_WatchesViewImportsOutsidePagesRoot_WhenAreaPagesRootIsNested()
        {
            // Arrange
            var fileProvider = new TestFileProvider();
            var accessor     = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);

            var templateEngine = new RazorTemplateEngine(
                RazorEngine.Create(),
                new FileProviderRazorProject(accessor, _hostingEnvironment));

            templateEngine.Options.ImportsFileName = "_ViewImports.cshtml";
            var options = Options.Create(new RazorPagesOptions());

            options.Value.RootDirectory     = "/dir1/dir2";
            options.Value.AreaRootDirectory = "/dir3/dir4";
            options.Value.AllowAreas        = true;

            var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);

            // Act & Assert
            var compositeChangeToken = Assert.IsType <CompositeChangeToken>(changeProvider.GetChangeToken());

            Assert.Collection(compositeChangeToken.ChangeTokens,
                              changeToken => Assert.Same(fileProvider.GetChangeToken("/dir1/_ViewImports.cshtml"), changeToken),
                              changeToken => Assert.Same(fileProvider.GetChangeToken("/_ViewImports.cshtml"), changeToken),
                              changeToken => Assert.Same(fileProvider.GetChangeToken("/dir3/_ViewImports.cshtml"), changeToken),
                              changeToken => Assert.Same(fileProvider.GetChangeToken("/dir1/dir2/**/*.cshtml"), changeToken),
                              changeToken => Assert.Same(fileProvider.GetChangeToken("/dir3/dir4/**/*.cshtml"), changeToken));
        }
        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_WatchesAllCshtmlFilesUnderSpecifiedRootDirectory(string rootDirectory)
        {
            // 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());

            options.Value.RootDirectory = rootDirectory;

            var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);

            // Act
            var changeToken = changeProvider.GetChangeToken();

            // Assert
            fileProvider.Verify(f => f.Watch("/pages-base-dir/**/*.cshtml"));
        }
Esempio n. 6
0
        public void GetChangeToken_WatchesAllCshtmlFilesUnderFileSystemRoot()
        {
            // Arrange
            var fileProvider = new Mock <IFileProvider>();
            var accessor     = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider.Object);

            var templateEngine = new RazorTemplateEngine(
                RazorEngine.Create(),
                new FileProviderRazorProject(accessor));
            var options        = Options.Create(new RazorPagesOptions());
            var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);

            // Act
            var changeToken = changeProvider.GetChangeToken();

            // Assert
            fileProvider.Verify(f => f.Watch("/Pages/**/*.cshtml"));
        }
Esempio n. 7
0
        public void GetChangeToken_WatchesAllCshtmlFilesUnderSpecifiedRootDirectory(string rootDirectory)
        {
            // Arrange
            var fileProvider = new Mock <IFileProvider>();
            var accessor     = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider.Object);

            var templateEngine = new RazorTemplateEngine(
                RazorEngine.Create(),
                new FileProviderRazorProject(accessor));
            var options = Options.Create(new RazorPagesOptions());

            options.Value.RootDirectory = rootDirectory;

            var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);

            // Act
            var changeToken = changeProvider.GetChangeToken();

            // Assert
            fileProvider.Verify(f => f.Watch("/pages-base-dir/**/*.cshtml"));
        }
        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());
        }
        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 templateEngine = new RazorTemplateEngine(
                RazorEngine.Create(),
                new FileProviderRazorProject(accessor));
            var options = Options.Create(new RazorPagesOptions {
                EnableAreas = true
            });
            var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);

            // 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 templateEngine = new RazorTemplateEngine(
                RazorEngine.Create(),
                new FileProviderRazorProject(accessor));

            templateEngine.Options.ImportsFileName = "_ViewImports.cshtml";
            var options = Options.Create(new RazorPagesOptions {
                EnableAreas = false
            });

            var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);

            // 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));
        }