Added tests for ExactMatch, IntegerMatch and StringMatch in the Rewrite
project.
This commit is contained in:
parent
2807e0b436
commit
d2913edf61
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNetCore.Rewrite;
|
||||
|
||||
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlMatches
|
||||
{
|
||||
|
|
@ -21,7 +22,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlMatches
|
|||
int compValue;
|
||||
if (!int.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out compValue))
|
||||
{
|
||||
throw new FormatException("Syntax error for integers in comparison.");
|
||||
throw new FormatException(Resources.Error_IntegerMatch_FormatExceptionMessage);
|
||||
}
|
||||
_value = compValue;
|
||||
_operation = operation;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: AssemblyMetadata("Serviceable", "True")]
|
||||
[assembly: NeutralResourcesLanguage("en-us")]
|
||||
[assembly: AssemblyCompany("Microsoft Corporation.")]
|
||||
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
|
||||
[assembly: AssemblyProduct("Microsoft ASP.NET Core")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Rewrite.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||
|
|
|
|||
|
|
@ -138,6 +138,22 @@ namespace Microsoft.AspNetCore.Rewrite
|
|||
return string.Format(CultureInfo.CurrentCulture, GetString("Error_ModRewriteGeneralParseError"), p0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Syntax error for integers in comparison.
|
||||
/// </summary>
|
||||
internal static string Error_IntegerMatch_FormatExceptionMessage
|
||||
{
|
||||
get { return GetString("Error_IntegerMatch_FormatExceptionMessage"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Syntax error for integers in comparison.
|
||||
/// </summary>
|
||||
internal static string FormatError_IntegerMatch_FormatExceptionMessage()
|
||||
{
|
||||
return GetString("Error_IntegerMatch_FormatExceptionMessage");
|
||||
}
|
||||
|
||||
private static string GetString(string name, params string[] formatterNames)
|
||||
{
|
||||
var value = _resourceManager.GetString(name);
|
||||
|
|
|
|||
|
|
@ -141,4 +141,7 @@
|
|||
<data name="Error_ModRewriteGeneralParseError" xml:space="preserve">
|
||||
<value>Could not parse the mod_rewrite file. Line number '{0}'.</value>
|
||||
</data>
|
||||
<data name="Error_IntegerMatch_FormatExceptionMessage" xml:space="preserve">
|
||||
<value>Syntax error for integers in comparison.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// 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 Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Rewrite.Internal;
|
||||
using Microsoft.AspNetCore.Rewrite.Internal.UrlActions;
|
||||
using Microsoft.AspNetCore.Rewrite.Internal.UrlMatches;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Rewrite.Tests.UrlMatches
|
||||
{
|
||||
public class ExactMatchTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineDataAttribute(true,"string",false,"string",true)]
|
||||
[InlineDataAttribute(true, "string", true, "string", false)]
|
||||
[InlineDataAttribute(false, "STRING", false, "string",false)]
|
||||
[InlineDataAttribute(false, "STRING", true, "string", true)]
|
||||
public void ExactMatch_Case_Sensitivity_Negate_Tests(bool ignoreCase, string inputString, bool negate, string pattern, bool expectedResult)
|
||||
{
|
||||
var context = new RewriteContext { HttpContext = new DefaultHttpContext() };
|
||||
var Match = new ExactMatch(ignoreCase, inputString, negate);
|
||||
var matchResults = Match.Evaluate(pattern, context);
|
||||
Assert.Equal(matchResults.Success, expectedResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// 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;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Rewrite;
|
||||
using Microsoft.AspNetCore.Rewrite.Internal;
|
||||
using Microsoft.AspNetCore.Rewrite.Internal.UrlActions;
|
||||
using Microsoft.AspNetCore.Rewrite.Internal.UrlMatches;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Rewrite.Tests.UrlMatches
|
||||
{
|
||||
public class IntegerMatchTests
|
||||
{
|
||||
[Fact]
|
||||
public void IntegerMatch_Constructor_Integer_Parse_Excetion()
|
||||
{
|
||||
var ex = Assert.Throws<FormatException>(() => new IntegerMatch("Not an int", IntegerOperationType.Equal));
|
||||
Assert.Equal(ex.Message, Resources.Error_IntegerMatch_FormatExceptionMessage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1,IntegerOperationType.Equal,"1",true)]
|
||||
[InlineData(1, IntegerOperationType.NotEqual, "2", true)]
|
||||
[InlineData(2, IntegerOperationType.Less, "1", true)]
|
||||
[InlineData(1, IntegerOperationType.LessEqual, "2", false)]
|
||||
[InlineData(1, IntegerOperationType.Greater, "2", true)]
|
||||
[InlineData(2, IntegerOperationType.GreaterEqual, "1", false)]
|
||||
[InlineData(1, IntegerOperationType.Equal, "Not an int", false)]
|
||||
[InlineData(1, IntegerOperationType.Equal, "", false)]
|
||||
[InlineData(1, IntegerOperationType.Equal, "2147483648", false)]
|
||||
public void IntegerMatch_Evaluation_Cases_Tests(int value,IntegerOperationType operation, string input,bool expectedResult)
|
||||
{
|
||||
var context = new RewriteContext { HttpContext = new DefaultHttpContext() };
|
||||
var integerMatch = new IntegerMatch(value, operation);
|
||||
var matchResult = integerMatch.Evaluate(input, context);
|
||||
Assert.Equal(matchResult.Success, expectedResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Rewrite.Internal.UrlMatches;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Rewrite.Tests.UrlMatches
|
||||
{
|
||||
public class StringMatchTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("hi", StringOperationType.Equal,true,"hi",true)]
|
||||
[InlineData("a", StringOperationType.Greater, true, "b", true)]
|
||||
[InlineData("a", StringOperationType.GreaterEqual, true, "b", true)]
|
||||
[InlineData("b", StringOperationType.Less,true, "a", true)]
|
||||
[InlineData("b", StringOperationType.LessEqual, true, "a", true)]
|
||||
[InlineData("", StringOperationType.Equal, true, "", true)]
|
||||
[InlineData(null, StringOperationType.Equal, true, null, true)]
|
||||
public void StringMatch_Evaluation_Check_Cases(string value, StringOperationType operation, bool ignoreCase, string input, bool expectedResult)
|
||||
{
|
||||
var context = new RewriteContext { HttpContext = new DefaultHttpContext() };
|
||||
var stringMatch = new StringMatch(value, operation, ignoreCase);
|
||||
var matchResult = stringMatch.Evaluate(input, context);
|
||||
Assert.Equal(matchResult.Success, expectedResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"version": "1.1.0-*",
|
||||
"buildOptions": {
|
||||
"warningsAsErrors": true
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
},
|
||||
"dependencies": {
|
||||
"dotnet-test-xunit": "2.2.0-*",
|
||||
|
|
@ -12,7 +13,12 @@
|
|||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"imports": "dnxcore50",
|
||||
"dependencies": {
|
||||
"Microsoft.CodeCoverage": {
|
||||
"type": "build",
|
||||
"version": "1.0.1"
|
||||
},
|
||||
"Microsoft.NETCore.App": {
|
||||
"version": "1.0.0-*",
|
||||
"type": "platform"
|
||||
|
|
|
|||
Loading…
Reference in New Issue