示例#1
0
        public void GetExtensions_SomeConfiguredExtensions_ReturnsConfiguredExtensions()
        {
            // Arrange
            var expectedExtension1Name = "Extension1";
            var expectedExtension2Name = "Extension2";
            var projectItems           = new IMSBuildItemEvaluated[]
            {
                new TestMSBuildItem("RazorExtension")
                {
                    Include = "UnconfiguredExtensionName",
                },
                new TestMSBuildItem("RazorExtension")
                {
                    Include = expectedExtension1Name,
                },
                new TestMSBuildItem("RazorExtension")
                {
                    Include = expectedExtension2Name,
                },
            };

            // Act
            var extensions = DefaultMacRazorProjectHost.GetExtensions(new[] { expectedExtension1Name, expectedExtension2Name }, projectItems);

            // Assert
            Assert.Collection(
                extensions,
                extension => Assert.Equal(expectedExtension1Name, extension.ExtensionName),
                extension => Assert.Equal(expectedExtension2Name, extension.ExtensionName));
        }
示例#2
0
        public void IsRazorDocumentItem_NoInclude_ReturnsFalse()
        {
            // Arrange
            var item = new TestMSBuildItem("Content");

            // Act
            var result = DefaultMacRazorProjectHost.IsRazorDocumentItem(item);

            // Assert
            Assert.False(result);
        }
示例#3
0
        public void GetExtensionNames_FailsIfNoExtensions()
        {
            // Arrange
            var configurationItem = new TestMSBuildItem("RazorConfiguration");

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

            // Assert
            Assert.Empty(extensionNames);
        }
示例#4
0
        public void TryGetLanguageVersion_FailsIfNoLanguageVersion()
        {
            // Arrange
            var projectProperties = new MSBuildPropertyGroup();

            // Act
            var result = DefaultMacRazorProjectHost.TryGetLanguageVersion(projectProperties, out var languageVersion);

            // Assert
            Assert.False(result);
            Assert.Null(languageVersion);
        }
示例#5
0
        public void TryGetConfigurationItem_FailsNoRazorConfigurationItems()
        {
            // Arrange
            var projectItems = Enumerable.Empty <IMSBuildItemEvaluated>();

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

            // Assert
            Assert.False(result);
            Assert.Null(configurationItem);
        }
示例#6
0
        public void TryGetDefaultConfiguration_FailsIfNoConfiguration()
        {
            // Arrange
            var projectProperties = new MSBuildPropertyGroup();

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

            // Assert
            Assert.False(result);
            Assert.Null(defaultConfiguration);
        }
示例#7
0
        public void TryGetConfiguration_FailsIfNoDefaultConfiguration()
        {
            // Arrange
            var projectProperties = new MSBuildPropertyGroup();
            var projectItems      = Array.Empty <IMSBuildItemEvaluated>();

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

            // Assert
            Assert.False(result);
            Assert.Null(configuration);
        }
示例#8
0
        public void GetExtensionNames_FailsIfEmptyExtensions()
        {
            // Arrange
            var configurationItem = new TestMSBuildItem("RazorConfiguration");

            configurationItem.TestMetadata.SetValue("Extensions", string.Empty);

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

            // Assert
            Assert.Empty(extensionNames);
        }
示例#9
0
        public void IsRazorDocumentItem_NonRazorFile_ReturnsFalse()
        {
            // Arrange
            var item = new TestMSBuildItem("Content")
            {
                Include = "\\Path\\To\\File.notrazor",
            };

            // Act
            var result = DefaultMacRazorProjectHost.IsRazorDocumentItem(item);

            // Assert
            Assert.False(result);
        }
示例#10
0
        public void TryGetConfiguration_SucceedsWithAllPreRequisites()
        {
            // Arrange
            var expectedLanguageVersion        = RazorLanguageVersion.Version_1_0;
            var expectedConfigurationName      = "Razor-Test";
            var expectedExtension1Name         = "Extension1";
            var expectedExtension2Name         = "Extension2";
            var expectedRazorConfigurationItem = new TestMSBuildItem("RazorConfiguration")
            {
                Include = expectedConfigurationName,
            };

            expectedRazorConfigurationItem.TestMetadata.SetValue("Extensions", "Extension1;Extension2");
            var projectItems = new IMSBuildItemEvaluated[]
            {
                new TestMSBuildItem("RazorConfiguration")
                {
                    Include = "UnconfiguredRazorConfiguration",
                },
                new TestMSBuildItem("RazorExtension")
                {
                    Include = "UnconfiguredExtensionName",
                },
                new TestMSBuildItem("RazorExtension")
                {
                    Include = expectedExtension1Name,
                },
                new TestMSBuildItem("RazorExtension")
                {
                    Include = expectedExtension2Name,
                },
                expectedRazorConfigurationItem,
            };
            var projectProperties = new MSBuildPropertyGroup();

            projectProperties.SetValue("RazorDefaultConfiguration", expectedConfigurationName);
            projectProperties.SetValue("RazorLangVersion", "1.0");

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

            // Assert
            Assert.True(result);
            Assert.Equal(expectedLanguageVersion, configuration.LanguageVersion);
            Assert.Equal(expectedConfigurationName, configuration.ConfigurationName);
            Assert.Collection(
                configuration.Extensions,
                extension => Assert.Equal(expectedExtension1Name, extension.ExtensionName),
                extension => Assert.Equal(expectedExtension2Name, extension.ExtensionName));
        }
示例#11
0
        public void IsRazorDocumentItem_CSHTMLFile_ReturnsTrue()
        {
            // Arrange
            var item = new TestMSBuildItem("Content")
            {
                Include = "\\Path\\To\\File.cshtml",
            };

            // Act
            var result = DefaultMacRazorProjectHost.IsRazorDocumentItem(item);

            // Assert
            Assert.True(result);
        }
示例#12
0
        public void TryGetLanguageVersion_SucceedsWithUnknownLanguageVersion_DefaultsToLatest()
        {
            // Arrange
            var projectProperties = new MSBuildPropertyGroup();

            projectProperties.SetValue("RazorLangVersion", "13.37");

            // Act
            var result = DefaultMacRazorProjectHost.TryGetLanguageVersion(projectProperties, out var languageVersion);

            // Assert
            Assert.True(result);
            Assert.Same(RazorLanguageVersion.Latest, languageVersion);
        }
示例#13
0
        public void TryGetLanguageVersion_SucceedsWithValidLanguageVersion()
        {
            // Arrange
            var projectProperties = new MSBuildPropertyGroup();

            projectProperties.SetValue("RazorLangVersion", "1.0");

            // Act
            var result = DefaultMacRazorProjectHost.TryGetLanguageVersion(projectProperties, out var languageVersion);

            // Assert
            Assert.True(result);
            Assert.Same(RazorLanguageVersion.Version_1_0, languageVersion);
        }
示例#14
0
        public void TryGetLanguageVersion_FailsIfEmptyLanguageVersion()
        {
            // Arrange
            var projectProperties = new MSBuildPropertyGroup();

            projectProperties.SetValue("RazorLangVersion", string.Empty);

            // Act
            var result = DefaultMacRazorProjectHost.TryGetLanguageVersion(projectProperties, out var languageVersion);

            // Assert
            Assert.False(result);
            Assert.Null(languageVersion);
        }
示例#15
0
        public void TryGetDefaultConfiguration_SucceedsWithValidConfiguration()
        {
            // Arrange
            var expectedConfiguration = "Razor-13.37";
            var projectProperties     = new MSBuildPropertyGroup();

            projectProperties.SetValue("RazorDefaultConfiguration", expectedConfiguration);

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

            // Assert
            Assert.True(result);
            Assert.Equal(expectedConfiguration, defaultConfiguration);
        }
示例#16
0
        public void GetExtensionNames_SucceedsIfSingleExtension()
        {
            // Arrange
            var expectedExtensionName = "SomeExtensionName";
            var configurationItem     = new TestMSBuildItem("RazorConfiguration");

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

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

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

            Assert.Equal(expectedExtensionName, extensionName);
        }
示例#17
0
        public void GetExtensionNames_SucceedsIfMultipleExtensions()
        {
            // Arrange
            var configurationItem = new TestMSBuildItem("RazorConfiguration");

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

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

            // Assert
            Assert.Collection(
                extensionNames,
                name => Assert.Equal("SomeExtensionName", name),
                name => Assert.Equal("SomeOtherExtensionName", name));
        }
示例#18
0
        public void TryGetConfiguration_FailsIfNoConfigurationItems()
        {
            // Arrange
            var projectProperties = new MSBuildPropertyGroup();

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

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

            // Assert
            Assert.False(result);
            Assert.Null(configuration);
        }
示例#19
0
        public void GetExtensions_UnConfiguredExtensionTypes_ReturnsEmptyArray()
        {
            // Arrange
            var projectItems = new IMSBuildItemEvaluated[]
            {
                new TestMSBuildItem("RazorExtension")
                {
                    Include = "UnconfiguredExtensionName",
                },
            };

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

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

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

            // Assert
            Assert.False(result);
            Assert.Null(configurationItem);
        }
示例#21
0
        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 = DefaultMacRazorProjectHost.TryGetConfiguration(projectProperties, projectItems, out var configuration);

            // Assert
            Assert.True(result);
            Assert.Empty(configuration.Extensions);
        }
示例#22
0
        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 = DefaultMacRazorProjectHost.TryGetConfigurationItem(expectedConfiguration, projectItems, out var configurationItem);

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