public void CreateFactory_ReturnsExpirationTokensFromCompilerCache_ForSuccessfulResults()
        {
            // Arrange
            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(new CompilationResult(typeof(object)), 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("/file-exists");

            // Assert
            Assert.True(result.Success);
            Assert.Equal(expirationTokens, result.ExpirationTokens);
        }
        public void CreateFactory_ProducesDelegateThatSetsPagePath()
        {
            // Arrange
            var compilerCache = new Mock <ICompilerCache>();

            compilerCache
            .Setup(f => f.GetOrAdd(It.IsAny <string>(), It.IsAny <Func <RelativeFileInfo, CompilationResult> >()))
            .Returns(new CompilerCacheResult(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("/file-exists");

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

            Assert.Equal("/file-exists", actual.Path);
        }
예제 #3
0
    public void CreateFactory_ProducesDelegateThatSetsPagePath()
    {
        // Arrange
        var relativePath = "/file-exists";
        var descriptor   = new CompiledViewDescriptor
        {
            RelativePath     = relativePath,
            Item             = TestRazorCompiledItem.CreateForView(typeof(TestRazorPage), relativePath),
            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);
    }
예제 #4
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,
            Item             = TestRazorCompiledItem.CreateForView(typeof(TestRazorPage), relativePath),
            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);
    }
예제 #5
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_ReturnsExpirationTokensFromCompilerCache_ForSuccessfulResults()
        {
            // Arrange
            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(new CompilationResult(typeof(object)), 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("/file-exists");

            // Assert
            Assert.True(result.Success);
            Assert.Equal(expirationTokens, result.ExpirationTokens);
        }
        public void CreateFactory_ProducesDelegateThatSetsPagePath()
        {
            // Arrange
            var compilerCache = new Mock<ICompilerCache>();
            compilerCache
                .Setup(f => f.GetOrAdd(It.IsAny<string>(), It.IsAny<Func<RelativeFileInfo, CompilationResult>>()))
                .Returns(new CompilerCacheResult(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("/file-exists");

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