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 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 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 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 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 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); }
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 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 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); } }