// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; using Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite; using Xunit; namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite { public class InvalidUrlRewriteFormatExceptionHandlingTests { [Theory] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'Condition must have an associated match'. Line number '3': '10'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'Match must have Url Attribute'. Line number '4': '14'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'Conditions must have an input attribute'. Line number '6': '18'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'Url attribute cannot contain an empty string'. Line number '5': '14'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The redirectType parameter 'foo' was not recognized'. Line number '5': '14'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The type parameter 'foo' was not recognized'. Line number '5': '14'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The logicalGrouping parameter 'foo' was not recognized'. Line number '5': '14'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The patternSyntax parameter 'foo' was not recognized'. Line number '3': '10'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The matchType parameter 'foo' was not recognized'. Line number '6': '18'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The enabled parameter 'foo' was not recognized'. Line number '3': '10'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The stopProcessing parameter 'foo' was not recognized'. Line number '3': '10'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The ignoreCase parameter 'foo' was not recognized'. Line number '4': '14'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The ignoreCase parameter 'foo' was not recognized'. Line number '6': '18'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The negate parameter 'foo' was not recognized'. Line number '4': '14'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The negate parameter 'foo' was not recognized'. Line number '6': '18'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The trackAllCaptures parameter 'foo' was not recognized'. Line number '5': '14'.")] [InlineData( @" ", "Could not parse the UrlRewrite file. Message: 'The appendQueryString parameter 'foo' was not recognized'. Line number '5': '14'.")] public void ThrowInvalidUrlRewriteFormatExceptionWithCorrectMessage(string input, string expected) { // Arrange, Act, Assert var ex = Assert.Throws(() => new UrlRewriteFileParser().Parse(new StringReader(input))); Assert.Equal(expected, ex.Message); } } }