Ejemplo n.º 1
0
        public void CreateFactory_ProducesDelegateThatSetsPagePath()
        {
            // Arrange
            var relativePath  = "/file-exists";
            var compilerCache = new Mock <ICompilerCache>();

            compilerCache
            .Setup(f => f.GetOrAdd(It.IsAny <string>(), It.IsAny <Func <RelativeFileInfo, CompilationResult> >()))
            .Returns(new CompilerCacheResult(relativePath, new CompilationResult(typeof(TestRazorPage)), new IChangeToken[0]));
            var compilerCacheProvider = new Mock <ICompilerCacheProvider>();

            compilerCacheProvider
            .SetupGet(c => c.Cache)
            .Returns(compilerCache.Object);
            var factoryProvider = new DefaultRazorPageFactoryProvider(
                Mock.Of <IRazorCompilationService>(),
                compilerCacheProvider.Object);

            // Act
            var result = factoryProvider.CreateFactory(relativePath);

            // Assert
            Assert.True(result.Success);
            var actual = result.RazorPageFactory();

            Assert.Equal("/file-exists", actual.Path);
        }
        public void CreateFactory_ReturnsExpirationTokensFromCompilerCache_ForSuccessfulResults()
        {
            // Arrange
            var relativePath = "/file-exists";
            var expirationTokens = new[]
            {
                Mock.Of<IChangeToken>(),
                Mock.Of<IChangeToken>(),
            };
            var compilerCache = new Mock<ICompilerCache>();
            compilerCache
                .Setup(f => f.GetOrAdd(It.IsAny<string>(), It.IsAny<Func<RelativeFileInfo, CompilationResult>>()))
                .Returns(new CompilerCacheResult(relativePath, new CompilationResult(typeof(TestRazorPage)), expirationTokens));
            var compilerCacheProvider = new Mock<ICompilerCacheProvider>();
            compilerCacheProvider
                .SetupGet(c => c.Cache)
                .Returns(compilerCache.Object);
            var factoryProvider = new DefaultRazorPageFactoryProvider(
                Mock.Of<IRazorCompilationService>(),
                compilerCacheProvider.Object);

            // Act
            var result = factoryProvider.CreateFactory(relativePath);

            // Assert
            Assert.True(result.Success);
            Assert.Equal(expirationTokens, result.ExpirationTokens);
        }
Ejemplo n.º 3
0
        public void CreateFactory_ReturnsExpirationTokensFromCompilerCache_ForSuccessfulResults()
        {
            // Arrange
            var relativePath     = "/file-exists";
            var expirationTokens = new[]
            {
                Mock.Of <IChangeToken>(),
                Mock.Of <IChangeToken>(),
            };
            var compilerCache = new Mock <ICompilerCache>();

            compilerCache
            .Setup(f => f.GetOrAdd(It.IsAny <string>(), It.IsAny <Func <RelativeFileInfo, CompilationResult> >()))
            .Returns(new CompilerCacheResult(relativePath, new CompilationResult(typeof(TestRazorPage)), expirationTokens));
            var compilerCacheProvider = new Mock <ICompilerCacheProvider>();

            compilerCacheProvider
            .SetupGet(c => c.Cache)
            .Returns(compilerCache.Object);
            var factoryProvider = new DefaultRazorPageFactoryProvider(
                Mock.Of <IRazorCompilationService>(),
                compilerCacheProvider.Object);

            // Act
            var result = factoryProvider.CreateFactory(relativePath);

            // Assert
            Assert.True(result.Success);
            Assert.Equal(expirationTokens, result.ExpirationTokens);
        }
Ejemplo n.º 4
0
        public void CreateFactory_ProducesDelegateThatSetsPagePath()
        {
            // Arrange
            var relativePath = "/file-exists";
            var descriptor   = new CompiledViewDescriptor
            {
                RelativePath     = relativePath,
                ViewAttribute    = new RazorViewAttribute(relativePath, typeof(TestRazorPage)),
                ExpirationTokens = Array.Empty <IChangeToken>(),
            };
            var viewCompiler = new Mock <IViewCompiler>();

            viewCompiler
            .Setup(f => f.CompileAsync(It.IsAny <string>()))
            .ReturnsAsync(descriptor);

            var factoryProvider = new DefaultRazorPageFactoryProvider(GetCompilerProvider(viewCompiler.Object));

            // Act
            var result = factoryProvider.CreateFactory(relativePath);

            // Assert
            Assert.True(result.Success);
            var actual = result.RazorPageFactory();

            Assert.Equal("/file-exists", actual.Path);
        }
Ejemplo n.º 5
0
        public void CreateFactory_ReturnsViewDescriptor_ForSuccessfulResults()
        {
            // Arrange
            var relativePath     = "/file-exists";
            var expirationTokens = new[]
            {
                Mock.Of <IChangeToken>(),
                Mock.Of <IChangeToken>(),
            };
            var descriptor = new CompiledViewDescriptor
            {
                RelativePath     = relativePath,
                ViewAttribute    = new RazorViewAttribute(relativePath, typeof(TestRazorPage)),
                ExpirationTokens = expirationTokens,
            };
            var compilerCache = new Mock <IViewCompiler>();

            compilerCache
            .Setup(f => f.CompileAsync(It.IsAny <string>()))
            .ReturnsAsync(descriptor);

            var factoryProvider = new DefaultRazorPageFactoryProvider(GetCompilerProvider(compilerCache.Object));

            // Act
            var result = factoryProvider.CreateFactory(relativePath);

            // Assert
            Assert.True(result.Success);
            Assert.Equal(expirationTokens, descriptor.ExpirationTokens);
        }
Ejemplo n.º 6
0
        public void CreateFactory_ReturnsViewDescriptor_ForUnsuccessfulResults()
        {
            // Arrange
            var path             = "/file-does-not-exist";
            var expirationTokens = new[]
            {
                Mock.Of <IChangeToken>(),
                Mock.Of <IChangeToken>(),
            };
            var descriptor = new CompiledViewDescriptor
            {
                RelativePath     = path,
                ExpirationTokens = expirationTokens,
            };
            var compilerCache = new Mock <IViewCompiler>();

            compilerCache
            .Setup(f => f.CompileAsync(It.IsAny <string>()))
            .ReturnsAsync(descriptor);

            var factoryProvider = new DefaultRazorPageFactoryProvider(GetCompilerProvider(compilerCache.Object));

            // Act
            var result = factoryProvider.CreateFactory(path);

            // Assert
            Assert.False(result.Success);
            Assert.Same(descriptor, result.ViewDescriptor);
        }
        public void CreateFactory_ProducesDelegateThatSetsPagePath()
        {
            // Arrange
            var relativePath = "/file-exists";
            var compilerCache = new Mock<ICompilerCache>();
            compilerCache
                .Setup(f => f.GetOrAdd(It.IsAny<string>(), It.IsAny<Func<RelativeFileInfo, CompilationResult>>()))
                .Returns(new CompilerCacheResult(relativePath, new CompilationResult(typeof(TestRazorPage)), new IChangeToken[0]));
            var compilerCacheProvider = new Mock<ICompilerCacheProvider>();
            compilerCacheProvider
                .SetupGet(c => c.Cache)
                .Returns(compilerCache.Object);
            var factoryProvider = new DefaultRazorPageFactoryProvider(
                Mock.Of<IRazorCompilationService>(),
                compilerCacheProvider.Object);

            // Act
            var result = factoryProvider.CreateFactory(relativePath);

            // Assert
            Assert.True(result.Success);
            var actual = result.RazorPageFactory();
            Assert.Equal("/file-exists", actual.Path);
        }