Remove TaskCache and TaskCacheOfT

This commit is contained in:
Pranav K 2017-06-07 16:56:02 -07:00
parent 8662422e18
commit a5f3a6425e
47 changed files with 100 additions and 168 deletions

View File

@ -4,8 +4,8 @@
using System;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Core;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Net.Http.Headers;

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc
public virtual Task ExecuteResultAsync(ActionContext context)
{
ExecuteResult(context);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
/// <summary>

View File

@ -3,7 +3,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.Filters
{
@ -26,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Filters
}
OnException(context);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
/// <inheritdoc />

View File

@ -3,7 +3,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.Formatters
{
@ -43,7 +42,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
response.StatusCode = StatusCodes.Status204NoContent;
}
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -5,8 +5,6 @@ using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Mvc.Formatters
{
@ -53,7 +51,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
var valueAsString = (string)context.Object;
if (string.IsNullOrEmpty(valueAsString))
{
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
var response = context.HttpContext.Response;

View File

@ -7,7 +7,6 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Core;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
@ -138,7 +137,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
{
var response = context.HttpContext.Response;
response.StatusCode = StatusCodes.Status406NotAcceptable;
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
context.ContentType = selectedMediaType;

View File

@ -239,7 +239,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
}
isCompleted = true;
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
var actionExecutedContext = _actionExecutedContext;
@ -251,7 +251,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
}
isCompleted = true;
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
default:
@ -459,7 +459,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
if (actionDescriptor.BoundProperties.Count == 0 &&
actionDescriptor.Parameters.Count == 0)
{
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
Debug.Assert(_cacheEntry.ControllerBinderDelegate != null);

View File

@ -4,7 +4,6 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Core;
using Microsoft.AspNetCore.Mvc.Infrastructure;
@ -79,7 +78,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
if (actionDescriptor == null)
{
_logger.NoActionsMatched(context.RouteData.Values);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
foreach (var kvp in actionDescriptor.RouteValues)
@ -111,7 +110,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
return invoker.InvokeAsync();
};
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -67,14 +67,14 @@ namespace Microsoft.AspNetCore.Mvc.Internal
if (candidates == null || candidates.Count == 0)
{
_logger.NoActionsMatched(context.RouteData.Values);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
var actionDescriptor = _actionSelector.SelectBestCandidate(context, candidates);
if (actionDescriptor == null)
{
_logger.NoActionsMatched(context.RouteData.Values);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
context.Handler = (c) =>
@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
return invoker.InvokeAsync();
};
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
public Task BindModelAsync(ModelBindingContext bindingContext)
{
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
Logger.NoFormatter(formatterContext);
context.HttpContext.Response.StatusCode = StatusCodes.Status406NotAcceptable;
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
Logger.FormatterSelected(selectedFormatter, formatterContext);

View File

@ -624,7 +624,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
if (scope == Scope.Exception)
{
isCompleted = true;
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
if (exceptionContext != null)
@ -662,7 +662,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// If we're inside an exception filter, let's allow those filters to 'unwind' before
// the result.
isCompleted = true;
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
Debug.Assert(scope == Scope.Invoker || scope == Scope.Resource);
@ -847,7 +847,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
}
isCompleted = true;
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
Rethrow(_resultExecutedContext);
@ -877,7 +877,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
if (scope == Scope.Resource)
{
isCompleted = true;
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
Debug.Assert(scope == Scope.Invoker);
@ -889,7 +889,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
case State.InvokeEnd:
{
isCompleted = true;
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
default:

View File

@ -1,20 +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.Mvc.Internal
{
public static class TaskCache
{
/// <summary>
/// A <see cref="Task"/> that's already completed successfully.
/// </summary>
/// <remarks>
/// We're caching this in a static readonly field to make it more inlinable and avoid the volatile lookup done
/// by <c>Task.CompletedTask</c>.
/// </remarks>
public static readonly Task CompletedTask = Task.CompletedTask;
}
}

View File

@ -1,18 +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.Mvc.Internal
{
public static class TaskCache<T>
{
private static readonly Task<T> _defaultCompletedTask = Task.FromResult(default(T));
/// <summary>
/// Gets a completed <see cref="Task"/> with the value of <c>default(T)</c>.
/// </summary>
public static Task<T> DefaultCompletedTask => _defaultCompletedTask;
}
}

View File

@ -3,7 +3,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{
@ -24,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
if (valueProviderResult == ValueProviderResult.None)
{
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueProviderResult);
@ -33,14 +32,14 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
var value = valueProviderResult.FirstValue;
if (string.IsNullOrEmpty(value))
{
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
try
{
var model = Convert.FromBase64String(value);
bindingContext.Result = ModelBindingResult.Success(model);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
catch (Exception exception)
{
@ -48,7 +47,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
bindingContext.ModelName,
exception,
bindingContext.ModelMetadata);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -5,7 +5,6 @@ using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{
@ -30,7 +29,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
bindingContext.ValidationState.Add(model, new ValidationStateEntry() { SuppressValidation = true });
bindingContext.Result = ModelBindingResult.Success(model);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -7,7 +7,6 @@ using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Core;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{
@ -45,7 +44,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
if (!CanCreateModel(bindingContext))
{
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
// Perf: separated to avoid allocating a state machine when we don't

View File

@ -4,7 +4,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
@ -63,7 +62,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
bindingContext.Result = ModelBindingResult.Success(model);
}
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
private static object GetCompatibleCollection(ModelBindingContext bindingContext, string[] values)

View File

@ -3,7 +3,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.Extensions.DependencyInjection;
@ -29,7 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
bindingContext.ValidationState.Add(model, new ValidationStateEntry() { SuppressValidation = true });
bindingContext.Result = ModelBindingResult.Success(model);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -5,7 +5,6 @@ using System;
using System.ComponentModel;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{
@ -38,7 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
if (valueProviderResult == ValueProviderResult.None)
{
// no entry
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueProviderResult);
@ -83,12 +82,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
bindingContext.ModelMetadata.ModelBindingMessageProvider.ValueMustNotBeNullAccessor(
valueProviderResult.ToString()));
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
else
{
bindingContext.Result = ModelBindingResult.Success(model);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
catch (Exception exception)
@ -107,7 +106,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
bindingContext.ModelMetadata);
// Were able to find a converter for the type but conversion failed.
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -4,8 +4,6 @@
using System;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
@ -29,7 +27,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
return AddValueProviderAsync(context);
}
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
private static async Task AddValueProviderAsync(ValueProviderFactoryContext context)

View File

@ -8,7 +8,6 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Core;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Mvc.ModelBinding
@ -33,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
return AddValueProviderAsync(context);
}
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
private static async Task AddValueProviderAsync(ValueProviderFactoryContext context)

View File

@ -4,7 +4,6 @@
using System;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
@ -29,7 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
context.ValueProviders.Add(valueProvider);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -3,7 +3,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
@ -26,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
context.ValueProviders.Add(valueProvider);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
}
// Let the action be executed.
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal
}
}
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -3,7 +3,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewEngines;
@ -22,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
throw new ArgumentNullException(nameof(context));
}
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -2,9 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
@ -41,10 +41,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
// Example: An action returns NoContentResult and since NoContentResult does not write anything to
// the body of the response, this delegate would get executed way late in the pipeline at which point
// the session feature would have been removed.
object obj;
if (saveTempDataContext.HttpContext.Items.TryGetValue(TempDataSavedKey, out obj))
if (saveTempDataContext.HttpContext.Items.TryGetValue(TempDataSavedKey, out var obj))
{
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
SaveTempData(
@ -53,7 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
filters: saveTempDataContext.Filters,
httpContext: saveTempDataContext.HttpContext);
return TaskCache.CompletedTask;
return Task.CompletedTask;
},
state: new SaveTempDataContext()
{

View File

@ -7,7 +7,6 @@ using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
@ -253,7 +252,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
if (IsBuffering)
{
Buffer.AppendHtml(value.ToString());
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
else
{
@ -281,7 +280,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
if (IsBuffering)
{
Buffer.AppendHtml(new string(buffer, index, count));
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
else
{
@ -295,7 +294,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
if (IsBuffering)
{
Buffer.AppendHtml(value);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
else
{
@ -337,7 +336,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
Buffer.AppendHtml(value.ToString());
Buffer.AppendHtml(NewLine);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
else
{
@ -352,7 +351,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
Buffer.AppendHtml(new string(value, start, offset));
Buffer.AppendHtml(NewLine);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
else
{
@ -367,7 +366,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
Buffer.AppendHtml(value);
Buffer.AppendHtml(NewLine);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
else
{
@ -381,7 +380,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
if (IsBuffering)
{
Buffer.AppendHtml(NewLine);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
else
{

View File

@ -3,7 +3,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ViewComponents
{
@ -58,7 +57,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
{
Execute(context);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -4,7 +4,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ViewComponents
{
@ -58,7 +57,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
{
Execute(context);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -3,7 +3,6 @@
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
@ -21,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.WebApiCompatShim
bindingContext.ValidationState.Add(model, new ValidationStateEntry() { SuppressValidation = true });
bindingContext.Result = ModelBindingResult.Success(model);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -6,7 +6,6 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -26,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc
var auth = new Mock<IAuthenticationService>();
auth
.Setup(c => c.ForbidAsync(httpContext.Object, "", null))
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
var result = new ForbidResult("", null);
@ -53,11 +52,11 @@ namespace Microsoft.AspNetCore.Mvc
var auth = new Mock<IAuthenticationService>();
auth
.Setup(c => c.ForbidAsync(httpContext.Object, "Scheme1", authProperties))
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
auth
.Setup(c => c.ForbidAsync(httpContext.Object, "Scheme2", authProperties))
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
var result = new ForbidResult(new[] { "Scheme1", "Scheme2" }, authProperties);
@ -91,7 +90,7 @@ namespace Microsoft.AspNetCore.Mvc
var auth = new Mock<IAuthenticationService>();
auth
.Setup(c => c.ForbidAsync(httpContext.Object, null, expected))
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
var result = new ForbidResult(expected);
@ -119,7 +118,7 @@ namespace Microsoft.AspNetCore.Mvc
var auth = new Mock<IAuthenticationService>();
auth
.Setup(c => c.ForbidAsync(httpContext.Object, null, expected))
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
var result = new ForbidResult(expected)

View File

@ -69,9 +69,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal
selected = actions[1];
}
routeContext.Handler = (c) => TaskCache.CompletedTask;
routeContext.Handler = (c) => Task.CompletedTask;
return TaskCache.CompletedTask;
return Task.CompletedTask;
});
return handler.Object;
@ -788,7 +788,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
handler
.Setup(h => h.RouteAsync(It.IsAny<RouteContext>()))
.Callback<RouteContext>(c => c.Handler = NullHandler)
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
return handler;
}

View File

@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var binder = new Mock<IModelBinder>();
binder
.Setup(b => b.BindModelAsync(It.IsAny<DefaultModelBindingContext>()))
.Returns(TaskCache.CompletedTask);
.Returns(Task.CompletedTask);
var factory = GetModelBinderFactory(binder.Object);
var parameterBinder = GetParameterBinder(factory);
@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var binder = new Mock<IModelBinder>();
binder
.Setup(b => b.BindModelAsync(It.IsAny<DefaultModelBindingContext>()))
.Returns(TaskCache.CompletedTask);
.Returns(Task.CompletedTask);
var factory = GetModelBinderFactory(binder.Object);
var parameterBinder = GetParameterBinder(factory);
@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
context.ModelMetadata = metadataProvider.GetMetadataForType(typeof(string));
context.Result = ModelBindingResult.Success(value);
})
.Returns(TaskCache.CompletedTask);
.Returns(Task.CompletedTask);
var factory = GetModelBinderFactory(binder.Object);
var parameterBinder = GetParameterBinder(factory);
@ -209,7 +209,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var binder = new Mock<IModelBinder>();
binder
.Setup(b => b.BindModelAsync(It.IsAny<DefaultModelBindingContext>()))
.Returns(TaskCache.CompletedTask);
.Returns(Task.CompletedTask);
var mockValidator = new Mock<IObjectModelValidator>(MockBehavior.Strict);
mockValidator
@ -308,7 +308,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var binder = new Mock<IModelBinder>();
binder
.Setup(b => b.BindModelAsync(It.IsAny<DefaultModelBindingContext>()))
.Returns(TaskCache.CompletedTask);
.Returns(Task.CompletedTask);
var mockValidator = new Mock<IObjectModelValidator>(MockBehavior.Strict);
mockValidator
@ -821,7 +821,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
.Returns<DefaultModelBindingContext>(mbc =>
{
mbc.Result = ModelBindingResult.Success(model);
return TaskCache.CompletedTask;
return Task.CompletedTask;
});
return GetModelBinderFactory(binder.Object);

View File

@ -475,7 +475,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
arguments.Add(entry.Key, entry.Value);
}
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}

View File

@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
public Task BindModelAsync(ModelBindingContext bindingContext)
{
bindingContext.Result = ModelBindingResult.Success(_model);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -1374,7 +1374,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
bindingContext.Result = result;
}
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
protected override Task BindProperty(ModelBindingContext bindingContext)

View File

@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
Assert.Equal(expectedModelName, context.ModelName, StringComparer.Ordinal);
})
.Returns(TaskCache.CompletedTask);
.Returns(Task.CompletedTask);
var parameterDescriptor = new ParameterDescriptor
{
@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
Assert.Equal(expectedModelName, context.ModelName, StringComparer.Ordinal);
})
.Returns(TaskCache.CompletedTask);
.Returns(Task.CompletedTask);
var parameterDescriptor = new ParameterDescriptor
{

View File

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public StubModelBinder()
{
_callback = context => TaskCache.CompletedTask;
_callback = context => Task.CompletedTask;
}
public StubModelBinder(ModelBindingResult result)
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
_callback = context =>
{
context.Result = result;
return TaskCache.CompletedTask;
return Task.CompletedTask;
};
}
@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
_callback = context =>
{
callback(context);
return TaskCache.CompletedTask;
return Task.CompletedTask;
};
}
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
var result = callback.Invoke(context);
context.Result = result;
return TaskCache.CompletedTask;
return Task.CompletedTask;
};
}

View File

@ -7,7 +7,6 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -28,7 +27,7 @@ namespace Microsoft.AspNetCore.Mvc
var auth = new Mock<IAuthenticationService>();
auth
.Setup(c => c.SignInAsync(httpContext.Object, "", principal, null))
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
var result = new SignInResult("", principal, null);
@ -56,7 +55,7 @@ namespace Microsoft.AspNetCore.Mvc
var auth = new Mock<IAuthenticationService>();
auth
.Setup(c => c.SignInAsync(httpContext.Object, "Scheme1", principal, authProperties))
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
var result = new SignInResult("Scheme1", principal, authProperties);

View File

@ -6,7 +6,6 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -26,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc
var auth = new Mock<IAuthenticationService>();
auth
.Setup(c => c.SignOutAsync(httpContext.Object, "", null))
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
var result = new SignOutResult("", null);
@ -53,11 +52,11 @@ namespace Microsoft.AspNetCore.Mvc
var auth = new Mock<IAuthenticationService>();
auth
.Setup(c => c.SignOutAsync(httpContext.Object, "Scheme1", authProperties))
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
auth
.Setup(c => c.SignOutAsync(httpContext.Object, "Scheme2", authProperties))
.Returns(TaskCache.CompletedTask)
.Returns(Task.CompletedTask)
.Verifiable();
httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
var result = new SignOutResult(new[] { "Scheme1", "Scheme2" }, authProperties);

View File

@ -5,7 +5,6 @@ using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Testing;
using Xunit;
@ -327,7 +326,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
if (bindingContext.ModelType != typeof(Address))
{
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
var address = new Address() { Street = "SomeStreet" };
@ -338,7 +337,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
address.Street);
bindingContext.Result = ModelBindingResult.Success(address);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
@ -355,7 +354,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
if (bindingContext.ModelType != typeof(Address3))
{
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
var address = new Address3 { Street = "SomeStreet" };
@ -366,7 +365,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
address.Street);
bindingContext.Result = ModelBindingResult.Success(address);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
@ -387,7 +386,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
model);
bindingContext.Result =ModelBindingResult.Success(model);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
@ -402,7 +401,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
Debug.Assert(bindingContext.Result == ModelBindingResult.Failed());
bindingContext.Result = ModelBindingResult.Success(model: null);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
@ -417,7 +416,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
Debug.Assert(bindingContext.Result == ModelBindingResult.Failed());
bindingContext.Result = ModelBindingResult.Failed();
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -7,7 +7,6 @@ using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Xunit;
@ -183,11 +182,11 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
{
// Binding Sources are opt-in. This model either didn't specify one or specified something
// incompatible so let other binders run.
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
bindingContext.Result = ModelBindingResult.Success(new Address());
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
{
context.ValueProviders.Add(_valueProvider);
return TaskCache.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -1,6 +1,5 @@
@page "{handler?}"
@using Microsoft.AspNetCore.Mvc.Internal
@using RazorPagesWebSite
@functions{
@ -13,26 +12,26 @@
public async Task<IActionResult> OnPostAsync()
{
await TaskCache.CompletedTask;
await Task.CompletedTask;
MethodName = nameof(OnPostAsync);
return Page();
}
public async Task OnGetCustomer()
{
await TaskCache.CompletedTask;
await Task.CompletedTask;
MethodName = nameof(OnGetCustomer);
}
public async Task OnGetViewCustomerAsync()
{
await TaskCache.CompletedTask;
await Task.CompletedTask;
MethodName = nameof(OnGetViewCustomerAsync);
}
public async Task<CustomActionResult> OnPostCustomActionResult()
{
await TaskCache.CompletedTask;
await Task.CompletedTask;
return new CustomActionResult();
}

View File

@ -3,7 +3,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace RazorPagesWebSite
@ -19,26 +18,26 @@ namespace RazorPagesWebSite
public async Task<IActionResult> OnPostAsync()
{
await TaskCache.CompletedTask;
await Task.CompletedTask;
MethodName = nameof(OnPostAsync);
return Page();
}
public async Task OnGetCustomer()
{
await TaskCache.CompletedTask;
await Task.CompletedTask;
MethodName = nameof(OnGetCustomer);
}
public async Task OnGetViewCustomerAsync()
{
await TaskCache.CompletedTask;
await Task.CompletedTask;
MethodName = nameof(OnGetViewCustomerAsync);
}
public async Task<CustomActionResult> OnPostCustomActionResult()
{
await TaskCache.CompletedTask;
await Task.CompletedTask;
return new CustomActionResult();
}