From fcd4484542733d9666aa981ba8709bb22ce3de4c Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Mon, 12 Mar 2018 15:31:12 -0700 Subject: [PATCH] Fix TagHelperDescriptor.Kind serialization --- .../TagHelperDescriptorJsonConverter.cs | 2 +- .../TagHelperDescriptorSerializationTest.cs | 52 ++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Serialization/TagHelperDescriptorJsonConverter.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Serialization/TagHelperDescriptorJsonConverter.cs index 271af9e1fd..72b4f98d24 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Serialization/TagHelperDescriptorJsonConverter.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/Serialization/TagHelperDescriptorJsonConverter.cs @@ -39,7 +39,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Serialization var diagnostics = descriptor[nameof(TagHelperDescriptor.Diagnostics)].Value(); var metadata = descriptor[nameof(TagHelperDescriptor.Metadata)].Value(); - var builder = TagHelperDescriptorBuilder.Create(typeName, assemblyName); + var builder = TagHelperDescriptorBuilder.Create(descriptorKind, typeName, assemblyName); builder.Documentation = documentation; builder.TagOutputHint = tagOutputHint; diff --git a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Serialization/TagHelperDescriptorSerializationTest.cs b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Serialization/TagHelperDescriptorSerializationTest.cs index b19a701506..9427f77e32 100644 --- a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Serialization/TagHelperDescriptorSerializationTest.cs +++ b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Serialization/TagHelperDescriptorSerializationTest.cs @@ -3,8 +3,8 @@ using System; using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.VisualStudio.LanguageServices.Razor.Serialization; using Newtonsoft.Json; using Xunit; @@ -18,6 +18,51 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor { // Arrange var expectedDescriptor = CreateTagHelperDescriptor( + kind: TagHelperConventions.DefaultKind, + tagName: "tag-name", + typeName: "type name", + assemblyName: "assembly name", + attributes: new Action[] + { + builder => builder + .Name("test-attribute") + .PropertyName("TestAttribute") + .TypeName("string"), + }, + ruleBuilders: new Action[] + { + builder => builder + .RequireAttributeDescriptor(attribute => attribute + .Name("required-attribute-one") + .NameComparisonMode(RequiredAttributeDescriptor.NameComparisonMode.PrefixMatch)) + .RequireAttributeDescriptor(attribute => attribute + .Name("required-attribute-two") + .NameComparisonMode(RequiredAttributeDescriptor.NameComparisonMode.FullMatch) + .Value("something") + .ValueComparisonMode(RequiredAttributeDescriptor.ValueComparisonMode.PrefixMatch)) + .RequireParentTag("parent-name") + .RequireTagStructure(TagStructure.WithoutEndTag), + }, + configureAction: builder => + { + builder.AllowChildTag("allowed-child-one"); + builder.AddMetadata("foo", "bar"); + }); + + // Act + var serializedDescriptor = JsonConvert.SerializeObject(expectedDescriptor, TagHelperDescriptorJsonConverter.Instance, RazorDiagnosticJsonConverter.Instance); + var descriptor = JsonConvert.DeserializeObject(serializedDescriptor, TagHelperDescriptorJsonConverter.Instance, RazorDiagnosticJsonConverter.Instance); + + // Assert + Assert.Equal(expectedDescriptor, descriptor, TagHelperDescriptorComparer.Default); + } + + [Fact] + public void ViewComponentTagHelperDescriptor_RoundTripsProperly() + { + // Arrange + var expectedDescriptor = CreateTagHelperDescriptor( + kind: ViewComponentTagHelperConventions.Kind, tagName: "tag-name", typeName: "type name", assemblyName: "assembly name", @@ -61,6 +106,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor { // Arrange var expectedDescriptor = CreateTagHelperDescriptor( + kind: TagHelperConventions.DefaultKind, tagName: "tag-name", typeName: "type name", assemblyName: "assembly name", @@ -105,6 +151,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor { // Arrange var expectedDescriptor = CreateTagHelperDescriptor( + kind: TagHelperConventions.DefaultKind, tagName: "tag-name", typeName: "type name", assemblyName: "assembly name", @@ -146,6 +193,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor } private static TagHelperDescriptor CreateTagHelperDescriptor( + string kind, string tagName, string typeName, string assemblyName, @@ -153,7 +201,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor IEnumerable> ruleBuilders = null, Action configureAction = null) { - var builder = TagHelperDescriptorBuilder.Create(typeName, assemblyName); + var builder = TagHelperDescriptorBuilder.Create(kind, typeName, assemblyName); builder.SetTypeName(typeName); if (attributes != null)