-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathCommandTests.cs
44 lines (38 loc) · 1.43 KB
/
CommandTests.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
using System.Text.Json;
using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.TestUtilities;
using CommandQuery.AWSLambda;
using CommandQuery.Sample.Contracts.Commands;
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
namespace CommandQuery.Sample.AWSLambda.Tests
{
public class CommandTests
{
[SetUp]
public void SetUp()
{
var serviceCollection = new ServiceCollection();
new Startup().ConfigureServices(serviceCollection);
var serviceProvider = serviceCollection.BuildServiceProvider();
Subject = new Command(serviceProvider.GetRequiredService<ICommandFunction>());
Context = new TestLambdaContext();
}
[Test]
public async Task should_handle_command()
{
var response = await Subject.Post(GetRequest(new FooCommand { Value = "Foo" }), Context, "FooCommand");
response.StatusCode.Should().Be(200);
}
[Test]
public async Task should_handle_errors()
{
var response = await Subject.Post(GetRequest(new FooCommand()), Context, "FooCommand");
response.ShouldBeError("Value cannot be null or empty");
}
static APIGatewayProxyRequest GetRequest(object body) => new() { Body = JsonSerializer.Serialize(body) };
Command Subject = null!;
TestLambdaContext Context = null!;
}
}