geffzhang 903b380a5b update .net core 3.0 RTM (#1025)
* feat: update to asp.net core 3.0 preview 9

* fix :  AspDotNetLogger unittest

* feat:  update generic host  and  useMvc

1、Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing https://github.com/aspnet/AspNetCore/issues/9542
2、 use IHost and IHostBuilder

* feat : update .net core 3.0 rc1

* eureka extension

* fixed logger formatter error

* fixed synchronous operations are disallowed of ReadToEnd method

* fix log tests

* Flush method of FakeStream should do nothing

* Update ContentTests.cs

* Fixed ws tests

* feat: delelte comment code

* feat: update .net core 3.0 RTM

* Update OcelotBuilderTests.cs

* Update .travis.yml

mono 6.0.0 and dotnet 3.0.100

* Update Ocelot.IntegrationTests.csproj

update Microsoft.Data.SQLite 3.0.0

* Update .travis.yml

* feat: remove FrameworkReference

1、 remove FrameworkReference
2、 update package

* add appveyor configuration to use version of VS2019 with dotnet core 3 sdk support

* update obsoleted SetCollectionValidator method

* Swap out OpenCover for Coverlet

* Bump Cake to 0.35.0

* Downgrade coveralls.net to 0.7.0
Fix disposing of PollConsul instance

* Remove environment specific path separator

* Do not return ReportGenerator on Mac/Linux

* Remove direct dependency on IInternalConfiguration

* Fix ordering of variable assignment

* Fix broken tests

* Fix acceptance tests for Consul
2019-10-28 07:24:30 +00:00

177 lines
6.8 KiB
C#

namespace Ocelot.AcceptanceTests
{
using Microsoft.AspNetCore.Http;
using Ocelot.Configuration.File;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Net;
using TestStack.BDDfy;
using Xunit;
public class ContentTests : IDisposable
{
private readonly Steps _steps;
private string _contentType;
private long? _contentLength;
private bool _contentTypeHeaderExists;
private readonly ServiceHandler _serviceHandler;
public ContentTests()
{
_serviceHandler = new ServiceHandler();
_steps = new Steps();
}
[Fact]
public void should_not_add_content_type_or_content_length_headers()
{
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
{
new FileReRoute
{
DownstreamPathTemplate = "/",
DownstreamScheme = "http",
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new FileHostAndPort
{
Host = "localhost",
Port = 51339,
}
},
UpstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "Get" },
}
}
};
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51339", "/", 200, "Hello from Laura"))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
.And(x => ThenTheContentTypeShouldBeEmpty())
.And(x => ThenTheContentLengthShouldBeZero())
.BDDfy();
}
[Fact]
public void should_add_content_type_and_content_length_headers()
{
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
{
new FileReRoute
{
DownstreamPathTemplate = "/",
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new FileHostAndPort
{
Host = "localhost",
Port = 51349,
}
},
DownstreamScheme = "http",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "Post" },
}
}
};
var contentType = "application/json";
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51349", "/", 201, string.Empty))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenThePostHasContent("postContent"))
.And(x => _steps.GivenThePostHasContentType(contentType))
.When(x => _steps.WhenIPostUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Created))
.And(x => ThenTheContentLengthIs(11))
.And(x => ThenTheContentTypeIsIs(contentType))
.BDDfy();
}
[Fact]
public void should_add_default_content_type_header()
{
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
{
new FileReRoute
{
DownstreamPathTemplate = "/",
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new FileHostAndPort
{
Host = "localhost",
Port = 51359,
}
},
DownstreamScheme = "http",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "Post" },
}
}
};
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51359", "/", 201, string.Empty))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenThePostHasContent("postContent"))
.When(x => _steps.WhenIPostUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Created))
.And(x => ThenTheContentLengthIs(11))
.And(x => ThenTheContentTypeIsIs("text/plain; charset=utf-8"))
.BDDfy();
}
private void ThenTheContentTypeIsIs(string expected)
{
_contentType.ShouldBe(expected);
}
private void ThenTheContentLengthShouldBeZero()
{
_contentLength.ShouldBeEquivalentTo(0L);
}
private void ThenTheContentLengthIs(int expected)
{
_contentLength.ShouldBe(expected);
}
private void ThenTheContentTypeShouldBeEmpty()
{
_contentType.ShouldBeNullOrEmpty();
_contentTypeHeaderExists.ShouldBe(false);
}
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
{
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
{
_contentType = context.Request.ContentType;
_contentLength = context.Request.ContentLength;
_contentTypeHeaderExists = context.Request.Headers.TryGetValue("Content-Type", out var value);
context.Response.StatusCode = statusCode;
await context.Response.WriteAsync(responseBody);
});
}
public void Dispose()
{
_serviceHandler?.Dispose();
_steps.Dispose();
}
}
}