Fix async/await warnings

This commit is contained in:
Philip Wood 2018-03-06 10:59:01 +00:00
parent db05935b89
commit b8e95373a4
21 changed files with 60 additions and 85 deletions

View File

@ -18,7 +18,7 @@ namespace Ocelot.Configuration.Repository
_configFilePath = $"{AppContext.BaseDirectory}/configuration{(string.IsNullOrEmpty(hostingEnvironment.EnvironmentName) ? string.Empty : ".")}{hostingEnvironment.EnvironmentName}.json";
}
public async Task<Response<FileConfiguration>> Get()
public Task<Response<FileConfiguration>> Get()
{
string jsonConfiguration;
@ -29,10 +29,10 @@ namespace Ocelot.Configuration.Repository
var fileConfiguration = JsonConvert.DeserializeObject<FileConfiguration>(jsonConfiguration);
return new OkResponse<FileConfiguration>(fileConfiguration);
return Task.FromResult<Response<FileConfiguration>>(new OkResponse<FileConfiguration>(fileConfiguration));
}
public async Task<Response> Set(FileConfiguration fileConfiguration)
public Task<Response> Set(FileConfiguration fileConfiguration)
{
string jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration);
@ -45,8 +45,8 @@ namespace Ocelot.Configuration.Repository
System.IO.File.WriteAllText(_configFilePath, jsonConfiguration);
}
return new OkResponse();
return Task.FromResult<Response>(new OkResponse());
}
}
}
}

View File

@ -12,19 +12,19 @@ namespace Ocelot.Configuration.Repository
private IOcelotConfiguration _ocelotConfiguration;
public async Task<Response<IOcelotConfiguration>> Get()
public Task<Response<IOcelotConfiguration>> Get()
{
return new OkResponse<IOcelotConfiguration>(_ocelotConfiguration);
return Task.FromResult<Response<IOcelotConfiguration>>(new OkResponse<IOcelotConfiguration>(_ocelotConfiguration));
}
public async Task<Response> AddOrReplace(IOcelotConfiguration ocelotConfiguration)
public Task<Response> AddOrReplace(IOcelotConfiguration ocelotConfiguration)
{
lock (LockObject)
{
_ocelotConfiguration = ocelotConfiguration;
}
return new OkResponse();
return Task.FromResult<Response>(new OkResponse());
}
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Ocelot.Values;
@ -14,16 +13,16 @@ namespace Ocelot.ServiceDiscovery
_configuration = configuration;
}
public async Task<List<Service>> Get()
public Task<List<Service>> Get()
{
return new List<Service>
return Task.FromResult(new List<Service>
{
new Service(_configuration.ServiceName,
new ServiceHostAndPort(_configuration.HostName, _configuration.Port),
"doesnt matter with service fabric",
"doesnt matter with service fabric",
new List<string>())
};
});
}
}
}

View File

@ -221,13 +221,15 @@ namespace Ocelot.AcceptanceTests
.Configure(app =>
{
app.UsePathBase(basePath);
app.Run(async context =>
app.Run(context =>
{
context.Response.OnStarting(() => {
context.Response.Headers.Add(headerKey, headerValue);
context.Response.StatusCode = statusCode;
return Task.CompletedTask;
});
return Task.CompletedTask;
});
})
.Build();

View File

@ -6,6 +6,7 @@ namespace Ocelot.UnitTests.Authentication
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Moq;
using Ocelot.Authentication.Middleware;
@ -44,10 +45,11 @@ namespace Ocelot.UnitTests.Authentication
private void WhenICallTheMiddleware()
{
_next = async (context) => {
_next = (context) => {
byte[] byteArray = Encoding.ASCII.GetBytes("The user is authenticated");
MemoryStream stream = new MemoryStream(byteArray);
var stream = new MemoryStream(byteArray);
context.HttpContext.Response.Body = stream;
return Task.CompletedTask;
};
_middleware = new AuthenticationMiddleware(_next, _factory.Object);
_middleware.Invoke(_downstreamContext).GetAwaiter().GetResult();
@ -55,10 +57,11 @@ namespace Ocelot.UnitTests.Authentication
private void GivenTheTestServerPipelineIsConfigured()
{
_next = async (context) => {
_next = (context) => {
byte[] byteArray = Encoding.ASCII.GetBytes("The user is authenticated");
MemoryStream stream = new MemoryStream(byteArray);
var stream = new MemoryStream(byteArray);
context.HttpContext.Response.Body = stream;
return Task.CompletedTask;
};
}

View File

@ -4,18 +4,17 @@ namespace Ocelot.UnitTests.Authorization
{
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Moq;
using Ocelot.Authorisation;
using Ocelot.Authorisation.Middleware;
using Ocelot.Configuration.Builder;
using Ocelot.DownstreamRouteFinder;
using Ocelot.DownstreamRouteFinder.UrlMatcher;
using Ocelot.Logging;
using Ocelot.Responses;
using TestStack.BDDfy;
using Xunit;
using Microsoft.AspNetCore.Http;
using Ocelot.DownstreamRouteFinder.Middleware;
using Ocelot.Configuration;
public class AuthorisationMiddlewareTests
@ -36,9 +35,7 @@ namespace Ocelot.UnitTests.Authorization
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<AuthorisationMiddleware>()).Returns(_logger.Object);
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
_middleware = new AuthorisationMiddleware(_next, _authService.Object, _authScopesService.Object, _loggerFactory.Object);
}

View File

@ -10,6 +10,7 @@ namespace Ocelot.UnitTests.Cache
using Shouldly;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Moq;
using Ocelot.Cache;
using Ocelot.Cache.Middleware;
@ -43,9 +44,7 @@ namespace Ocelot.UnitTests.Cache
_cacheManager = new OcelotCacheManagerCache<CachedResponse>(cacheManagerOutputCache);
_downstreamContext = new DownstreamContext(new DefaultHttpContext());
_downstreamContext.DownstreamRequest = new HttpRequestMessage(HttpMethod.Get, "https://some.url/blah?abcd=123");
_next = async context => {
//do nothing..
};
_next = context => Task.CompletedTask;
_middleware = new OutputCacheMiddleware(_next, _loggerFactory.Object, _cacheManager, _regionCreator);
}

View File

@ -7,19 +7,16 @@ namespace Ocelot.UnitTests.Cache
using System;
using System.Collections.Generic;
using System.Net.Http;
using Microsoft.AspNetCore.Builder;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Cache;
using Ocelot.Cache.Middleware;
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
using Ocelot.DownstreamRouteFinder;
using Ocelot.DownstreamRouteFinder.Middleware;
using Ocelot.DownstreamRouteFinder.UrlMatcher;
using Ocelot.Logging;
using Ocelot.Responses;
using TestStack.BDDfy;
using Xunit;
@ -42,10 +39,7 @@ namespace Ocelot.UnitTests.Cache
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<OutputCacheMiddleware>()).Returns(_logger.Object);
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
_downstreamContext.DownstreamRequest = new HttpRequestMessage(HttpMethod.Get, "https://some.url/blah?abcd=123");
}

View File

@ -3,6 +3,7 @@
namespace Ocelot.UnitTests.Claims
{
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Moq;
using Ocelot.Claims;
@ -32,9 +33,7 @@ namespace Ocelot.UnitTests.Claims
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<ClaimsBuilderMiddleware>()).Returns(_logger.Object);
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
_middleware = new ClaimsBuilderMiddleware(_next, _loggerFactory.Object, _addHeaders.Object);
}

View File

@ -4,9 +4,8 @@ using Ocelot.Middleware.Multiplexer;
namespace Ocelot.UnitTests.DownstreamRouteFinder
{
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
@ -42,9 +41,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<DownstreamRouteFinderMiddleware>()).Returns(_logger.Object);
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
_multiplexer = new Mock<IMultiplexer>();
_middleware = new DownstreamRouteFinderMiddleware(_next, _loggerFactory.Object, _finder.Object, _provider.Object, _multiplexer.Object);
}

View File

@ -6,23 +6,19 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator
using System;
using System.Collections.Generic;
using System.Net.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Moq;
using Ocelot.Configuration.Builder;
using Ocelot.DownstreamRouteFinder;
using Ocelot.DownstreamRouteFinder.UrlMatcher;
using Ocelot.DownstreamUrlCreator;
using Ocelot.DownstreamUrlCreator.Middleware;
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
using Ocelot.Infrastructure.RequestData;
using Ocelot.Logging;
using Ocelot.Responses;
using Ocelot.Values;
using TestStack.BDDfy;
using Xunit;
using Shouldly;
using Ocelot.DownstreamRouteFinder.Middleware;
using Microsoft.AspNetCore.Http;
public class DownstreamUrlCreatorMiddlewareTests
@ -43,9 +39,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator
_loggerFactory.Setup(x => x.CreateLogger<DownstreamUrlCreatorMiddleware>()).Returns(_logger.Object);
_downstreamUrlTemplateVariableReplacer = new Mock<IDownstreamPathPlaceholderReplacer>();
_downstreamContext.DownstreamRequest = new HttpRequestMessage(HttpMethod.Get, "https://my.url/abc/?q=123");
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
}
[Fact]

View File

@ -11,11 +11,12 @@ using Ocelot.Configuration.Builder;
using Ocelot.Headers;
using System.Net.Http;
using Ocelot.Authorisation.Middleware;
using Ocelot.DownstreamRouteFinder.Middleware;
using Ocelot.Middleware;
namespace Ocelot.UnitTests.Headers
{
using System.Threading.Tasks;
public class HttpHeadersTransformationMiddlewareTests
{
private Mock<IHttpContextRequestHeaderReplacer> _preReplacer;
@ -34,9 +35,7 @@ namespace Ocelot.UnitTests.Headers
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<AuthorisationMiddleware>()).Returns(_logger.Object);
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
_middleware = new HttpHeadersTransformationMiddleware(_next, _loggerFactory.Object, _preReplacer.Object, _postReplacer.Object);
}

View File

@ -4,14 +4,12 @@ namespace Ocelot.UnitTests.Headers
{
using System.Collections.Generic;
using System.Net.Http;
using Microsoft.AspNetCore.Builder;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
using Ocelot.DownstreamRouteFinder;
using Ocelot.DownstreamRouteFinder.Middleware;
using Ocelot.DownstreamRouteFinder.UrlMatcher;
using Ocelot.Headers;
using Ocelot.Headers.Middleware;
@ -37,9 +35,7 @@ namespace Ocelot.UnitTests.Headers
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<HttpRequestHeadersBuilderMiddleware>()).Returns(_logger.Object);
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
_middleware = new HttpRequestHeadersBuilderMiddleware(_next, _loggerFactory.Object, _addHeaders.Object);
_downstreamContext.DownstreamRequest = new HttpRequestMessage();
}

View File

@ -4,6 +4,7 @@ namespace Ocelot.UnitTests.LoadBalancer
{
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Moq;
using Ocelot.Configuration;
@ -43,9 +44,7 @@ namespace Ocelot.UnitTests.LoadBalancer
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<LoadBalancingMiddleware>()).Returns(_logger.Object);
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
_downstreamContext.DownstreamRequest = _downstreamRequest;
}

View File

@ -24,7 +24,7 @@ namespace Ocelot.UnitTests.Middleware
{
_aggregator = new Mock<IResponseAggregator>();
_context = new DownstreamContext(new DefaultHttpContext());
_pipeline = async context => { _count++; };
_pipeline = context => Task.FromResult(_count++);
_multiplexer = new Multiplexer(_aggregator.Object);
}

View File

@ -4,7 +4,6 @@ namespace Ocelot.UnitTests.QueryStrings
{
using System.Collections.Generic;
using System.Net.Http;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
@ -17,9 +16,8 @@ namespace Ocelot.UnitTests.QueryStrings
using TestStack.BDDfy;
using Xunit;
using System.Security.Claims;
using Microsoft.AspNetCore.Builder;
using Ocelot.DownstreamRouteFinder.Middleware;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
public class QueryStringBuilderMiddlewareTests
{
@ -36,9 +34,7 @@ namespace Ocelot.UnitTests.QueryStrings
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<QueryStringBuilderMiddleware>()).Returns(_logger.Object);
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
_addQueries = new Mock<IAddQueriesToRequest>();
_downstreamContext.DownstreamRequest = new HttpRequestMessage();
_middleware = new QueryStringBuilderMiddleware(_next, _loggerFactory.Object, _addQueries.Object);

View File

@ -15,9 +15,9 @@ namespace Ocelot.UnitTests.RateLimit
using Shouldly;
using TestStack.BDDfy;
using Xunit;
using Ocelot.DownstreamRouteFinder.Middleware;
using Microsoft.Extensions.Caching.Memory;
using System.IO;
using System.Threading.Tasks;
public class ClientRateLimitMiddlewareTests
{
@ -42,8 +42,7 @@ namespace Ocelot.UnitTests.RateLimit
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<ClientRateLimitMiddleware>()).Returns(_logger.Object);
_next = async (context) => {
};
_next = context => Task.CompletedTask;
_middleware = new ClientRateLimitMiddleware(_next, _loggerFactory.Object, _rateLimitCounterHandler);
}

View File

@ -9,6 +9,7 @@ namespace Ocelot.UnitTests.RequestId
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Moq;
using Ocelot.Configuration.Builder;
using Ocelot.DownstreamRouteFinder;
@ -40,8 +41,10 @@ namespace Ocelot.UnitTests.RequestId
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<ReRouteRequestIdMiddleware>()).Returns(_logger.Object);
_next = async context => {
_next = context =>
{
context.HttpContext.Response.Headers.Add("LSRequestId", context.HttpContext.TraceIdentifier);
return Task.CompletedTask;
};
_middleware = new ReRouteRequestIdMiddleware(_next, _loggerFactory.Object, _repo.Object);
_downstreamContext.DownstreamRequest = _downstreamRequest;

View File

@ -17,12 +17,13 @@ namespace Ocelot.UnitTests.Requester
}
public int Order {get;private set;}
public DateTime TimeCalled {get;private set;}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
TimeCalled = DateTime.Now;
return new HttpResponseMessage();
return Task.FromResult(new HttpResponseMessage());
}
}
}

View File

@ -13,6 +13,7 @@ namespace Ocelot.UnitTests.Requester
using TestStack.BDDfy;
using Xunit;
using Shouldly;
using System.Threading.Tasks;
public class HttpRequesterMiddlewareTests
{
@ -30,9 +31,7 @@ namespace Ocelot.UnitTests.Requester
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<HttpRequesterMiddleware>()).Returns(_logger.Object);
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
_middleware = new HttpRequesterMiddleware(_next, _loggerFactory.Object, _requester.Object);
}

View File

@ -5,6 +5,7 @@ namespace Ocelot.UnitTests.Responder
{
using Microsoft.AspNetCore.Http;
using System.Net.Http;
using System.Threading.Tasks;
using Moq;
using Ocelot.DownstreamRouteFinder.Finder;
using Ocelot.Errors;
@ -32,9 +33,7 @@ namespace Ocelot.UnitTests.Responder
_loggerFactory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_loggerFactory.Setup(x => x.CreateLogger<ResponderMiddleware>()).Returns(_logger.Object);
_next = async context => {
//do nothing
};
_next = context => Task.CompletedTask;
_middleware = new ResponderMiddleware(_next, _responder.Object, _loggerFactory.Object, _codeMapper.Object);
}