// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #if !ASPNETCORE50 using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.TagHelpers; using Moq; using Xunit; namespace Microsoft.AspNet.Razor.Test.Parser { public class ParserVisitorExtensionsTest { [Fact] public void VisitThrowsOnNullVisitor() { ParserVisitor target = null; var results = new ParserResults(new BlockBuilder() { Type = BlockType.Comment }.Build(), Enumerable.Empty(), parserErrors: new List()); Assert.Throws("self", () => target.Visit(results)); } [Fact] public void VisitThrowsOnNullResults() { var target = new Mock().Object; Assert.Throws("result", () => target.Visit(null)); } [Fact] public void VisitSendsDocumentToVisitor() { // Arrange Mock targetMock = new Mock(); var root = new BlockBuilder() { Type = BlockType.Comment }.Build(); var results = new ParserResults(root, Enumerable.Empty(), parserErrors: new List()); // Act targetMock.Object.Visit(results); // Assert targetMock.Verify(v => v.VisitBlock(root)); } [Fact] public void VisitSendsErrorsToVisitor() { // Arrange Mock targetMock = new Mock(); var root = new BlockBuilder() { Type = BlockType.Comment }.Build(); List errors = new List() { new RazorError("Foo", 1, 0, 1), new RazorError("Bar", 2, 0, 2) }; var results = new ParserResults(root, Enumerable.Empty(), errors); // Act targetMock.Object.Visit(results); // Assert targetMock.Verify(v => v.VisitError(errors[0])); targetMock.Verify(v => v.VisitError(errors[1])); } [Fact] public void VisitCallsOnCompleteWhenAllNodesHaveBeenVisited() { // Arrange Mock targetMock = new Mock(); var root = new BlockBuilder() { Type = BlockType.Comment }.Build(); List errors = new List() { new RazorError("Foo", 1, 0, 1), new RazorError("Bar", 2, 0, 2) }; var results = new ParserResults(root, Enumerable.Empty(), errors); // Act targetMock.Object.Visit(results); // Assert targetMock.Verify(v => v.OnComplete()); } } } #endif