コード例 #1
0
        public async Task LoadAsync_DoesNotCacheResults()
        {
            // Arrange
            var descriptor = new PageActionDescriptor()
            {
                AttributeRouteInfo = new AttributeRouteInfo()
                {
                    Template = "/test",
                },
            };

            var transformer = new Mock <RoutePatternTransformer>();

            transformer
            .Setup(t => t.SubstituteRequiredValues(It.IsAny <RoutePattern>(), It.IsAny <object>()))
            .Returns <RoutePattern, object>((p, v) => p);

            var compilerProvider = GetCompilerProvider();

            var mvcOptions      = Options.Create(new MvcOptions());
            var endpointFactory = new PublicActionEndpointFactory(transformer.Object);

            var provider = new Mock <IPageApplicationModelProvider>();

            var pageApplicationModel = new PageApplicationModel(descriptor, typeof(object).GetTypeInfo(), Array.Empty <object>());

            provider.Setup(p => p.OnProvidersExecuting(It.IsAny <PageApplicationModelProviderContext>()))
            .Callback((PageApplicationModelProviderContext c) => {
                Assert.Null(c.PageApplicationModel);
                c.PageApplicationModel = pageApplicationModel;
            })
            .Verifiable();

            var providers = new[]
            {
                provider.Object,
            };

            var loader = new RuntimeRazorPageLoader(
                providers,
                compilerProvider,
                endpointFactory,
                RazorPagesOptions,
                mvcOptions);

            // Act
            var result1 = await loader.LoadAsync(descriptor);

            var result2 = await loader.LoadAsync(descriptor);

            // Assert
            Assert.NotSame(result1.Id, result2.Id);
        }
コード例 #2
0
        public async Task LoadAsync_InvokesApplicationModelProviders()
        {
            // Arrange
            var descriptor = new PageActionDescriptor();

            var compilerProvider = GetCompilerProvider();

            var mvcOptions      = Options.Create(new MvcOptions());
            var endpointFactory = new PublicActionEndpointFactory(Mock.Of <RoutePatternTransformer>());

            var provider1 = new Mock <IPageApplicationModelProvider>();
            var provider2 = new Mock <IPageApplicationModelProvider>();

            var sequence = 0;
            var pageApplicationModel1 = new PageApplicationModel(descriptor, typeof(object).GetTypeInfo(), Array.Empty <object>());
            var pageApplicationModel2 = new PageApplicationModel(descriptor, typeof(object).GetTypeInfo(), Array.Empty <object>());

            provider1.Setup(p => p.OnProvidersExecuting(It.IsAny <PageApplicationModelProviderContext>()))
            .Callback((PageApplicationModelProviderContext c) => {
                Assert.Equal(0, sequence++);
                Assert.Null(c.PageApplicationModel);
                c.PageApplicationModel = pageApplicationModel1;
            })
            .Verifiable();

            provider2.Setup(p => p.OnProvidersExecuting(It.IsAny <PageApplicationModelProviderContext>()))
            .Callback((PageApplicationModelProviderContext c) => {
                Assert.Equal(1, sequence++);
                Assert.Same(pageApplicationModel1, c.PageApplicationModel);
                c.PageApplicationModel = pageApplicationModel2;
            })
            .Verifiable();

            provider1.Setup(p => p.OnProvidersExecuted(It.IsAny <PageApplicationModelProviderContext>()))
            .Callback((PageApplicationModelProviderContext c) => {
                Assert.Equal(3, sequence++);
                Assert.Same(pageApplicationModel2, c.PageApplicationModel);
            })
            .Verifiable();

            provider2.Setup(p => p.OnProvidersExecuted(It.IsAny <PageApplicationModelProviderContext>()))
            .Callback((PageApplicationModelProviderContext c) => {
                Assert.Equal(2, sequence++);
                Assert.Same(pageApplicationModel2, c.PageApplicationModel);
            })
            .Verifiable();

            var providers = new[]
            {
                provider1.Object, provider2.Object
            };

            var loader = new RuntimeRazorPageLoader(
                providers,
                compilerProvider,
                endpointFactory,
                RazorPagesOptions,
                mvcOptions);

            // Act
            var result = await loader.LoadAsync(new PageActionDescriptor());

            // Assert
            provider1.Verify();
            provider2.Verify();
        }