public void Compile_ReturnsFailedResultIfParseFails() { // Arrange var errorSink = new ErrorSink(); errorSink.OnError(new RazorError("some message", 1, 1, 1, 1)); var generatorResult = new GeneratorResults( new Block(new BlockBuilder { Type = BlockType.Comment }), Enumerable.Empty<TagHelperDescriptor>(), errorSink, new CodeGeneratorResult("", new LineMapping[0]), new ChunkTree()); var host = new Mock<IMvcRazorHost>(); host.Setup(h => h.GenerateCode(It.IsAny<string>(), It.IsAny<Stream>())) .Returns(generatorResult) .Verifiable(); var fileInfo = new Mock<IFileInfo>(); fileInfo.Setup(f => f.CreateReadStream()) .Returns(Stream.Null); var compiler = new Mock<ICompilationService>(MockBehavior.Strict); var relativeFileInfo = new RelativeFileInfo(fileInfo.Object, @"Views\index\home.cshtml"); var razorService = new RazorCompilationService(compiler.Object, host.Object, GetOptions()); // Act var result = razorService.Compile(relativeFileInfo); // Assert Assert.NotNull(result.CompilationFailures); Assert.Collection(result.CompilationFailures, failure => { var message = Assert.Single(failure.Messages); Assert.Equal("some message", message.Message); }); host.Verify(); }
/// <inheritdoc /> protected override IEnumerable<TagHelperDescriptor> GetTagHelperDescriptors( Block documentRoot, ErrorSink errorSink) { if (documentRoot == null) { throw new ArgumentNullException(nameof(documentRoot)); } if (errorSink == null) { throw new ArgumentNullException(nameof(errorSink)); } var visitor = new ViewImportsTagHelperDirectiveSpanVisitor( TagHelperDescriptorResolver, _viewImportsDirectiveDescriptors, errorSink); var descriptors = visitor.GetDescriptors(documentRoot); foreach (var descriptor in descriptors) { foreach (var attributeDescriptor in descriptor.Attributes) { if (attributeDescriptor.IsIndexer && string.Equals( attributeDescriptor.TypeName, _modelExpressionTypeName, StringComparison.Ordinal)) { errorSink.OnError( SourceLocation.Undefined, Resources.FormatMvcRazorParser_InvalidPropertyType( descriptor.TypeName, attributeDescriptor.Name, _modelExpressionTypeName), length: 0); } } } return descriptors; }