mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 09:08:14 +08:00
Feature/#623 (#632)
* #630 only set status code if response hasnt started, otherwise exception * #623 made {RemoteIpAddress} available as placeholder so you can do x-forwarded-for * #623 local address different on mac, windows and linux for integration test
This commit is contained in:
@ -1,27 +1,31 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using Moq;
|
||||
using Ocelot.Infrastructure;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.Request.Middleware;
|
||||
using Ocelot.Responses;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Infrastructure
|
||||
{
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Moq;
|
||||
using Ocelot.Infrastructure;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.Request.Middleware;
|
||||
using Ocelot.Responses;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
public class PlaceholdersTests
|
||||
{
|
||||
private IPlaceholders _placeholders;
|
||||
private Mock<IBaseUrlFinder> _finder;
|
||||
private Mock<IRequestScopedDataRepository> _repo;
|
||||
|
||||
private readonly IPlaceholders _placeholders;
|
||||
private readonly Mock<IBaseUrlFinder> _finder;
|
||||
private readonly Mock<IRequestScopedDataRepository> _repo;
|
||||
private readonly Mock<IHttpContextAccessor> _accessor;
|
||||
|
||||
public PlaceholdersTests()
|
||||
{
|
||||
_accessor = new Mock<IHttpContextAccessor>();
|
||||
_repo = new Mock<IRequestScopedDataRepository>();
|
||||
_finder = new Mock<IBaseUrlFinder>();
|
||||
_placeholders = new Placeholders(_finder.Object, _repo.Object);
|
||||
_placeholders = new Placeholders(_finder.Object, _repo.Object, _accessor.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -33,6 +37,15 @@ namespace Ocelot.UnitTests.Infrastructure
|
||||
result.Data.ShouldBe(baseUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_remote_ip_address()
|
||||
{
|
||||
var httpContext = new DefaultHttpContext(){Connection = { RemoteIpAddress = IPAddress.Any}};
|
||||
_accessor.Setup(x => x.HttpContext).Returns(httpContext);
|
||||
var result = _placeholders.Get("{RemoteIpAddress}");
|
||||
result.Data.ShouldBe(httpContext.Connection.RemoteIpAddress.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_key_does_not_exist()
|
||||
{
|
||||
|
Reference in New Issue
Block a user