added happy path tests for more middlewares

This commit is contained in:
TomPallister
2016-10-13 19:59:12 +01:00
parent 52ba77f4d5
commit 7ae35f4ce3
8 changed files with 324 additions and 69 deletions

View File

@ -1,24 +1,21 @@
/*
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.RequestBuilder;
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Middleware;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Middleware
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using Library.Infrastructure.DownstreamRouteFinder;
using Library.Infrastructure.Repository;
using Library.Infrastructure.RequestBuilder;
using Library.Infrastructure.Responses;
using Library.Infrastructure.UrlMatcher;
using Library.Infrastructure.UrlTemplateReplacer;
using Library.Middleware;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using TestStack.BDDfy;
using Xunit;
public class HttpRequestBuilderMiddlewareTests : IDisposable
{
private readonly Mock<IRequestBuilder> _requestBuilder;
@ -27,6 +24,7 @@ namespace Ocelot.UnitTests.Middleware
private readonly TestServer _server;
private readonly HttpClient _client;
private HttpResponseMessage _result;
private OkResponse<Request> _request;
private OkResponse<string> _downstreamUrl;
public HttpRequestBuilderMiddlewareTests()
@ -58,25 +56,26 @@ namespace Ocelot.UnitTests.Middleware
[Fact]
public void happy_path()
{
this.Given(x => x.GivenTheDownStreamUrlIs(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), "any old string")))
.And(x => x.GivenTheRequestBuilderReturns("any old string"))
this.Given(x => x.GivenTheDownStreamUrlIs("any old string"))
.And(x => x.GivenTheRequestBuilderReturns(new Request(new HttpRequestMessage(), new CookieContainer())))
.When(x => x.WhenICallTheMiddleware())
.Then(x => x.ThenTheScopedDataRepositoryIsCalledCorrectly())
.BDDfy();
}
private void GivenTheRequestBuilderReturns(Response<Request> request)
private void GivenTheRequestBuilderReturns(Request request)
{
_downstreamUrl = new OkResponse<string>(downstreamUrl);
_downstreamUrlTemplateVariableReplacer
.Setup(x => x.ReplaceTemplateVariables(It.IsAny<DownstreamRoute>()))
.Returns(_downstreamUrl);
_request = new OkResponse<Request>(request);
_requestBuilder
.Setup(x => x.Build(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Stream>(), It.IsAny<IHeaderDictionary>(),
It.IsAny<IRequestCookieCollection>(), It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(_request);
}
private void ThenTheScopedDataRepositoryIsCalledCorrectly()
{
_scopedRepository
.Verify(x => x.Add("DownstreamUrl", _downstreamUrl.Data), Times.Once());
.Verify(x => x.Add("Request", _request.Data), Times.Once());
}
private void WhenICallTheMiddleware()
@ -84,9 +83,9 @@ namespace Ocelot.UnitTests.Middleware
_result = _client.GetAsync(_url).Result;
}
private void GivenTheDownStreamUrlIs(string downstreamRoute)
private void GivenTheDownStreamUrlIs(string downstreamUrl)
{
_downstreamUrl = new OkResponse<string>(downstreamRoute);
_downstreamUrl = new OkResponse<string>(downstreamUrl);
_scopedRepository
.Setup(x => x.Get<string>(It.IsAny<string>()))
.Returns(_downstreamUrl);
@ -99,4 +98,3 @@ namespace Ocelot.UnitTests.Middleware
}
}
}
*/