naming and plan

This commit is contained in:
Tom Gardham-Pallister
2016-07-10 17:38:54 +01:00
parent 711a3d6a91
commit cea6a557e9
22 changed files with 182 additions and 159 deletions

View File

@ -1,21 +1,21 @@
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.BaseUrlRepository;
using Ocelot.Library.Infrastructure.HostUrlRepository;
using Shouldly;
using Xunit;
namespace Ocelot.UnitTests
{
public class BaseUrlMapRepositoryTests
public class HostUrlMapRepositoryTests
{
private string _upstreamBaseUrl;
private string _downstreamBaseUrl;
private IBaseUrlMapRepository _repository;
private IHostUrlMapRepository _repository;
private Response _response;
private Response<BaseUrlMap> _getRouteResponse;
private Response<HostUrlMap> _getRouteResponse;
public BaseUrlMapRepositoryTests()
public HostUrlMapRepositoryTests()
{
_repository = new InMemoryBaseUrlMapRepository();
_repository = new InMemoryHostUrlMapRepository();
}
[Fact]
@ -66,7 +66,7 @@ namespace Ocelot.UnitTests
private void ThenTheKeyDoesNotExist()
{
_getRouteResponse.ShouldNotBeNull();
_getRouteResponse.ShouldBeOfType<ErrorResponse<BaseUrlMap>>();
_getRouteResponse.ShouldBeOfType<ErrorResponse<HostUrlMap>>();
_getRouteResponse.Errors[0].Message.ShouldBe("This key does not exist");
}
@ -77,8 +77,8 @@ namespace Ocelot.UnitTests
private void ThenTheRouteIsReturned()
{
_getRouteResponse.Data.DownstreamBaseUrl.ShouldBe(_downstreamBaseUrl);
_getRouteResponse.Data.UpstreamBaseUrl.ShouldBe(_upstreamBaseUrl);
_getRouteResponse.Data.DownstreamHostUrl.ShouldBe(_downstreamBaseUrl);
_getRouteResponse.Data.UpstreamHostUrl.ShouldBe(_upstreamBaseUrl);
}
private void GivenIHaveSetUpAnApiKeyAndUpstreamUrl(string apiKey, string upstreamUrl)
@ -100,7 +100,7 @@ namespace Ocelot.UnitTests
private void WhenIAddTheConfiguration()
{
_response = _repository.AddBaseUrlMap(new BaseUrlMap(_downstreamBaseUrl, _upstreamBaseUrl));
_response = _repository.AddBaseUrlMap(new HostUrlMap(_downstreamBaseUrl, _upstreamBaseUrl));
}
private void ThenTheResponseIsSuccesful()

View File

@ -1,4 +1,4 @@
using Ocelot.Library.Infrastructure.BaseUrlRepository;
using Ocelot.Library.Infrastructure.HostUrlRepository;
using Ocelot.Library.Infrastructure.UrlFinder;
using Ocelot.Library.Infrastructure.Responses;
using Xunit;
@ -9,28 +9,41 @@ namespace Ocelot.UnitTests
{
public class UpstreamBaseUrlFinderTests
{
private IUpstreamBaseUrlFinder _upstreamBaseUrlFinder;
private IBaseUrlMapRepository _baseUrlMapRepository;
private IUpstreamHostUrlFinder _upstreamBaseUrlFinder;
private IHostUrlMapRepository _hostUrlMapRepository;
private string _downstreamBaseUrl;
private Response<string> _result;
public UpstreamBaseUrlFinderTests()
{
_baseUrlMapRepository = new InMemoryBaseUrlMapRepository();
_upstreamBaseUrlFinder = new UpstreamBaseUrlFinder(_baseUrlMapRepository);
_hostUrlMapRepository = new InMemoryHostUrlMapRepository();
_upstreamBaseUrlFinder = new UpstreamHostUrlFinder(_hostUrlMapRepository);
}
[Fact]
public void can_find_base_url()
{
GivenTheBaseUrlMapExists(new BaseUrlMap("api.tom.com", "api.laura.com"));
GivenTheBaseUrlMapExists(new HostUrlMap("api.tom.com", "api.laura.com"));
GivenTheDownstreamBaseUrlIs("api.tom.com");
WhenIFindTheMatchingUpstreamBaseUrl();
ThenTheFollowingIsReturned("api.laura.com");
}
private void GivenTheBaseUrlMapExists(BaseUrlMap baseUrlMap)
[Fact]
public void cant_find_base_url()
{
_baseUrlMapRepository.AddBaseUrlMap(baseUrlMap);
GivenTheDownstreamBaseUrlIs("api.tom.com");
WhenIFindTheMatchingUpstreamBaseUrl();
ThenAnErrorIsReturned();
}
private void ThenAnErrorIsReturned()
{
_result.Errors.Count.ShouldBe(1);
}
private void GivenTheBaseUrlMapExists(HostUrlMap baseUrlMap)
{
_hostUrlMapRepository.AddBaseUrlMap(baseUrlMap);
}
@ -41,7 +54,7 @@ namespace Ocelot.UnitTests
private void WhenIFindTheMatchingUpstreamBaseUrl()
{
_result = _upstreamBaseUrlFinder.FindUpstreamBaseUrl(_downstreamBaseUrl);
_result = _upstreamBaseUrlFinder.FindUpstreamHostUrl(_downstreamBaseUrl);
}