Exemplo n.º 1
0
        public void IsRazorDocumentItem_NoInclude_ReturnsFalse()
        {
            // Arrange
            var item = new TestMSBuildItem("Content");

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

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

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

            // Assert
            Assert.Empty(extensionNames);
        }
        public void TryGetConfiguredExtensionNames_FailsIfNoExtensions()
        {
            // Arrange
            var configurationItem = new TestMSBuildItem("RazorConfiguration");

            // Act
            var result = DefaultRazorProjectHost.TryGetConfiguredExtensionNames(configurationItem, out var configuredExtensionnames);

            // Assert
            Assert.False(result);
            Assert.Null(configuredExtensionnames);
        }
        public void GetExtensionNames_FailsIfEmptyExtensions()
        {
            // Arrange
            var configurationItem = new TestMSBuildItem("RazorConfiguration");

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

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

            // Assert
            Assert.Empty(extensionNames);
        }
        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 = DefaultRazorProjectHost.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));
        }
Exemplo n.º 6
0
        public void IsRazorDocumentItem_CSHTMLFile_ReturnsTrue()
        {
            // Arrange
            var item = new TestMSBuildItem("Content")
            {
                Include = "\\Path\\To\\File.cshtml",
            };

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

            // Assert
            Assert.True(result);
        }
Exemplo n.º 7
0
        public void IsRazorDocumentItem_NonRazorFile_ReturnsFalse()
        {
            // Arrange
            var item = new TestMSBuildItem("Content")
            {
                Include = "\\Path\\To\\File.notrazor",
            };

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

            // Assert
            Assert.False(result);
        }
        public void TryGetConfiguredExtensionNames_FailsIfEmptyExtensions()
        {
            // Arrange
            var configurationItem = new TestMSBuildItem("RazorConfiguration");

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

            // Act
            var result = DefaultRazorProjectHost.TryGetConfiguredExtensionNames(configurationItem, out var configuredExtensionNames);

            // Assert
            Assert.False(result);
            Assert.Null(configuredExtensionNames);
        }
        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 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);
        }