Skip to content

Commit

Permalink
Added unit tests to Forms body
Browse files Browse the repository at this point in the history
  • Loading branch information
galvesribeiro committed Jan 9, 2020
1 parent 9808d9b commit 8aa96ac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
15 changes: 15 additions & 0 deletions test/Orleans.Http.Test/HttpTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -104,6 +105,20 @@ public async Task RouteTest()
Assert.True(response.StatusCode == HttpStatusCode.BadRequest);
}

[Fact]
public async Task FormsTest()
{
var payload = new TestPayload();
payload.Number = 12340000;
payload.Text = "Test text";

var url = "/grains/test/00000000-0000-0000-0000-000000000000/FormTest";
var dic = new Dictionary<string, string>();
dic["Test"] = "testing dic";
var response = await this._http.PostAsync(url, new FormUrlEncodedContent(dic));
Assert.True(response.StatusCode == HttpStatusCode.OK);
}

[Fact]
public async Task PostTest()
{
Expand Down
3 changes: 2 additions & 1 deletion test/Orleans.Http.Test/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public void ConfigureServices(IServiceCollection services)
services
.AddGrainRouter()
.AddJsonMediaType()
.AddProtobufMediaType();
.AddProtobufMediaType()
.AddFormsMediaType();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand Down
10 changes: 10 additions & 0 deletions test/Orleans.Http.Test/TestGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public interface ITestGrain : IGrainWithGuidKey

[HttpGet(pattern: "Get8")]
Task Get8();

[HttpPost("{grainId}/FormTest")]
Task FormTest([FromBody]Dictionary<string, string> payload);
}

[ProtoContract]
Expand Down Expand Up @@ -186,6 +189,13 @@ public Task<AuthResponse> GetWithAuthAdmin()
public Task Get7() => Task.CompletedTask;

public Task Get8() => Task.CompletedTask;

public Task FormTest(Dictionary<string, string> payload)
{
if (payload != null && payload.Count == 1) return Task.CompletedTask;

throw new ArgumentException(nameof(payload));
}
}

public class RandomGuidRouteGrainProvider : IRouteGrainProvider
Expand Down

0 comments on commit 8aa96ac

Please sign in to comment.