-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathProcessEmployeeFunctionTests.cs
78 lines (64 loc) · 2.58 KB
/
ProcessEmployeeFunctionTests.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Threading;
using System.Threading.Tasks;
using Amazon.Lambda.TestUtilities;
using Amazon.Runtime.SharedInterfaces;
using FluentAssertions;
using FakeItEasy;
using SqsEventHandler.Functions;
using SqsEventHandler.Repositories;
using SqsEventHandler.Repositories.Mappers;
using SqsEventHandler.Repositories.Models;
using SqsEventHandler.UnitTests.Utilities;
using Xunit;
namespace SqsEventHandler.UnitTests.Functions;
public class ProcessEmployeeFunctionTests
{
[Fact]
public Task ProcessEmployeeFunction_Should_ExecuteSuccessfully()
{
//Arrange
var fakeRepository = A.Fake<IDynamoDbRepository<EmployeeDto>>();
A.CallTo(() => fakeRepository.PutItemAsync(A<EmployeeDto>._, A<CancellationToken>._))
.Returns(Task.FromResult(UpsertResult.Inserted));
var sut = new ProcessEmployeeFunction(fakeRepository);
var employee = new EmployeeBuilder().Build();
var context = new TestLambdaContext();
//Act
var taskResult = sut.ProcessSqsMessage(employee, context);
//Assert
Assert.True(taskResult.IsCompleted);
return Task.CompletedTask;
}
[Fact]
public async Task ProcessEmployeeFunction_Should_NotThrowArgumentNullException()
{
//Arrange
var fakeRepository = A.Fake<IDynamoDbRepository<EmployeeDto>>();
A.CallTo(() => fakeRepository.PutItemAsync(A<EmployeeDto>._, A<CancellationToken>._))
.Returns(Task.FromResult(UpsertResult.Inserted));
var sut = new ProcessEmployeeFunction(fakeRepository);
var employee = new EmployeeBuilder().Build();
var context = new TestLambdaContext();
//Act & Assert
await sut.Invoking(_ => sut.ProcessSqsMessage(employee, context))
.Should()
.NotThrowAsync<ArgumentNullException>();
}
[Fact]
public async Task ProcessEmployeeFunction_Should_ThrowArgumentNullException()
{
//Arrange
var fakeRepository = A.Fake<IDynamoDbRepository<EmployeeDto>>();
A.CallTo(() => fakeRepository.PutItemAsync(A<EmployeeDto>._, A<CancellationToken>._))
.Returns(Task.FromResult(UpsertResult.Inserted));
var sut = new ProcessEmployeeFunction(fakeRepository);
var employee = new EmployeeBuilder().WithEmployeeId(null);
var context = new TestLambdaContext();
//Act & Assert
await sut.Invoking(_ => sut.ProcessSqsMessage(employee, context))
.Should()
.ThrowAsync<ArgumentNullException>()
.WithMessage("Value cannot be null. (Parameter 'EmployeeId')");
}
}