public void GetDescriptors_LocatesTagHelperCodeGenerator_CreatesDirectiveDescriptors() { // Arrange var resolver = new TestTagHelperDescriptorResolver(); var tagHelperDirectiveSpanVisitor = new TagHelperDirectiveSpanVisitor(resolver, new ParserErrorSink()); var document = new MarkupBlock( Factory.Code("\"one\"").AsAddTagHelper("one"), Factory.Code("\"two\"").AsRemoveTagHelper("two"), Factory.Code("\"three\"").AsRemoveTagHelper("three"), Factory.Code("\"four\"").AsTagHelperPrefixDirective("four")); var expectedDescriptors = new TagHelperDirectiveDescriptor[] { new TagHelperDirectiveDescriptor("one", TagHelperDirectiveType.AddTagHelper), new TagHelperDirectiveDescriptor("two", TagHelperDirectiveType.RemoveTagHelper), new TagHelperDirectiveDescriptor("three", TagHelperDirectiveType.RemoveTagHelper), new TagHelperDirectiveDescriptor("four", TagHelperDirectiveType.TagHelperPrefix), }; // Act tagHelperDirectiveSpanVisitor.GetDescriptors(document); // Assert Assert.Equal( expectedDescriptors, resolver.DirectiveDescriptors, TagHelperDirectiveDescriptorComparer.Default); }
public void GetDescriptors_RemovesSpecifiedTagHelper() { // Arrange var resolver = new TestTagHelperDescriptorResolver( new Dictionary <string, IEnumerable <TagHelperDescriptor> > { { "twoTagHelpers", new[] { PTagHelperDescriptor, DivTagHelperDescriptor } }, { "singleTagHelper", new [] { PTagHelperDescriptor } } }); var addOrRemoveTagHelperSpanVisitor = new AddOrRemoveTagHelperSpanVisitor(resolver); var document = new MarkupBlock( Factory.Code("\"twoTagHelpers\"").AsAddTagHelper("twoTagHelpers"), Factory.Code("\"singleTagHelper\"").AsRemoveTagHelper("singleTagHelper")); // Act var descriptors = addOrRemoveTagHelperSpanVisitor.GetDescriptors(document); // Assert var descriptor = Assert.Single(descriptors); Assert.Equal(DivTagHelperDescriptor, descriptor, TagHelperDescriptorComparer.Default); Assert.Equal(2, resolver.Lookups.Count); Assert.Contains("twoTagHelpers", resolver.Lookups); Assert.Contains("singleTagHelper", resolver.Lookups); }
public void GetDescriptors_LocatesTagHelperPrefixDirectiveCodeGenerator() { // Arrange var resolver = new TestTagHelperDescriptorResolver(); var tagHelperDirectiveSpanVisitor = new TagHelperDirectiveSpanVisitor(resolver, new ParserErrorSink()); var document = new MarkupBlock( new DirectiveBlock( Factory.CodeTransition(), Factory .MetaCode(SyntaxConstants.CSharp.TagHelperPrefixKeyword + " ") .Accepts(AcceptedCharacters.None), Factory.Code("\"something\"").AsTagHelperPrefixDirective("something"))); var expectedDirectiveDescriptor = new TagHelperDirectiveDescriptor("something", TagHelperDirectiveType.TagHelperPrefix); // Act tagHelperDirectiveSpanVisitor.GetDescriptors(document); // Assert var directiveDescriptor = Assert.Single(resolver.DirectiveDescriptors); Assert.Equal( expectedDirectiveDescriptor, directiveDescriptor, TagHelperDirectiveDescriptorComparer.Default); }
public void DescriptorResolver_CreatesErrorIfNullOrEmptyLookupText_DoesNotThrow(string lookupText) { // Arrange var errorSink = new ParserErrorSink(); var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver( new TestTagHelperTypeResolver(InvalidTestableTagHelpers)); var documentLocation = new SourceLocation(1, 2, 3); var directiveType = TagHelperDirectiveType.AddTagHelper; var expectedErrorMessage = Resources.FormatTagHelperDescriptorResolver_InvalidTagHelperLookupText(lookupText); var resolutionContext = new TagHelperDescriptorResolutionContext( new [] { new TagHelperDirectiveDescriptor(lookupText, documentLocation, directiveType) }, errorSink); // Act tagHelperDescriptorResolver.Resolve(resolutionContext); // Assert var error = Assert.Single(errorSink.Errors); Assert.Equal(1, error.Length); Assert.Equal(documentLocation, error.Location); Assert.Equal(expectedErrorMessage, error.Message); }
public void GetDescriptors_LocatesNestedRemoveTagHelperCodeGenerator() { // Arrange var resolver = new TestTagHelperDescriptorResolver( new Dictionary <string, IEnumerable <TagHelperDescriptor> > { { "something", new[] { PTagHelperDescriptor } } }); var addOrRemoveTagHelperSpanVisitor = new AddOrRemoveTagHelperSpanVisitor(resolver); var document = new MarkupBlock( new DirectiveBlock( Factory.CodeTransition(), Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ") .Accepts(AcceptedCharacters.None), Factory.Code("\"something\"").AsRemoveTagHelper("something")) ); // Act var descriptors = addOrRemoveTagHelperSpanVisitor.GetDescriptors(document); // Assert Assert.Empty(descriptors); var lookup = Assert.Single(resolver.Lookups); Assert.Equal("something", lookup); }
public void GetDescriptors_LocatesNestedRemoveTagHelperChunkGenerator() { // Arrange var resolver = new TestTagHelperDescriptorResolver(); var tagHelperDirectiveSpanVisitor = new TagHelperDirectiveSpanVisitor(resolver, new ErrorSink()); var document = new MarkupBlock( new DirectiveBlock( Factory.CodeTransition(), Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ") .Accepts(AcceptedCharacters.None), Factory.Code("\"something\"").AsRemoveTagHelper("something")) ); var expectedRegistration = new TagHelperDirectiveDescriptor { DirectiveText = "something", DirectiveType = TagHelperDirectiveType.RemoveTagHelper }; // Act tagHelperDirectiveSpanVisitor.GetDescriptors(document); // Assert var directiveDescriptor = Assert.Single(resolver.DirectiveDescriptors); Assert.Equal(expectedRegistration, directiveDescriptor, TagHelperDirectiveDescriptorComparer.Default); }
public void GetDescriptors_LocatesQuotedTagHelperDirectives_CreatesDirectiveDescriptors( MarkupBlock document, IEnumerable <TagHelperDirectiveDescriptor> expectedDescriptors) { // Arrange var resolver = new TestTagHelperDescriptorResolver(); var tagHelperDirectiveSpanVisitor = new TagHelperDirectiveSpanVisitor(resolver, new ErrorSink()); // Act tagHelperDirectiveSpanVisitor.GetDescriptors(document); // Assert Assert.Equal( expectedDescriptors, resolver.DirectiveDescriptors, TagHelperDirectiveDescriptorComparer.Default); }
public void DescriptorResolver_IgnoresSpaces(string lookupText) { // Arrange var tagHelperTypeResolver = new TestTagHelperTypeResolver(TestableTagHelpers) { OnGetExportedTypes = (assemblyName) => { Assert.Equal("MyAssembly", assemblyName.Name); } }; var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver(tagHelperTypeResolver); // Act var descriptors = tagHelperDescriptorResolver.Resolve(lookupText); // Assert Assert.Empty(descriptors); }
public void Resolve_CanReturnEmptyDescriptorsBasedOnDirectiveDescriptors( Dictionary <string, IEnumerable <Type> > descriptorAssemblyLookups, IEnumerable <TagHelperDirectiveDescriptor> directiveDescriptors) { // Arrange var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver(descriptorAssemblyLookups)); var resolutionContext = new TagHelperDescriptorResolutionContext( directiveDescriptors, new ParserErrorSink()); // Act var descriptors = tagHelperDescriptorResolver.Resolve(resolutionContext); // Assert Assert.Empty(descriptors); }
public void DescriptorResolver_DoesNotResolveTypesForNoTypeResolvingLookupText() { // Arrange var resolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver( new Dictionary <string, IEnumerable <Type> >(StringComparer.OrdinalIgnoreCase) { { AssemblyName, ValidTestableTagHelpers }, { Valid_PlainTagHelperType.FullName + ", " + AssemblyName, new Type[] { Valid_PlainTagHelperType } } })); // Act var descriptors = resolver.Resolve("lookupText").ToArray(); // Assert Assert.Empty(descriptors); }
public void DescriptorResolver_DoesNotReturnInvalidTagHelpersWhenSpecified() { // Arrange var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver( new TestTagHelperTypeResolver(TestableTagHelpers)); // Act var descriptors = tagHelperDescriptorResolver.Resolve( "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_AbstractTagHelper, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_GenericTagHelper`, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_NestedPublicTagHelper, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_NestedInternalTagHelper, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_PrivateTagHelper, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_ProtectedTagHelper, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_InternalTagHelper, " + AssemblyName); // Assert Assert.Empty(descriptors); }
public void GetDescriptors_RemovesAddedTagHelpers() { // Arrange var resolver = new TestTagHelperDescriptorResolver( new Dictionary <string, IEnumerable <TagHelperDescriptor> > { { "twoTagHelpers", new[] { PTagHelperDescriptor, DivTagHelperDescriptor } } }); var addOrRemoveTagHelperSpanVisitor = new AddOrRemoveTagHelperSpanVisitor(resolver); var document = new MarkupBlock( Factory.Code("\"twoTagHelpers\"").AsAddTagHelper("twoTagHelpers"), Factory.Code("\"twoTagHelpers\"").AsRemoveTagHelper("twoTagHelpers")); // Act var descriptors = addOrRemoveTagHelperSpanVisitor.GetDescriptors(document); // Assert Assert.Empty(descriptors); Assert.Equal(Enumerable.Repeat("twoTagHelpers", 2), resolver.Lookups); }
public void GetDescriptors_CanOverrideResolutionContext() { // Arrange var resolver = new TestTagHelperDescriptorResolver(); var expectedInitialDirectiveDescriptors = new TagHelperDirectiveDescriptor[] { new TagHelperDirectiveDescriptor("one", TagHelperDirectiveType.AddTagHelper), new TagHelperDirectiveDescriptor("two", TagHelperDirectiveType.RemoveTagHelper), new TagHelperDirectiveDescriptor("three", TagHelperDirectiveType.RemoveTagHelper), new TagHelperDirectiveDescriptor("four", TagHelperDirectiveType.TagHelperPrefix), }; var expectedEndDirectiveDescriptors = new TagHelperDirectiveDescriptor[] { new TagHelperDirectiveDescriptor("custom", TagHelperDirectiveType.AddTagHelper) }; var tagHelperDirectiveSpanVisitor = new CustomTagHelperDirectiveSpanVisitor( resolver, (descriptors, errorSink) => { Assert.Equal( expectedInitialDirectiveDescriptors, descriptors, TagHelperDirectiveDescriptorComparer.Default); return(new TagHelperDescriptorResolutionContext(expectedEndDirectiveDescriptors, errorSink)); }); var document = new MarkupBlock( Factory.Code("\"one\"").AsAddTagHelper("one"), Factory.Code("\"two\"").AsRemoveTagHelper("two"), Factory.Code("\"three\"").AsRemoveTagHelper("three"), Factory.Code("\"four\"").AsTagHelperPrefixDirective("four")); // Act tagHelperDirectiveSpanVisitor.GetDescriptors(document); // Assert Assert.Equal(expectedEndDirectiveDescriptors, resolver.DirectiveDescriptors, TagHelperDirectiveDescriptorComparer.Default); }
public void DescriptorResolver_ResolvesOnlyTypeResolverProvidedTypes() { // Arrange var resolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver( new Dictionary <string, IEnumerable <Type> >(StringComparer.OrdinalIgnoreCase) { { AssemblyName, ValidTestableTagHelpers }, { Valid_PlainTagHelperType.FullName + ", " + AssemblyName, new Type[] { Valid_PlainTagHelperType } } })); // Act var descriptors = resolver.Resolve(Valid_PlainTagHelperType + ", " + AssemblyName); // Assert var descriptor = Assert.Single(descriptors); Assert.Equal(Valid_PlainTagHelperDescriptor, descriptor, CompleteTagHelperDescriptorComparer.Default); }
public void DescriptorResolver_ResolvesMultipleTypes() { // Arrange var resolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver( new Dictionary <string, IEnumerable <Type> >(StringComparer.OrdinalIgnoreCase) { { AssemblyName, new Type[] { Valid_PlainTagHelperType, Valid_InheritedTagHelperType } }, })); var expectedDescriptors = new TagHelperDescriptor[] { Valid_PlainTagHelperDescriptor, Valid_InheritedTagHelperDescriptor }; // Act var descriptors = resolver.Resolve(AssemblyName).ToArray(); // Assert Assert.Equal(descriptors.Length, 2); Assert.Equal(expectedDescriptors, descriptors, CompleteTagHelperDescriptorComparer.Default); }
public void Resolve_ReturnsDescriptorsBasedOnDirectiveDescriptors( Dictionary <string, IEnumerable <Type> > descriptorAssemblyLookups, IEnumerable <TagHelperDirectiveDescriptor> directiveDescriptors, IEnumerable <TagHelperDescriptor> expectedDescriptors) { // Arrange var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver(descriptorAssemblyLookups)); var resolutionContext = new TagHelperDescriptorResolutionContext( directiveDescriptors, new ParserErrorSink()); // Act var descriptors = tagHelperDescriptorResolver.Resolve(resolutionContext); // Assert Assert.Equal(expectedDescriptors.Count(), descriptors.Count()); foreach (var expectedDescriptor in expectedDescriptors) { Assert.Contains(expectedDescriptor, descriptors, TagHelperDescriptorComparer.Default); } }
public void Resolve_CreatesExpectedErrorsForTagHelperPrefixDirectives( Dictionary<string, IEnumerable<Type>> descriptorAssemblyLookups, IEnumerable<TagHelperDirectiveDescriptor> directiveDescriptors, IEnumerable<TagHelperDescriptor> expectedDescriptors, IEnumerable<RazorError> expectedErrors) { // Arrange var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver(descriptorAssemblyLookups)); var errorSink = new ParserErrorSink(); var resolutionContext = new TagHelperDescriptorResolutionContext( directiveDescriptors, errorSink); // Act var descriptors = tagHelperDescriptorResolver.Resolve(resolutionContext); // Assert Assert.Equal(expectedErrors, errorSink.Errors); Assert.Equal(expectedDescriptors.Count(), descriptors.Count()); foreach (var expectedDescriptor in expectedDescriptors) { Assert.Contains(expectedDescriptor, descriptors, TagHelperDescriptorComparer.Default); } }
public void Resolve_ReturnsDescriptorsBasedOnDirectiveDescriptors( Dictionary<string, IEnumerable<Type>> descriptorAssemblyLookups, IEnumerable<TagHelperDirectiveDescriptor> directiveDescriptors, IEnumerable<TagHelperDescriptor> expectedDescriptors) { // Arrange var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver(descriptorAssemblyLookups)); var resolutionContext = new TagHelperDescriptorResolutionContext( directiveDescriptors, new ErrorSink()); // Act var descriptors = tagHelperDescriptorResolver.Resolve(resolutionContext); // Assert Assert.Equal(expectedDescriptors.Count(), descriptors.Count()); foreach (var expectedDescriptor in expectedDescriptors) { Assert.Contains(expectedDescriptor, descriptors, TagHelperDescriptorComparer.Default); } }
public void DescriptorResolver_CreatesErrorIfInvalidLookupText_DoesNotThrow(string lookupText, int errorLength) { // Arrange var errorSink = new ErrorSink(); var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver( new TestTagHelperTypeResolver(InvalidTestableTagHelpers)); var documentLocation = new SourceLocation(1, 2, 3); var directiveType = TagHelperDirectiveType.AddTagHelper; var expectedErrorMessage = string.Format( "Invalid tag helper directive look up text '{0}'. The correct look up text " + "format is: \"typeName, assemblyName\".", lookupText); var resolutionContext = new TagHelperDescriptorResolutionContext( new[] { new TagHelperDirectiveDescriptor { DirectiveText = lookupText, Location = documentLocation, DirectiveType = directiveType } }, errorSink); // Act tagHelperDescriptorResolver.Resolve(resolutionContext); // Assert var error = Assert.Single(errorSink.Errors); Assert.Equal(errorLength, error.Length); Assert.Equal(documentLocation, error.Location); Assert.Equal(expectedErrorMessage, error.Message); }
public void DescriptorResolver_DoesNotResolveTypesForNoTypeResolvingLookupText() { // Arrange var resolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver( new Dictionary<string, IEnumerable<Type>>(StringComparer.OrdinalIgnoreCase) { { AssemblyName, ValidTestableTagHelpers }, { Valid_PlainTagHelperType.FullName + ", " + AssemblyName, new Type[]{ Valid_PlainTagHelperType } } })); // Act var descriptors = resolver.Resolve("*, lookupText").ToArray(); // Assert Assert.Empty(descriptors); }
public void DescriptorResolver_ResolvesMultipleTypes() { // Arrange var resolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver( new Dictionary<string, IEnumerable<Type>>(StringComparer.OrdinalIgnoreCase) { { AssemblyName, new Type[]{ Valid_PlainTagHelperType, Valid_InheritedTagHelperType } }, })); var expectedDescriptors = new TagHelperDescriptor[] { Valid_PlainTagHelperDescriptor, Valid_InheritedTagHelperDescriptor }; // Act var descriptors = resolver.Resolve("*, " + AssemblyName).ToArray(); // Assert Assert.Equal(descriptors.Length, 2); Assert.Equal(expectedDescriptors, descriptors, CaseSensitiveTagHelperDescriptorComparer.Default); }
public void DescriptorResolver_ResolvesOnlyTypeResolverProvidedTypes() { // Arrange var resolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver( new Dictionary<string, IEnumerable<Type>>(StringComparer.OrdinalIgnoreCase) { { AssemblyName, ValidTestableTagHelpers }, { Valid_PlainTagHelperType.FullName + ", " + AssemblyName, new Type[] { Valid_PlainTagHelperType } } })); // Act var descriptors = resolver.Resolve(Valid_PlainTagHelperType + ", " + AssemblyName); // Assert var descriptor = Assert.Single(descriptors); Assert.Equal(Valid_PlainTagHelperDescriptor, descriptor, CaseSensitiveTagHelperDescriptorComparer.Default); }
public void DescriptorResolver_IgnoresSpaces(string lookupText) { // Arrange var invoked = false; var tagHelperTypeResolver = new TestTagHelperTypeResolver(TestableTagHelpers) { OnGetExportedTypes = (assemblyName) => { Assert.Equal(AssemblyName, assemblyName.Name); invoked = true; } }; var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver(tagHelperTypeResolver); // Act var descriptors = tagHelperDescriptorResolver.Resolve(lookupText); // Assert Assert.True(invoked); var descriptor = Assert.Single(descriptors); Assert.Equal(AssemblyName, descriptor.AssemblyName); Assert.Equal(typeof(Valid_PlainTagHelper).FullName, descriptor.TypeName); }
public void DescriptorResolver_DoesNotReturnInvalidTagHelpersWhenSpecified() { // Arrange var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver( new TestTagHelperTypeResolver(TestableTagHelpers)); // Act var descriptors = tagHelperDescriptorResolver.Resolve( "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_AbstractTagHelper, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_GenericTagHelper`, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_NestedPublicTagHelper, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_NestedInternalTagHelper, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_PrivateTagHelper, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_ProtectedTagHelper, " + AssemblyName, "Microsoft.AspNet.Razor.Runtime.Test.TagHelpers.Invalid_InternalTagHelper, " + AssemblyName); // Assert Assert.Empty(descriptors); }
public void Resolve_CanReturnEmptyDescriptorsBasedOnDirectiveDescriptors( Dictionary<string, IEnumerable<Type>> descriptorAssemblyLookups, IEnumerable<TagHelperDirectiveDescriptor> directiveDescriptors) { // Arrange var tagHelperDescriptorResolver = new TestTagHelperDescriptorResolver( new LookupBasedTagHelperTypeResolver(descriptorAssemblyLookups)); var resolutionContext = new TagHelperDescriptorResolutionContext( directiveDescriptors, new ErrorSink()); // Act var descriptors = tagHelperDescriptorResolver.Resolve(resolutionContext); // Assert Assert.Empty(descriptors); }