// Internal for testing
        internal static bool TryGetConfiguration(
            IMSBuildEvaluatedPropertyCollection projectProperties,
            IEnumerable <IMSBuildItemEvaluated> projectItems,
            out RazorConfiguration configuration)
        {
            if (!TryGetDefaultConfiguration(projectProperties, out var defaultConfiguration))
            {
                configuration = null;
                return(false);
            }

            if (!TryGetLanguageVersion(projectProperties, out var languageVersion))
            {
                configuration = null;
                return(false);
            }

            if (!TryGetConfigurationItem(defaultConfiguration, projectItems, out var configurationItem))
            {
                configuration = null;
                return(false);
            }

            if (!TryGetConfiguredExtensionNames(configurationItem, out var configuredExtensionNames))
            {
                configuration = null;
                return(false);
            }

            var extensions = GetExtensions(configuredExtensionNames, projectItems);

            configuration = new ProjectSystemRazorConfiguration(languageVersion, configurationItem.Include, extensions);
            return(true);
        }
Ejemplo n.º 2
0
        // Internal for testing
        internal static bool TryGetConfiguration(
            ProjectInstance projectInstance,
            out ProjectConfiguration configuration)
        {
            if (!TryGetDefaultConfiguration(projectInstance, out var defaultConfiguration))
            {
                configuration = null;
                return(false);
            }

            if (!TryGetLanguageVersion(projectInstance, out var languageVersion))
            {
                configuration = null;
                return(false);
            }

            if (!TryGetConfigurationItem(defaultConfiguration, projectInstance.Items, out var configurationItem))
            {
                configuration = null;
                return(false);
            }

            var configuredExtensionNames = GetConfiguredExtensionNames(configurationItem);
            var rootNamespace            = GetRootNamespace(projectInstance);
            var extensions         = GetExtensions(configuredExtensionNames, projectInstance.Items);
            var razorConfiguration = new ProjectSystemRazorConfiguration(languageVersion, configurationItem.EvaluatedInclude, extensions);
            var hostDocuments      = GetHostDocuments(projectInstance.Items);

            configuration = new ProjectConfiguration(razorConfiguration, hostDocuments, rootNamespace);
            return(true);
        }
        public void RazorConfigurationJsonConverter_Serialization_CanRoundTrip()
        {
            // Arrange
            var configuration = new ProjectSystemRazorConfiguration(
                RazorLanguageVersion.Version_1_1,
                "Test",
                new[]
            {
                new ProjectSystemRazorExtension("Test-Extension1"),
                new ProjectSystemRazorExtension("Test-Extension2"),
            });

            // Act
            var json = JsonConvert.SerializeObject(configuration, Converters);
            var obj  = JsonConvert.DeserializeObject <RazorConfiguration>(json, Converters);

            // Assert
            Assert.Equal(configuration.ConfigurationName, obj.ConfigurationName);
            Assert.Collection(
                configuration.Extensions,
                e => Assert.Equal("Test-Extension1", e.ExtensionName),
                e => Assert.Equal("Test-Extension2", e.ExtensionName));
            Assert.Equal(configuration.LanguageVersion, obj.LanguageVersion);
        }