mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 11:38:15 +08:00
Added first authentiction code..we have a test that makes sure we are unauthenticed but i havent been able to get authenticated to work yet due to identity server usual madness when calling with their SDK!
This commit is contained in:
@ -7,10 +7,10 @@ using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
using Ocelot.Library.Middleware;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -9,7 +11,6 @@
|
||||
using Library.Infrastructure.Repository;
|
||||
using Library.Infrastructure.Responses;
|
||||
using Library.Infrastructure.UrlMatcher;
|
||||
using Library.Middleware;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -10,7 +12,6 @@
|
||||
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;
|
||||
|
@ -7,10 +7,10 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.RequestBuilder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Middleware;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
|
@ -6,11 +6,11 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.RequestBuilder;
|
||||
using Ocelot.Library.Infrastructure.Requester;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Middleware;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
|
@ -6,10 +6,10 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.Responder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Middleware;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -19,6 +19,7 @@ namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
private readonly Mock<IHttpResponder> _responder;
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IErrorsToHttpStatusCodeMapper> _codeMapper;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
private readonly HttpClient _client;
|
||||
@ -30,10 +31,12 @@ namespace Ocelot.UnitTests.Middleware
|
||||
_url = "http://localhost:51879";
|
||||
_responder = new Mock<IHttpResponder>();
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_codeMapper = new Mock<IErrorsToHttpStatusCodeMapper>();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
{
|
||||
x.AddSingleton(_codeMapper.Object);
|
||||
x.AddSingleton(_responder.Object);
|
||||
x.AddSingleton(_scopedRepository.Object);
|
||||
})
|
||||
|
@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Responder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Responder
|
||||
{
|
||||
public class ErrorsToHttpStatusCodeMapperTests
|
||||
{
|
||||
private readonly IErrorsToHttpStatusCodeMapper _codeMapper;
|
||||
private Response<int> _result;
|
||||
private List<Error> _errors;
|
||||
|
||||
public ErrorsToHttpStatusCodeMapperTests()
|
||||
{
|
||||
_codeMapper = new ErrorsToHttpStatusCodeMapper();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_unauthenticated_response_code()
|
||||
{
|
||||
this.Given(x => x.GivenThereAreErrors(new List<Error>
|
||||
{
|
||||
new UnauthenticatedError("no matter")
|
||||
}))
|
||||
.When(x => x.WhenIGetErrorStatusCode())
|
||||
.Then(x => x.ThenTheResponseIsStatusCodeIs(401))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_not_found_response_response_code()
|
||||
{
|
||||
this.Given(x => x.GivenThereAreErrors(new List<Error>
|
||||
{
|
||||
new AnyError()
|
||||
}))
|
||||
.When(x => x.WhenIGetErrorStatusCode())
|
||||
.Then(x => x.ThenTheResponseIsStatusCodeIs(404))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
class AnyError : Error
|
||||
{
|
||||
public AnyError() : base("blahh", OcelotErrorCode.UnknownError)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void GivenThereAreErrors(List<Error> errors)
|
||||
{
|
||||
_errors = errors;
|
||||
}
|
||||
|
||||
private void WhenIGetErrorStatusCode()
|
||||
{
|
||||
_result = _codeMapper.Map(_errors);
|
||||
}
|
||||
|
||||
private void ThenTheResponseIsStatusCodeIs(int expectedCode)
|
||||
{
|
||||
_result.Data.ShouldBe(expectedCode);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Responder
|
||||
{
|
||||
public class ResponderTests
|
||||
{
|
||||
[Fact]
|
||||
public void should_do_something()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user