/// <summary>
        /// Configures <see cref="IMvcBuilder" /> to support runtime compilation of Razor views and Razor Pages.
        /// </summary>
        /// <param name="builder">The <see cref="IMvcBuilder" />.</param>
        /// <returns>The <see cref="IMvcBuilder"/>.</returns>
        public static IMvcBuilder AddRazorRuntimeCompilation(this IMvcBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            RazorRuntimeCompilationMvcCoreBuilderExtensions.AddServices(builder.Services);
            return(builder);
        }
        public void AddServices_DoesNotPageActionDescriptor_IfItWasNotPreviouslyFound()
        {
            // we want to make sure Page specific featurees are only added if AddRazorPages was called by the user.
            // Arrange
            var services = new ServiceCollection();

            // Act
            RazorRuntimeCompilationMvcCoreBuilderExtensions.AddServices(services);

            // Assert
            Assert.Empty(services.Where(service => service.ServiceType == typeof(IActionDescriptorProvider)));
            Assert.Empty(services.Where(service => service.ServiceType == typeof(MatcherPolicy)));
        }
        public void AddServices_ReplacesRazorViewCompiler()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddSingleton <IViewCompilerProvider, DefaultViewCompilerProvider>();

            // Act
            RazorRuntimeCompilationMvcCoreBuilderExtensions.AddServices(services);

            // Assert
            var serviceDescriptor = Assert.Single(services, service => service.ServiceType == typeof(IViewCompilerProvider));

            Assert.Equal(typeof(RuntimeViewCompilerProvider), serviceDescriptor.ImplementationType);
        }
        /// <summary>
        /// Configures <see cref="IMvcBuilder" /> to support runtime compilation of Razor views and Razor Pages.
        /// </summary>
        /// <param name="builder">The <see cref="IMvcBuilder" />.</param>
        /// <param name="setupAction">An action to configure the <see cref="MvcRazorRuntimeCompilationOptions"/>.</param>
        /// <returns>The <see cref="IMvcBuilder"/>.</returns>
        public static IMvcBuilder AddRazorRuntimeCompilation(this IMvcBuilder builder, Action <MvcRazorRuntimeCompilationOptions> setupAction)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (setupAction == null)
            {
                throw new ArgumentNullException(nameof(setupAction));
            }

            RazorRuntimeCompilationMvcCoreBuilderExtensions.AddServices(builder.Services);
            builder.Services.Configure(setupAction);
            return(builder);
        }
        public void AddServices_ReplacesActionDescriptorProvider()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddSingleton <IActionDescriptorProvider, CompiledPageActionDescriptorProvider>();

            // Act
            RazorRuntimeCompilationMvcCoreBuilderExtensions.AddServices(services);

            // Assert
            var serviceDescriptor = Assert.Single(services, service => service.ServiceType == typeof(IActionDescriptorProvider));

            Assert.Equal(typeof(PageActionDescriptorProvider), serviceDescriptor.ImplementationType);

            serviceDescriptor = Assert.Single(services, service => service.ServiceType == typeof(MatcherPolicy));
            Assert.Equal(typeof(PageLoaderMatcherPolicy), serviceDescriptor.ImplementationType);
        }