예제 #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);
        }