예제 #1
0
        protected override Task <int> ExecuteCoreAsync()
        {
            if (!Parent.Checker.Check(ExtensionFilePaths.Values))
            {
                Error.WriteLine($"Extensions could not be loaded. See output for details.");
                return(Task.FromResult(ExitCodeFailure));
            }

            // Loading all of the extensions should succeed as the dependency checker will have already
            // loaded them.
            var extensions = new RazorExtension[ExtensionNames.Values.Count];

            for (var i = 0; i < ExtensionNames.Values.Count; i++)
            {
                extensions[i] = new AssemblyExtension(ExtensionNames.Values[i], Parent.Loader.LoadFromPath(ExtensionFilePaths.Values[i]));
            }

            var version       = RazorLanguageVersion.Parse(Version.Value());
            var configuration = RazorConfiguration.Create(version, Configuration.Value(), extensions);

            var sourceItems = GetSourceItems(ProjectDirectory.Value(), Sources.Values, Outputs.Values, RelativePaths.Values, DocumentKinds.Values);

            var result = ExecuteCore(
                configuration: configuration,
                projectDirectory: ProjectDirectory.Value(),
                tagHelperManifest: TagHelperManifest.Value(),
                sourceItems: sourceItems);

            return(Task.FromResult(result));
        }
        public void RazorConfigurationJsonConverter_Serialization_MVC1_CanRead()
        {
            // Arrange
            var configurationJson = @"{
  ""ConfigurationName"": ""MVC-1.1"",
  ""Extensions"": [
    {
      ""ExtensionName"": ""MVC-1.1""
    }
  ],
  ""LanguageVersion"": {
    ""Major"": 1,
    ""Minor"": 1
  }
}";

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

            // Assert
            Assert.Equal("MVC-1.1", obj.ConfigurationName);
            var extension = Assert.Single(obj.Extensions);

            Assert.Equal("MVC-1.1", extension.ExtensionName);
            Assert.Equal(RazorLanguageVersion.Parse("1.1"), obj.LanguageVersion);
        }
예제 #3
0
        public void Equals_ReturnsTrue_IfRazorConfigurationAreDifferentInstancesButEqualValues()
        {
            // Arrange
            var options1 = new RazorSourceGenerationOptions
            {
                CSharpLanguageVersion = LanguageVersion.Latest,
                Configuration         = RazorConfiguration.Create(RazorLanguageVersion.Parse("6.0"), "Default", Enumerable.Empty <RazorExtension>(), useConsolidatedMvcViews: true),
                GenerateMetadataSourceChecksumAttributes = true,
                RootNamespace = "Asp",
                SupportLocalizedComponentNames = true,
                SuppressRazorSourceGenerator   = true,
            };

            var options2 = new RazorSourceGenerationOptions
            {
                Configuration         = RazorConfiguration.Create(RazorLanguageVersion.Parse("6.0"), "Default", Enumerable.Empty <RazorExtension>(), useConsolidatedMvcViews: true),
                CSharpLanguageVersion = LanguageVersion.Latest,
                GenerateMetadataSourceChecksumAttributes = true,
                RootNamespace = "Asp",
                SupportLocalizedComponentNames = true,
                SuppressRazorSourceGenerator   = true,
            };

            // Act
            var equals = options1.Equals(options2);

            // Assert
            Assert.True(equals);
        }
예제 #4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.StartObject)
            {
                return(null);
            }

            var obj = JObject.Load(reader);
            var configurationName = obj[nameof(RazorConfiguration.ConfigurationName)].Value <string>();
            var languageVersion   = obj[nameof(RazorConfiguration.LanguageVersion)].Value <string>();
            var extensions        = obj[nameof(RazorConfiguration.Extensions)].ToObject <RazorExtension[]>(serializer);

            return(RazorConfiguration.Create(RazorLanguageVersion.Parse(languageVersion), configurationName, extensions));
        }
예제 #5
0
    public void LatestPointsToNewestVersion()
    {
        // Arrange
        var v        = RazorLanguageVersion.Parse("latest");
        var versions = typeof(RazorLanguageVersion).GetFields(BindingFlags.Public | BindingFlags.Static)
                       .Where(f => f.Name.StartsWith("Version_", StringComparison.Ordinal))
                       .Select(f => f.GetValue(obj: null))
                       .Cast <RazorLanguageVersion>();

        // Act & Assert
        Assert.NotEmpty(versions);
        foreach (var version in versions)
        {
            Assert.True(version.CompareTo(v) <= 0, $"RazorLanguageVersion {version} has a higher version than RazorLanguageVersion.Latest");
        }
    }
예제 #6
0
        protected override Task <int> ExecuteCoreAsync()
        {
            // Loading all of the extensions should succeed as the dependency checker will have already
            // loaded them.
            var extensions = new RazorExtension[ExtensionNames.Values.Count];

            for (var i = 0; i < ExtensionNames.Values.Count; i++)
            {
                extensions[i] = new AssemblyExtension(ExtensionNames.Values[i], Parent.Loader.LoadFromPath(ExtensionFilePaths.Values[i]));
            }

            var version       = RazorLanguageVersion.Parse(Version.Value());
            var configuration = RazorConfiguration.Create(version, Configuration.Value(), extensions);

            var result = ExecuteCore(
                configuration: configuration,
                projectDirectory: ProjectDirectory.Value(),
                outputFilePath: TagHelperManifest.Value(),
                assemblies: Assemblies.Values.ToArray());

            return(Task.FromResult(result));
        }