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)); }
public void IsRazorDocumentItem_NoInclude_ReturnsFalse() { // Arrange var item = new TestMSBuildItem("Content"); // Act var result = DefaultMacRazorProjectHost.IsRazorDocumentItem(item); // Assert Assert.False(result); }
public void GetExtensionNames_FailsIfNoExtensions() { // Arrange var configurationItem = new TestMSBuildItem("RazorConfiguration"); // Act var extensionNames = DefaultMacRazorProjectHost.GetExtensionNames(configurationItem); // Assert Assert.Empty(extensionNames); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }