Skip to content

Commit

Permalink
Merge branch 'release/v0.4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
James Stumme committed Feb 11, 2017
2 parents 9610332 + c71ee9f commit 61b231d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/RService.IO.Abstractions/project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "RService.IO.Abstractions",
"version": "0.4.2",
"version": "0.4.3",

"packOptions": {
"summary": "The abstractions required for implementing a RService.IO service and routes.",
Expand Down
2 changes: 1 addition & 1 deletion src/RService.IO.Authorization/project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "RService.IO.Authorization",
"version": "0.4.2",
"version": "0.4.3",

"packOptions": {
"summary": "RService.IO authorization provider.",
Expand Down
4 changes: 2 additions & 2 deletions src/RService.IO/RServiceMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public async Task Invoke(HttpContext context)
acceptHeader = new StringValues(HttpContentTypes.Any);

if (acceptHeader.TakeWhile(header => !_options.SerializationProviders
.TryGetValue(header, out responseSerializer))
.Any(header => header == HttpContentTypes.Any))
.TryGetValue(header.Split(';')[0], out responseSerializer))
.Any(header => header.StartsWith( HttpContentTypes.Any)))
responseSerializer = _options.DefaultSerializationProvider;

if (responseSerializer == null)
Expand Down
2 changes: 1 addition & 1 deletion src/RService.IO/project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "RService.IO",
"version": "0.4.2",
"version": "0.4.3",
"packOptions": {
"summary": "A web service framework for dotnet core loosely based on ServiceStack v3",
"releaseNotes": "Initial alpha release",
Expand Down
56 changes: 56 additions & 0 deletions test/RService.IO.Tests/RServiceMiddlewareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,62 @@ public async void Invoke__AcceptHeaderBlankReturnsOk()
context.Response.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.OK);
}

[Fact]
public async void Invoke__AcceptHeaderAnyWithQualityReturnsOk()
{
var routePath = "/Foobar".Substring(1);
Delegate.Activator routeActivator = (target, args) => null;
var expectedFeature = new Mock<IRServiceFeature>();
expectedFeature.SetupGet(x => x.MethodActivator).Returns(routeActivator);

var sink = GetTestSink();

var provider = new Mock<IServiceProvider>()
.SetupAllProperties();
provider.Setup(x => x.Invoke(It.IsAny<HttpContext>()))
.Returns(Task.FromResult(0));

var routeData = BuildRouteData(routePath);
var context = BuildContext(routeData, ctx => Task.FromResult(0), accept: "*/*;q=0.8");
var middleware = BuildMiddleware(sink, $"{routePath}:GET", routeActivator, serviceProvider: provider.Object);

await middleware.Invoke(context);

context.Response.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.OK);
}

[Fact]
public async void Invoke__AcceptHeaderWithQualityReturnsOk()
{
var routePath = "/Foobar".Substring(1);
Delegate.Activator routeActivator = (target, args) => null;
var expectedFeature = new Mock<IRServiceFeature>();
expectedFeature.SetupGet(x => x.MethodActivator).Returns(routeActivator);

var sink = GetTestSink();

var provider = new Mock<IServiceProvider>()
.SetupAllProperties();
provider.Setup(x => x.Invoke(It.IsAny<HttpContext>()))
.Returns(Task.FromResult(0));

var routeData = BuildRouteData(routePath);
var options = BuildRServiceOptions(opt =>
{
var json = new NetJsonProvider();
opt.DefaultSerializationProvider = json;
opt.SerializationProviders.Add(json.ContentType, json);
});
var context = BuildContext(routeData, ctx => Task.FromResult(0),
accept: $"{new NetJsonProvider().ContentType};q=0.8");
var middleware = BuildMiddleware(sink, $"{routePath}:GET", routeActivator, serviceProvider: provider.Object,
options: options);

await middleware.Invoke(context);

context.Response.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.OK);
}

[Fact]
public async void Invoke__AcceptHeaderNotMachingSerialzaitonProviderReturnsNotAcceptable()
{
Expand Down

0 comments on commit 61b231d

Please sign in to comment.