public void ParseModelKeyword_ErrorOnModelFollowedByInherits() { // Arrange var errors = new List <RazorError>(); var document = "@model Foo" + Environment.NewLine + "@inherits Bar"; var factory = SpanFactory.CreateCsHtml(); var expectedSpans = new Span[] { factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) .Accepts(AcceptedCharacters.None), factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo" + Environment.NewLine) .As(new ModelChunkGenerator("Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) .Accepts(AcceptedCharacters.None), factory.MetaCode("inherits ") .Accepts(AcceptedCharacters.None), factory.Code("Bar") .As(new SetBaseTypeChunkGenerator("Bar")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; var expectedErrors = new[] { new RazorError( "The 'inherits' keyword is not allowed when a 'model' keyword is used.", PlatformNormalizer.NormalizedSourceLocation(21, 1, 9), length: 8) }; // Act var spans = ParseDocument(document, errors); // Assert Assert.Equal(expectedSpans, spans); Assert.Equal(expectedErrors, errors); }
public void ParseModelKeyword_ErrorOnMultipleModelStatements() { // Arrange + Act var errors = new List <RazorError>(); var document = "@model Foo" + Environment.NewLine + "@model Bar"; var factory = SpanFactory.CreateCsHtml(); var expectedSpans = new Span[] { factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) .Accepts(AcceptedCharacters.None), factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo" + Environment.NewLine) .As(new ModelChunkGenerator("Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) .Accepts(AcceptedCharacters.None), factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Bar") .As(new ModelChunkGenerator("Bar")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; var expectedErrors = new[] { new RazorError( "Only one 'model' statement is allowed in a file.", PlatformNormalizer.NormalizedSourceLocation(13, 1, 1), 5) }; // Act var spans = ParseDocument(document, errors); // Assert Assert.Equal(expectedSpans, spans); Assert.Equal(expectedErrors, errors); }