-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathMockBusinessLogicTests.cs
76 lines (59 loc) · 2.65 KB
/
MockBusinessLogicTests.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
using FakeItEasy;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using ServerlessTestSamples.Core.Queries;
using ServerlessTestSamples.Core.Services;
namespace ServerlessTestSamples.UnitTest;
public class MockBusinessLogicTests
{
private ILogger<ListStorageAreasQueryHandler> Logger { get; } = A.Fake<ILogger<ListStorageAreasQueryHandler>>();
[Fact]
public async Task TestCoreBusinessLogic_With_SuccessfulResponse_Should_ReturnStorageAreas()
{
// arrange
var fakeStorageService = A.Fake<IStorageService>();
A.CallTo(() => fakeStorageService.ListStorageAreas(A<string>._, A<CancellationToken>._))
.Returns(Task.FromResult(new ListStorageAreasResult(
new List<string>()
{
"bucket1",
"bucket2",
"bucket3",
})));
var handler = new ListStorageAreasQueryHandler(fakeStorageService, Logger);
// act
var result = await handler.Handle(new() { FilterPrefix = string.Empty }, default);
// assert
result.Should().BeEquivalentTo(new ListStorageAreasQueryResult(new[] { "bucket1", "bucket2", "bucket3" }));
}
[Fact]
public async Task TestCoreBusinessLogic_With_ErrorStorageResponse_Should_ReturnEmptyList()
{
// arrange
var fakeStorageService = A.Fake<IStorageService>();
A.CallTo(() => fakeStorageService.ListStorageAreas(A<string>._, A<CancellationToken>._))
.Returns(
Task.FromResult(
new ListStorageAreasResult(Enumerable.Empty<string>(),
false, "Failure retrieving storage data")));
var handler = new ListStorageAreasQueryHandler(fakeStorageService, Logger);
// act
var result = await handler.Handle(new() { FilterPrefix = string.Empty }, default);
// assert
result.Should().BeEquivalentTo(new ListStorageAreasQueryResult(Enumerable.Empty<string>()));
}
[Fact]
public async Task TestCoreBusinessLogic_With_StorageServiceException_Should_ReturnEmptyList()
{
// arrange
var fakeStorageService = A.Fake<IStorageService>();
A.CallTo(() =>
fakeStorageService.ListStorageAreas(A<string>._, A<CancellationToken>._))
.Throws<Exception>();
var handler = new ListStorageAreasQueryHandler(fakeStorageService, Logger);
// act
var result = await handler.Handle(new() { FilterPrefix = string.Empty }, default);
// assert
result.Should().BeEquivalentTo(new ListStorageAreasQueryResult(Enumerable.Empty<string>()));
}
}