-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathQueryTests.cs
45 lines (40 loc) · 1.23 KB
/
QueryTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Net.Http.Json;
using CommandQuery.Sample.Contracts.Queries;
using FluentAssertions;
using Google.Cloud.Functions.Testing;
using Microsoft.AspNetCore.Http;
using NUnit.Framework;
namespace CommandQuery.Sample.GoogleCloudFunctions.Tests
{
public class QueryTests
{
[SetUp]
public void SetUp()
{
Server = new FunctionTestServer<Query>();
Client = Server.CreateClient();
}
[TearDown]
public void TearDown()
{
Client.Dispose();
Server.Dispose();
}
[Test]
public async Task should_handle_query_via_Post()
{
var response = await Client.PostAsJsonAsync("/api/query/BarQuery", new BarQuery { Id = 1 });
var value = await response.Content.ReadFromJsonAsync<Bar>();
value!.Id.Should().Be(1);
}
[Test]
public async Task should_handle_query_via_Get()
{
var response = await Client.GetAsync("/api/query/BarQuery?Id=1");
var value = await response.Content.ReadFromJsonAsync<Bar>();
value!.Id.Should().Be(1);
}
FunctionTestServer<Query> Server = null!;
HttpClient Client = null!;
}
}