Repository navigation
Expand file tree
/
Copy pathAccountOperationsTests.cs
More file actions
65 lines (53 loc) · 2 KB
/
Copy pathAccountOperationsTests.cs
File metadata and controls
65 lines (53 loc) · 2 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
namespace UnitTesting
{
public class AccountOperationsTests
{
[Fact]
public async Task GetTotalAsync_ExistingAccountBalances_SumOfAllBalances()
{
// NOTE: How would you refactor this so you can test the add functionality to get the asserted result?
// Arrange
User user = new();
AccountRepository repository = new();
AccountOperations sut = new(user, repository);
// Act
decimal result = await sut.GetTotalAsync();
// Assert
Assert.Equal(100, result);
}
[Fact]
private async Task TransferAsync_ValidAccounts_AccountBalancesCorrectlySaved()
{
// Arrange
Account fromAccount = new(Guid.Empty, 100m);
Account toAccount = new(Guid.Empty, 0m);
User user = new();
AccountRepository repository = new();
AccountOperations sut = new(user, repository);
// Act
await sut.TransferAsync(fromAccount, toAccount, 100m);
// Assert
// NOTE: Check to see if the balance matches expected value
// NOTE: Check to see if the repository SaveChangesAsync did in fact get called correctly
}
[Fact]
private async Task TransferAsync_InvalidTransferAmount_ThrowsInvalidOperationException()
{
// Arrange
Account fromAccount = new(Guid.Empty, 50m);
Account toAccount = new(Guid.Empty, 50m);
User user = new();
AccountRepository repository = new();
AccountOperations sut = new(user, repository);
// Act
await sut.TransferAsync(fromAccount, toAccount, 100m);
// Assert
// NOTE: Assert than an InvalidOperationException was thrown as the transfer amount exceeds the account balance
}
}
}