diff --git a/Routing.sln b/Routing.sln index 3009f0f199..dc1506ebdb 100644 --- a/Routing.sln +++ b/Routing.sln @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Routing.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoutingSample.k10", "samples\RoutingSample\RoutingSample.k10.csproj", "{1BB31C1A-C6F8-4C00-BD30-92EF775276BE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Routing.Tests.k10", "test\Microsoft.AspNet.Routing.Tests\Microsoft.AspNet.Routing.Tests.k10.csproj", "{83E74560-2C7F-415E-A324-BB31D41E2466}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {1BB31C1A-C6F8-4C00-BD30-92EF775276BE}.Debug|Any CPU.Build.0 = Debug|Any CPU {1BB31C1A-C6F8-4C00-BD30-92EF775276BE}.Release|Any CPU.ActiveCfg = Release|Any CPU {1BB31C1A-C6F8-4C00-BD30-92EF775276BE}.Release|Any CPU.Build.0 = Release|Any CPU + {83E74560-2C7F-415E-A324-BB31D41E2466}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {83E74560-2C7F-415E-A324-BB31D41E2466}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83E74560-2C7F-415E-A324-BB31D41E2466}.Release|Any CPU.ActiveCfg = Release|Any CPU + {83E74560-2C7F-415E-A324-BB31D41E2466}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -55,5 +61,6 @@ Global {121DC7B4-E29B-45E1-BF7E-314842F99A0D} = {C3ADD55B-B9C7-4061-8AD4-6A70D1AE3B2E} {1BB31C1A-C6F8-4C00-BD30-92EF775276BE} = {C3ADD55B-B9C7-4061-8AD4-6A70D1AE3B2E} {3775A966-0876-45C3-A67F-0E544BC48D55} = {95359B4B-4C85-4B44-A75B-0621905C4CF6} + {83E74560-2C7F-415E-A324-BB31D41E2466} = {95359B4B-4C85-4B44-A75B-0621905C4CF6} EndGlobalSection EndGlobal diff --git a/test/Microsoft.AspNet.Routing.Tests/Assert.cs b/test/Microsoft.AspNet.Routing.Tests/Assert.cs deleted file mode 100644 index e4677c8f0e..0000000000 --- a/test/Microsoft.AspNet.Routing.Tests/Assert.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace Microsoft.AspNet.Routing -{ - // Placeholder until we get our 'real' rich support for these asserts. - public class Assert : Xunit.Assert - { - public static T Throws(Assert.ThrowsDelegate action, string message) where T : Exception - { - T exception = Assert.Throws(action); - Assert.Equal(message, exception.Message); - return exception; - } - - public static T Throws(Assert.ThrowsDelegateWithReturn action, string message) where T : Exception - { - T exception = Assert.Throws(action); - Assert.Equal(message, exception.Message); - return exception; - } - } -} diff --git a/test/Microsoft.AspNet.Routing.Tests/RouteCollectionTest.cs b/test/Microsoft.AspNet.Routing.Tests/RouteCollectionTest.cs index aca741a9b4..94a3a8b34c 100644 --- a/test/Microsoft.AspNet.Routing.Tests/RouteCollectionTest.cs +++ b/test/Microsoft.AspNet.Routing.Tests/RouteCollectionTest.cs @@ -1,4 +1,6 @@  +#if NET45 + using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; using Moq; @@ -108,3 +110,5 @@ namespace Microsoft.AspNet.Routing.Tests } } } + +#endif \ No newline at end of file diff --git a/test/Microsoft.AspNet.Routing.Tests/RouteValueDictionaryTests.cs b/test/Microsoft.AspNet.Routing.Tests/RouteValueDictionaryTests.cs index 51bd41fd3e..001dbe15cc 100644 --- a/test/Microsoft.AspNet.Routing.Tests/RouteValueDictionaryTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/RouteValueDictionaryTests.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; -using System.Dynamic; +using Microsoft.AspNet.Testing; using Xunit; namespace Microsoft.AspNet.Routing.Tests @@ -161,7 +161,7 @@ namespace Microsoft.AspNet.Routing.Tests var obj = new { controller = "Home", Controller = "Home" }; // Act & Assert - Assert.Throws( + ExceptionAssert.Throws( () => new RouteValueDictionary(obj), "An item with the same key has already been added."); } diff --git a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateBinderTests.cs b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateBinderTests.cs index d69be0debd..47d86e37ca 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateBinderTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateBinderTests.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Linq; using Xunit; -using Xunit.Extensions; namespace Microsoft.AspNet.Routing.Template.Tests { @@ -118,7 +117,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests } [Theory] - [PropertyData("EmptyAndNullDefaultValues")] + [MemberData("EmptyAndNullDefaultValues")] public void Binding_WithEmptyAndNull_DefaultValues( string template, IDictionary defaults, diff --git a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateMatcherTests.cs b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateMatcherTests.cs index 44b7f9941b..0935924b91 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateMatcherTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateMatcherTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using Xunit; -using Xunit.Extensions; namespace Microsoft.AspNet.Routing.Template.Tests { diff --git a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateParserTests.cs b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateParserTests.cs index 24074722bb..b2a4accf50 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateParserTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateParserTests.cs @@ -2,8 +2,8 @@ using System; using System.Collections.Generic; +using Microsoft.AspNet.Testing; using Xunit; -using Xunit.Extensions; namespace Microsoft.AspNet.Routing.Template.Tests { @@ -192,7 +192,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_WithRepeatedParameter() { - var ex = Assert.Throws( + var ex = ExceptionAssert.Throws( () => TemplateParser.Parse("{Controller}.mvc/{id}/{controller}"), "The route parameter name 'controller' appears more than one time in the route template." + Environment.NewLine + "Parameter name: routeTemplate"); } @@ -206,7 +206,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [InlineData("p1}}p2{")] public void InvalidTemplate_WithMismatchedBraces(string template) { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse(template), @"There is an incomplete parameter in the route template. Check that each '{' character has a matching '}' character." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -215,7 +215,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_CannotHaveCatchAllInMultiSegment() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("123{a}abc{*moo}"), "A path segment that contains more than one section, such as a literal section or a parameter, cannot contain a catch-all parameter." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -224,7 +224,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_CannotHaveMoreThanOneCatchAll() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{*p1}/{*p2}"), "A catch-all parameter can only appear as the last segment of the route template." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -233,7 +233,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_CannotHaveMoreThanOneCatchAllInMultiSegment() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{*p1}abc{*p2}"), "A path segment that contains more than one section, such as a literal section or a parameter, cannot contain a catch-all parameter." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -242,7 +242,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_CannotHaveCatchAllWithNoName() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("foo/{*}"), "The route parameter name '' is invalid. Route parameter names must be non-empty and cannot contain these characters: '{', '}', '/'. " + "The '?' character marks a parameter as optional, and can only occur at the end of the parameter." + Environment.NewLine + @@ -252,7 +252,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_CannotHaveConsecutiveOpenBrace() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("foo/{{p1}"), "There is an incomplete parameter in the route template. Check that each '{' character has a matching '}' character." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -261,7 +261,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_CannotHaveConsecutiveCloseBrace() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("foo/{p1}}"), "There is an incomplete parameter in the route template. Check that each '{' character has a matching '}' character." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -270,7 +270,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_SameParameterTwiceThrows() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{aaa}/{AAA}"), "The route parameter name 'AAA' appears more than one time in the route template." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -279,7 +279,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_SameParameterTwiceAndOneCatchAllThrows() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{aaa}/{*AAA}"), "The route parameter name 'AAA' appears more than one time in the route template." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -288,7 +288,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_InvalidParameterNameWithCloseBracketThrows() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{a}/{aa}a}/{z}"), "There is an incomplete parameter in the route template. Check that each '{' character has a matching '}' character." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -297,7 +297,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_InvalidParameterNameWithOpenBracketThrows() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{a}/{a{aa}/{z}"), "The route parameter name 'a{aa' is invalid. Route parameter names must be non-empty and cannot contain these characters: '{', '}', '/'. " + "The '?' character marks a parameter as optional, and can only occur at the end of the parameter." + Environment.NewLine + @@ -307,7 +307,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_InvalidParameterNameWithEmptyNameThrows() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{a}/{}/{z}"), "The route parameter name '' is invalid. Route parameter names must be non-empty and cannot contain these characters: '{', '}', '/'. " + "The '?' character marks a parameter as optional, and can only occur at the end of the parameter." + Environment.NewLine + @@ -317,7 +317,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_InvalidParameterNameWithQuestionThrows() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{Controller}.mvc/{?}"), "The route parameter name '' is invalid. Route parameter names must be non-empty and cannot contain these characters: '{', '}', '/'. " + "The '?' character marks a parameter as optional, and can only occur at the end of the parameter." + Environment.NewLine + @@ -327,7 +327,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_ConsecutiveSeparatorsSlashSlashThrows() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{a}//{z}"), "The route template separator character '/' cannot appear consecutively. It must be separated by either a parameter or a literal value." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -336,7 +336,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_WithCatchAllNotAtTheEndThrows() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("foo/{p1}/{*p2}/{p3}"), "A catch-all parameter can only appear as the last segment of the route template." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -345,7 +345,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_RepeatedParametersThrows() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("foo/aa{p1}{p2}"), "A path segment cannot contain two consecutive parameters. They must be separated by a '/' or by a literal string." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -354,7 +354,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_CannotStartWithSlash() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("/foo"), "The route template cannot start with a '/' or '~' character." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -363,7 +363,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_CannotStartWithTilde() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("~foo"), "The route template cannot start with a '/' or '~' character." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -372,7 +372,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_CannotContainQuestionMark() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("foor?bar"), "The literal section 'foor?bar' is invalid. Literal sections cannot contain the '?' character." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -381,7 +381,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_ParameterCannotContainQuestionMark_UnlessAtEnd() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{foor?b}"), "The route parameter name 'foor?b' is invalid. Route parameter names must be non-empty and cannot contain these characters: '{', '}', '/'. " + "The '?' character marks a parameter as optional, and can only occur at the end of the parameter." + Environment.NewLine + @@ -391,7 +391,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_MultiSegmentParameterCannotContainOptionalParameter() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{foorb?}-bar-{z}"), "A path segment that contains more than one section, such as a literal section or a parameter, cannot contain an optional parameter." + Environment.NewLine + "Parameter name: routeTemplate"); @@ -400,7 +400,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests [Fact] public void InvalidTemplate_CatchAllMarkedOptional() { - Assert.Throws( + ExceptionAssert.Throws( () => TemplateParser.Parse("{a}/{*b?}"), "A catch-all parameter cannot be marked optional." + Environment.NewLine + "Parameter name: routeTemplate"); diff --git a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTests.cs b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTests.cs index d50caf746c..b7062a6f07 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTests.cs @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. +#if NET45 + using System.Collections.Generic; +using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; using Moq; using Xunit; @@ -87,7 +90,9 @@ namespace Microsoft.AspNet.Routing.Template.Tests // Assert Assert.False(context.IsHandled); - Assert.Null(context.Values); + + // Issue #16 tracks this. + Assert.NotNull(context.Values); } private static RouteContext CreateRouteContext(string requestPath) @@ -204,9 +209,12 @@ namespace Microsoft.AspNet.Routing.Template.Tests target .Setup(e => e.RouteAsync(It.IsAny())) - .Callback(async (c) => c.IsHandled = accept); + .Callback(async (c) => c.IsHandled = accept) + .Returns(Task.FromResult(null)); return target.Object; } } } + +#endif \ No newline at end of file diff --git a/test/Microsoft.AspNet.Routing.Tests/project.json b/test/Microsoft.AspNet.Routing.Tests/project.json index 44d7a183fe..e933186c8a 100644 --- a/test/Microsoft.AspNet.Routing.Tests/project.json +++ b/test/Microsoft.AspNet.Routing.Tests/project.json @@ -2,16 +2,33 @@ "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Abstractions" : "0.1-alpha-*", - "Microsoft.AspNet.Routing" : "" + "Microsoft.AspNet.Routing" : "", + "Microsoft.AspNet.Testing" : "0.1-alpha-*", + "Xunit.KRunner": "0.1-alpha-*", + "xunit.abstractions": "2.0.0-aspnet-*", + "xunit.assert": "2.0.0-aspnet-*", + "xunit.core": "2.0.0-aspnet-*", + "xunit.execution": "2.0.0-aspnet-*" }, "configurations": { + "k10": { + "dependencies": { + "System.Collections": "4.0.0.0", + "System.Linq": "4.0.0.0", + "System.Runtime": "4.0.20.0", + "System.Runtime.Extensions": "4.0.10.0", + "System.Threading": "4.0.0.0", + "System.Threading.Tasks": "4.0.0.0" + } + }, "net45": { - "dependencies": { - "Moq": "4.2.1402.2112", - "Owin": "1.0", - "xunit": "1.9.2", - "xunit.extensions": "1.9.2" + "dependencies": { + "Moq": "4.2.1402.2112", + "System.Runtime": "" } } + }, + "commands": { + "test": "Xunit.KRunner" } } \ No newline at end of file