Skip to content

Commit 9f7422c

Browse files
committed
Merge master
2 parents 522775a + bea6f91 commit 9f7422c

3 files changed

Lines changed: 130 additions & 0 deletions

File tree

BankXUnitTests/BankAccountTests.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using Bank;
2+
using System;
3+
using Xunit;
4+
5+
namespace BankXUnitTests
6+
{
7+
public class BankAccountTests
8+
{
9+
[Fact]
10+
public void Adding_Funds_Updates_Balance()
11+
{
12+
// ARRANGE
13+
var account = new BankAccount(1000);
14+
15+
// ACT
16+
account.Add(100);
17+
18+
// ASSERT
19+
Assert.Equal(1100, account.Balance);
20+
}
21+
22+
[Fact]
23+
public void Adding_Negative_Funds_Throws()
24+
{
25+
// ARRANGE
26+
var account = new BankAccount(1000);
27+
28+
// ACT + ASSERT
29+
Assert.Throws<ArgumentOutOfRangeException>(() => account.Add(-100));
30+
}
31+
32+
[Fact]
33+
public void Withdrawing_Funds_Updates_Balance()
34+
{
35+
// ARRANGE
36+
var account = new BankAccount(1000);
37+
38+
// ACT
39+
account.Withdraw(100);
40+
41+
// ASSERT
42+
Assert.Equal(900, account.Balance);
43+
}
44+
45+
[Fact]
46+
public void Withdrawing_Negative_Funds_Throws()
47+
{
48+
// ARRANGE
49+
var account = new BankAccount(1000);
50+
51+
// ACT + ASSERT
52+
Assert.Throws<ArgumentOutOfRangeException>(() => account.Withdraw(-100));
53+
}
54+
55+
[Fact]
56+
public void Withdrawing_More_Than_Funds_Throws()
57+
{
58+
// ARRANGE
59+
var account = new BankAccount(1000);
60+
61+
// ACT + ASSERT
62+
Assert.Throws<ArgumentOutOfRangeException>(() => account.Withdraw(2000));
63+
}
64+
65+
[Fact]
66+
public void Transfering_Funds_Updates_Both_Accounts()
67+
{
68+
// ARRANGE
69+
var account = new BankAccount(1000);
70+
var otherAccount = new BankAccount();
71+
72+
// ACT
73+
account.TransferFundsTo(otherAccount, 500);
74+
75+
// ASSERT
76+
Assert.Equal(500, account.Balance);
77+
Assert.Equal(500, otherAccount.Balance);
78+
}
79+
80+
[Fact]
81+
public void TransferFundsTo_Non_Existing_Account_Throws()
82+
{
83+
// ARRANGE
84+
var account = new BankAccount(1000);
85+
86+
// ACT + ASSERT
87+
Assert.Throws<ArgumentNullException>(() => account.TransferFundsTo(null, 2000));
88+
}
89+
}
90+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
11+
<PackageReference Include="xunit" Version="2.4.1" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
16+
<PackageReference Include="coverlet.collector" Version="1.3.0">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\Bank\Bank.csproj" />
24+
</ItemGroup>
25+
26+
</Project>

UnitTestingTutorial.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bank", "Bank\Bank.csproj",
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankNUnitTests", "BankNUnitTests\BankNUnitTests.csproj", "{B26B161C-31B7-43EC-9E56-981F64F82935}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankXUnitTests", "BankXUnitTests\BankXUnitTests.csproj", "{D35819B5-A383-49C2-9256-BAFCE475E07F}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -41,6 +43,18 @@ Global
4143
{B26B161C-31B7-43EC-9E56-981F64F82935}.Release|x64.Build.0 = Release|Any CPU
4244
{B26B161C-31B7-43EC-9E56-981F64F82935}.Release|x86.ActiveCfg = Release|Any CPU
4345
{B26B161C-31B7-43EC-9E56-981F64F82935}.Release|x86.Build.0 = Release|Any CPU
46+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Debug|x64.ActiveCfg = Debug|Any CPU
49+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Debug|x64.Build.0 = Debug|Any CPU
50+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Debug|x86.ActiveCfg = Debug|Any CPU
51+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Debug|x86.Build.0 = Debug|Any CPU
52+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Release|Any CPU.Build.0 = Release|Any CPU
54+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Release|x64.ActiveCfg = Release|Any CPU
55+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Release|x64.Build.0 = Release|Any CPU
56+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Release|x86.ActiveCfg = Release|Any CPU
57+
{D35819B5-A383-49C2-9256-BAFCE475E07F}.Release|x86.Build.0 = Release|Any CPU
4458
EndGlobalSection
4559
GlobalSection(SolutionProperties) = preSolution
4660
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)