Exemple #1
0
        public void TryGetConfiguration_FailsIfNoLanguageVersion()
        {
            // Arrange
            var projectProperties = new MSBuildPropertyGroup();

            projectProperties.SetValue("RazorDefaultConfiguration", "Razor-13.37");
            var projectItems = Array.Empty <IMSBuildItemEvaluated>();

            // Act
            var result = DefaultRazorProjectHost.TryGetConfiguration(projectProperties, projectItems, out var configuration);

            // Assert
            Assert.False(result);
            Assert.Null(configuration);
        }
Exemple #2
0
        public void TryGetDefaultConfiguration_SucceedsWithValidConfiguration()
        {
            // Arrange
            var expectedConfiguration = "Razor-13.37";
            var projectProperties     = new MSBuildPropertyGroup();

            projectProperties.SetValue("RazorDefaultConfiguration", expectedConfiguration);

            // Act
            var result = DefaultRazorProjectHost.TryGetDefaultConfiguration(projectProperties, out var defaultConfiguration);

            // Assert
            Assert.True(result);
            Assert.Equal(expectedConfiguration, defaultConfiguration);
        }
        public void GetExtensionNames_SucceedsIfMultipleExtensions()
        {
            // Arrange
            var configurationItem = new TestMSBuildItem("RazorConfiguration");

            configurationItem.TestMetadata.SetValue("Extensions", "SomeExtensionName;SomeOtherExtensionName");

            // Act
            var extensionNames = DefaultRazorProjectHost.GetExtensionNames(configurationItem);

            // Assert
            Assert.Collection(
                extensionNames,
                name => Assert.Equal("SomeExtensionName", name),
                name => Assert.Equal("SomeOtherExtensionName", name));
        }
        public void GetExtensionNames_SucceedsIfSingleExtension()
        {
            // Arrange
            var expectedExtensionName = "SomeExtensionName";
            var configurationItem     = new TestMSBuildItem("RazorConfiguration");

            configurationItem.TestMetadata.SetValue("Extensions", expectedExtensionName);

            // Act
            var extensionNames = DefaultRazorProjectHost.GetExtensionNames(configurationItem);

            // Assert
            var extensionName = Assert.Single(extensionNames);

            Assert.Equal(expectedExtensionName, extensionName);
        }
        public void GetExtensions_UnConfiguredExtensionTypes_ReturnsEmptyArray()
        {
            // Arrange
            var projectItems = new IMSBuildItemEvaluated[]
            {
                new TestMSBuildItem("RazorExtension")
                {
                    Include = "UnconfiguredExtensionName",
                },
            };

            // Act
            var extensions = DefaultRazorProjectHost.GetExtensions(new[] { "Extension1", "Extension2" }, projectItems);

            // Assert
            Assert.Empty(extensions);
        }
        public void TryGetConfigurationItem_FailsNoMatchingRazorConfigurationItems()
        {
            // Arrange
            var projectItems = new IMSBuildItemEvaluated[]
            {
                new TestMSBuildItem("RazorConfiguration")
                {
                    Include = "Razor-10.0",
                }
            };

            // Act
            var result = DefaultRazorProjectHost.TryGetConfigurationItem("Razor-13.37", projectItems, out var configurationItem);

            // Assert
            Assert.False(result);
            Assert.Null(configurationItem);
        }
        public void TryGetConfiguration_SucceedsWithoutConfiguredExtensionNames()
        {
            // Arrange
            var projectProperties = new MSBuildPropertyGroup();

            projectProperties.SetValue("RazorDefaultConfiguration", "Razor-13.37");
            projectProperties.SetValue("RazorLangVersion", "1.0");
            var projectItems = new IMSBuildItemEvaluated[]
            {
                new TestMSBuildItem("RazorConfiguration")
                {
                    Include = "Razor-13.37",
                },
            };

            // Act
            var result = DefaultRazorProjectHost.TryGetConfiguration(projectProperties, projectItems, out var configuration);

            // Assert
            Assert.True(result);
            Assert.Empty(configuration.Extensions);
        }
        public void TryGetConfigurationItem_SucceedsForMatchingConfigurationItem()
        {
            // Arrange
            var expectedConfiguration     = "Razor-13.37";
            var expectedConfigurationItem = new TestMSBuildItem("RazorConfiguration")
            {
                Include = expectedConfiguration,
            };
            var projectItems = new IMSBuildItemEvaluated[]
            {
                new TestMSBuildItem("RazorConfiguration")
                {
                    Include = "Razor-10.0-DoesNotMatch",
                },
                expectedConfigurationItem
            };

            // Act
            var result = DefaultRazorProjectHost.TryGetConfigurationItem(expectedConfiguration, projectItems, out var configurationItem);

            // Assert
            Assert.True(result);
            Assert.Same(expectedConfigurationItem, configurationItem);
        }