mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-12-17 17:55:49 +08:00
naming and plan
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user