Use TaskCache class from Microsoft.Extensions.TaskCache.Sources (#361)

Instead of Task.FromResult(0)
This commit is contained in:
Pavel Krymets 2016-09-08 09:25:44 -07:00 committed by GitHub
parent 2fe646ca27
commit 032bcf43b2
6 changed files with 12 additions and 23 deletions

View File

@ -1,16 +0,0 @@
// 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.Threading.Tasks;
namespace Microsoft.AspNetCore.Routing.Internal
{
public static class TaskCache
{
#if NETSTANDARD1_3
public static readonly Task CompletedTask = Task.CompletedTask;
#else
public static readonly Task CompletedTask = Task.FromResult(0);
#endif
}
}

View File

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Routing.Internal;
using Microsoft.AspNetCore.Routing.Logging;
using Microsoft.AspNetCore.Routing.Template;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ObjectPool;

View File

@ -3,7 +3,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing.Internal;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Routing
{

View File

@ -36,6 +36,10 @@
"Microsoft.Extensions.PropertyHelper.Sources": {
"type": "build",
"version": "1.1.0-*"
},
"Microsoft.Extensions.TaskCache.Sources": {
"version": "1.1.0-*",
"type": "build"
}
},
"frameworks": {

View File

@ -6,7 +6,6 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder.Internal;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Internal;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Xunit;
@ -60,7 +59,7 @@ namespace Microsoft.AspNetCore.Builder
var router = new Mock<IRouter>(MockBehavior.Strict);
router
.Setup(r => r.RouteAsync(It.IsAny<RouteContext>()))
.Returns(TaskCache.CompletedTask)
.Returns(Task.FromResult(0))
.Verifiable();
app.UseRouter(router.Object);
@ -85,7 +84,7 @@ namespace Microsoft.AspNetCore.Builder
var router = new Mock<IRouter>(MockBehavior.Strict);
router
.Setup(r => r.RouteAsync(It.IsAny<RouteContext>()))
.Returns(TaskCache.CompletedTask)
.Returns(Task.FromResult(0))
.Verifiable();
app.UseRouter(b =>

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing.Internal;
using Microsoft.AspNetCore.Routing.Template;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Microsoft.Extensions.ObjectPool;
@ -1531,7 +1532,7 @@ namespace Microsoft.AspNetCore.Routing.Tree
nestedRouters = new List<IRouter>(c.RouteData.Routers);
c.Handler = null; // Not a match
})
.Returns(TaskCache.CompletedTask);
.Returns(Task.FromResult(0));
var builder = CreateBuilder();
MapInboundEntry(builder, "api/Store", handler: next.Object);
@ -1568,7 +1569,7 @@ namespace Microsoft.AspNetCore.Routing.Tree
nestedRouters = new List<IRouter>(c.RouteData.Routers);
c.Handler = null; // Not a match
})
.Returns(TaskCache.CompletedTask);
.Returns(Task.FromResult(0));
var builder = CreateBuilder();
MapInboundEntry(builder, "api/Store", handler: next.Object);
@ -1612,7 +1613,7 @@ namespace Microsoft.AspNetCore.Routing.Tree
nestedRouters = new List<IRouter>(c.RouteData.Routers);
throw new Exception();
})
.Returns(TaskCache.CompletedTask);
.Returns(Task.FromResult(0));
var builder = CreateBuilder();
MapInboundEntry(builder, "api/Store", handler: next.Object);