added a base url finder

This commit is contained in:
Tom Gardham-Pallister
2016-07-10 17:11:12 +01:00
parent 5b417ad466
commit 711a3d6a91
29 changed files with 356 additions and 186 deletions

View File

@ -0,0 +1,53 @@
using Ocelot.Library.Infrastructure.BaseUrlRepository;
using Ocelot.Library.Infrastructure.UrlFinder;
using Ocelot.Library.Infrastructure.Responses;
using Xunit;
using Shouldly;
using System;
namespace Ocelot.UnitTests
{
public class UpstreamBaseUrlFinderTests
{
private IUpstreamBaseUrlFinder _upstreamBaseUrlFinder;
private IBaseUrlMapRepository _baseUrlMapRepository;
private string _downstreamBaseUrl;
private Response<string> _result;
public UpstreamBaseUrlFinderTests()
{
_baseUrlMapRepository = new InMemoryBaseUrlMapRepository();
_upstreamBaseUrlFinder = new UpstreamBaseUrlFinder(_baseUrlMapRepository);
}
[Fact]
public void can_find_base_url()
{
GivenTheBaseUrlMapExists(new BaseUrlMap("api.tom.com", "api.laura.com"));
GivenTheDownstreamBaseUrlIs("api.tom.com");
WhenIFindTheMatchingUpstreamBaseUrl();
ThenTheFollowingIsReturned("api.laura.com");
}
private void GivenTheBaseUrlMapExists(BaseUrlMap baseUrlMap)
{
_baseUrlMapRepository.AddBaseUrlMap(baseUrlMap);
}
private void GivenTheDownstreamBaseUrlIs(string downstreamBaseUrl)
{
_downstreamBaseUrl = downstreamBaseUrl;
}
private void WhenIFindTheMatchingUpstreamBaseUrl()
{
_result = _upstreamBaseUrlFinder.FindUpstreamBaseUrl(_downstreamBaseUrl);
}
private void ThenTheFollowingIsReturned(string expectedBaseUrl)
{
_result.Data.ShouldBe(expectedBaseUrl);
}
}
}