public void ConfigureAfterRazorViewEngineOptionsSetupIsExecuted_CorrectlySetsUpOptimizationLevel()
        {
            // Arrange
            var dependencyContextOptions = new DependencyContextOptions(
                new[] { "MyDefine" },
                languageVersion: null,
                platform: null,
                allowUnsafe: null,
                warningsAsErrors: null,
                optimize: true,
                keyFile: null,
                delaySign: null,
                publicSign: null,
                debugType: null,
                emitEntryPoint: null,
                generateXmlDocumentation: null);
            var dependencyContextSetup = new TestableDependencyContextOptionsSetup(dependencyContextOptions);
            var options            = new RazorViewEngineOptions();
            var hostingEnvironment = new Mock <IHostingEnvironment>();

            hostingEnvironment.SetupGet(e => e.EnvironmentName)
            .Returns("Development");
#pragma warning disable 0618
            var viewEngineSetup = new RazorViewEngineOptionsSetup(hostingEnvironment.Object);
#pragma warning restore 0618

            // Act
            viewEngineSetup.Configure(options);
            dependencyContextSetup.Configure(options);

            // Assert
            Assert.Equal(OptimizationLevel.Release, options.CompilationOptions.OptimizationLevel);
        }
        public void Configure_SetsDefines()
        {
            // Arrange
            var dependencyContextOptions = new DependencyContextOptions(
                new[] { "MyDefine" },
                languageVersion: "csharp4",
                platform: null,
                allowUnsafe: null,
                warningsAsErrors: null,
                optimize: true,
                keyFile: null,
                delaySign: null,
                publicSign: null,
                debugType: null,
                emitEntryPoint: null,
                generateXmlDocumentation: null);
            var setup   = new TestableDependencyContextOptionsSetup(dependencyContextOptions);
            var options = new RazorViewEngineOptions();

            // Act
            setup.Configure(options);

            // Assert
            Assert.Equal(new[] { "MyDefine" }, options.ParseOptions.PreprocessorSymbolNames);
        }
        public void Configure_SetsOptimizationLevel()
        {
            // Arrange
            var dependencyContextOptions = new DependencyContextOptions(
                new[] { "MyDefine" },
                languageVersion: null,
                platform: null,
                allowUnsafe: null,
                warningsAsErrors: null,
                optimize: true,
                keyFile: null,
                delaySign: null,
                publicSign: null,
                debugType: null,
                emitEntryPoint: null,
                generateXmlDocumentation: null);
            var setup   = new TestableDependencyContextOptionsSetup(dependencyContextOptions);
            var options = new RazorViewEngineOptions();

            // Act
            setup.Configure(options);

            // Assert
            Assert.False(options.CompilationOptions.AllowUnsafe);
            Assert.Equal(ReportDiagnostic.Default, options.CompilationOptions.GeneralDiagnosticOption);
            Assert.Equal(OptimizationLevel.Release, options.CompilationOptions.OptimizationLevel);
        }
        public void GetCompilationOptions_ReturnsCompilationOptionsFromDependencyContext()
        {
            // Arrange
            var hostingEnvironment = new Mock <IHostingEnvironment>();

            hostingEnvironment.SetupGet(e => e.ApplicationName)
            .Returns(GetType().GetTypeInfo().Assembly.GetName().Name);
            var setup = new TestableDependencyContextOptionsSetup(hostingEnvironment.Object);

            // Act
            var options = setup.GetCompilationOptionsPublic();

            // Assert
            Assert.Contains("SOME_TEST_DEFINE", options.Defines);
        }
        public void GetCompilationOptions_ReturnsDefaultOptionsIfApplicationDoesNotHaveDependencyContext()
        {
            // Arrange
            var hostingEnvironment = new Mock <IHostingEnvironment>();

            hostingEnvironment.SetupGet(e => e.ApplicationName)
            .Returns(typeof(Controller).GetTypeInfo().Assembly.GetName().Name);
            var setup = new TestableDependencyContextOptionsSetup(hostingEnvironment.Object);

            // Act
            var options = setup.GetCompilationOptionsPublic();

            // Assert
            Assert.Same(DependencyContextOptions.Default, options);
        }
        public void GetCompilationOptions_ReturnsDefaultOptionsIfApplicationNameIsNullOrEmpty(string name)
        {
            // Arrange
            var hostingEnvironment = new Mock <IHostingEnvironment>();

            hostingEnvironment.SetupGet(e => e.ApplicationName)
            .Returns(name);
            var setup = new TestableDependencyContextOptionsSetup(hostingEnvironment.Object);

            // Act
            var options = setup.GetCompilationOptionsPublic();

            // Assert
            Assert.Same(DependencyContextOptions.Default, options);
        }