-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathProcessEmployeeFunctionTests.cs
84 lines (70 loc) · 2.73 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
79
80
81
82
83
84
using System;
using System.ComponentModel.DataAnnotations;
using System.Threading;
using System.Threading.Tasks;
using Amazon.Lambda.TestUtilities;
using FluentAssertions;
using KinesisEventHandler.Functions;
using KinesisEventHandler.Repositories;
using KinesisEventHandler.Repositories.Mappers;
using KinesisEventHandler.Repositories.Models;
using KinesisEventHandler.UnitTests.Utilities;
using FakeItEasy;
using Xunit;
namespace KinesisEventHandler.UnitTests.Functions;
public class ProcessEmployeeFunctionTests
{
[Fact]
public Task ProcessEmployeeFunction_With_ValidEmployeeRecord_Should_ProcessKinesisRecordSuccessfully()
{
//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.ProcessKinesisRecord(employee, context);
//Assert
Assert.True(taskResult.IsCompleted);
return Task.CompletedTask;
}
[Fact]
public async Task ProcessEmployeeFunction_With_ValidEmployeeRecord_Should_PassValidation()
{
//Arrange
var fakeRepository = A.Fake<IDynamoDbRepository<EmployeeDto>>();
var sut = new ProcessEmployeeFunction(fakeRepository);
var employee = new EmployeeBuilder().Build();
//Act
var result = await sut.ValidateKinesisRecord(employee);
//Assert
result.Should().BeTrue();
}
[Fact]
public async Task ProcessEmployeeFunction_With_InvalidEmployeeRecord_Should_ThrowValidationException()
{
//Arrange
var fakeRepository = A.Fake<IDynamoDbRepository<EmployeeDto>>();
var sut = new ProcessEmployeeFunction(fakeRepository);
var employee = new EmployeeBuilder().WithEmployeeId(null);
//Act & Assert
await sut.Invoking(_ => sut.ValidateKinesisRecord(employee))
.Should()
.ThrowAsync<ValidationException>()
.WithMessage("'EmployeeId' cannot be null or empty");
}
[Fact]
public async Task ProcessEmployeeFunction_With_NullEmployeeRecord_Should_ThrowArgumentNullException()
{
//Arrange
var repository = A.Fake<IDynamoDbRepository<EmployeeDto>>();
var sut = new ProcessEmployeeFunction(repository);
//Act & Assert
await sut.Invoking(_ => sut.ValidateKinesisRecord(null))
.Should()
.ThrowAsync<ArgumentNullException>()
.WithMessage("Value cannot be null. (Parameter 'record')");
}
}