mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 17:08:15 +08:00
simplifying stuff after i realised i added loads of crap i dont need
This commit is contained in:
70
test/Ocelot.AcceptanceTests/OcelotTests.cs
Normal file
70
test/Ocelot.AcceptanceTests/OcelotTests.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Xunit;
|
||||
using Ocelot.AcceptanceTests.Fake;
|
||||
using Shouldly;
|
||||
|
||||
namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
using System.Net;
|
||||
using TestStack.BDDfy;
|
||||
|
||||
public class OcelotTests : IDisposable
|
||||
{
|
||||
private readonly FakeService _fakeService;
|
||||
private readonly TestServer _server;
|
||||
private readonly HttpClient _client;
|
||||
private HttpResponseMessage _response;
|
||||
|
||||
public OcelotTests()
|
||||
{
|
||||
_server = new TestServer(new WebHostBuilder()
|
||||
.UseStartup<Startup>());
|
||||
|
||||
_client = _server.CreateClient();
|
||||
|
||||
_fakeService = new FakeService();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_404()
|
||||
{
|
||||
this.When(x => x.WhenIRequestTheUrl("/"))
|
||||
.Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200()
|
||||
{
|
||||
this.When(x => x.WhenIRequestTheUrl("/"))
|
||||
.Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(x => x.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void WhenIRequestTheUrl(string url)
|
||||
{
|
||||
_response = _client.GetAsync("/").Result;
|
||||
}
|
||||
|
||||
private void ThenTheStatusCodeShouldBe(HttpStatusCode expectedHttpStatusCode)
|
||||
{
|
||||
_response.StatusCode.ShouldBe(expectedHttpStatusCode);
|
||||
}
|
||||
|
||||
private void ThenTheResponseBodyShouldBe(string expectedBody)
|
||||
{
|
||||
_response.Content.ReadAsStringAsync().Result.ShouldBe(expectedBody);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_fakeService.Stop();
|
||||
_client.Dispose();
|
||||
_server.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user