Пример #1
0
        public void ParseAddOrRemoveDirective_CreatesErrorIfInvalidLookupText_DoesNotThrow(string directiveText, int errorLength)
        {
            // Arrange
            var source  = TestRazorSourceDocument.Create();
            var options = RazorParserOptions.CreateDefault();
            var context = new ParserContext(source, options);

            var parser = new CSharpCodeParser(context);

            var directive = new CSharpCodeParser.ParsedDirective()
            {
                DirectiveText = directiveText
            };

            var diagnostics   = new List <RazorDiagnostic>();
            var expectedError = RazorDiagnosticFactory.CreateParsing_InvalidTagHelperLookupText(
                new SourceSpan(new SourceLocation(1, 2, 3), errorLength), directiveText);

            // Act
            var result = parser.ParseAddOrRemoveDirective(directive, new SourceLocation(1, 2, 3), diagnostics);

            // Assert
            Assert.Same(directive, result);

            var error = Assert.Single(diagnostics);

            Assert.Equal(expectedError, error);
        }
Пример #2
0
        public void ParseAddOrRemoveDirective_CalculatesAssemblyLocationInLookupText(string text, int assemblyLocation)
        {
            // Arrange
            var source  = TestRazorSourceDocument.Create();
            var options = RazorParserOptions.CreateDefault();
            var context = new ParserContext(source, options);

            var parser = new CSharpCodeParser(context);

            var directive = new CSharpCodeParser.ParsedDirective()
            {
                DirectiveText = text,
            };

            var diagnostics = new List <RazorDiagnostic>();
            var expected    = new SourceLocation(assemblyLocation, 0, assemblyLocation);

            // Act
            var result = parser.ParseAddOrRemoveDirective(directive, SourceLocation.Zero, diagnostics);

            // Assert
            Assert.Empty(diagnostics);
            Assert.Equal("foo", result.TypePattern);
            Assert.Equal("assemblyName", result.AssemblyName);
        }