Skip to content

Commit 657c44e

Browse files
Part10
Part10
1 parent 78d79d1 commit 657c44e

9 files changed

+199
-43
lines changed

UserManagement.Application.UnitTests/User/Commands/AddUserCommandValidatorTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Shouldly;
2-
using System.Linq;
3-
using UserManagement.Application.Common.Interfaces;
4-
using UserManagement.Application.User.Commands;
5-
using Xunit;
6-
7-
namespace UserManagement.ApplicationTests.User.Commands
1+
namespace UserManagement.ApplicationTests.User.Commands
82
{
3+
using Shouldly;
4+
using System.Linq;
5+
using UserManagement.Application.Common.Interfaces;
6+
using UserManagement.Application.User.Commands;
7+
using Xunit;
8+
99
[Collection("UserCollection")]
1010
public class AddUserCommandValidatorTest
1111
{

UserManagement.Application.UnitTests/User/Commands/DeleteUserCommandTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using AutoMapper;
2-
using Shouldly;
3-
using System.Threading;
4-
using System.Threading.Tasks;
5-
using UserManagement.Application.Common.Interfaces;
6-
using UserManagement.Application.User.Commands;
7-
using UserManagement.Domain.UnitOfWork;
8-
using Xunit;
9-
10-
namespace UserManagement.ApplicationTests.User.Commands
1+
namespace UserManagement.ApplicationTests.User.Commands
112
{
3+
using AutoMapper;
4+
using Shouldly;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
using UserManagement.Application.Common.Interfaces;
8+
using UserManagement.Application.User.Commands;
9+
using UserManagement.Domain.UnitOfWork;
10+
using Xunit;
11+
1212
[Collection("UserCollection")]
1313
public class DeleteUserCommandTest
1414
{

UserManagement.Application.UnitTests/User/Commands/DeleteUserCommandValidatorTest.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using Shouldly;
2-
using System.Linq;
3-
using UserManagement.Application.Common.Interfaces;
4-
using UserManagement.Application.User.Commands;
5-
using Xunit;
6-
7-
namespace UserManagement.ApplicationTests.User.Commands
1+
namespace UserManagement.ApplicationTests.User.Commands
82
{
3+
using Shouldly;
4+
using UserManagement.Application.Common.Interfaces;
5+
using UserManagement.Application.User.Commands;
6+
using Xunit;
7+
98
[Collection("UserCollection")]
109
public class DeleteUserCommandValidatorTest
1110
{

UserManagement.Application.UnitTests/User/Commands/UpdateUserCommandTest.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
using AutoMapper;
2-
using Shouldly;
3-
using System.Threading;
4-
using System.Threading.Tasks;
5-
using UserManagement.Application.Common.Interfaces;
6-
using UserManagement.Application.User.Commands;
7-
using UserManagement.Domain.UnitOfWork;
8-
using Xunit;
9-
10-
11-
namespace UserManagement.ApplicationTests.User.Commands
1+
namespace UserManagement.ApplicationTests.User.Commands
122
{
3+
using AutoMapper;
4+
using Shouldly;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
using UserManagement.Application.Common.Interfaces;
8+
using UserManagement.Application.User.Commands;
9+
using UserManagement.Domain.UnitOfWork;
10+
using Xunit;
11+
1312
[Collection("UserCollection")]
1413
public class UpdateUserCommandTest
1514
{

UserManagement.Application.UnitTests/User/Commands/UpdateUserCommandValidatorTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Shouldly;
2-
using System.Linq;
3-
using UserManagement.Application.Common.Interfaces;
4-
using UserManagement.Application.User.Commands;
5-
using Xunit;
6-
7-
namespace UserManagement.ApplicationTests.User.Commands
1+
namespace UserManagement.ApplicationTests.User.Commands
82
{
3+
using Shouldly;
4+
using System.Linq;
5+
using UserManagement.Application.Common.Interfaces;
6+
using UserManagement.Application.User.Commands;
7+
using Xunit;
8+
99
[Collection("UserCollection")]
1010
public class UpdateUserCommandValidatorTest
1111
{
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
namespace UserManagement.Persistance.IntegrationTests.User
2+
{
3+
using Shouldly;
4+
using System;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using UserManagement.Domain.Repositories;
8+
using Xunit;
9+
10+
[Collection("UserCollection")]
11+
public class UserRepositoryTest : IDisposable
12+
{
13+
private readonly IUserRepository userRepository;
14+
public UserRepositoryTest(UserFixture fixture)
15+
{
16+
userRepository = fixture.UserRepository;
17+
}
18+
19+
[Fact]
20+
public async Task TestAddUser_GivenCorrectParam_ReturnUserID()
21+
{
22+
var res = await AddNewUser();
23+
res.ShouldBeGreaterThan(0);
24+
}
25+
26+
[Fact]
27+
public async Task TestGetAllUsers_GivenCorrectParam_ReturnUserList()
28+
{
29+
await AddNewUser();
30+
var res = await userRepository.GetAllUsers();
31+
res.Count().ShouldBeGreaterThan(0);
32+
}
33+
34+
[Fact]
35+
public async Task TestGetUserByID_GivenCorrectParam_ReturnUserList()
36+
{
37+
var userId = await AddNewUser();
38+
var res = await userRepository.GetUser(userId);
39+
res.ShouldBeOfType<Domain.Entities.User>();
40+
}
41+
42+
43+
[Fact]
44+
public async Task TestUpdateUser_GivenCorrectParam_ReturnTrue()
45+
{
46+
var userId = AddNewUser().Result;
47+
var user = new Domain.Entities.User
48+
{
49+
FirstName = "John",
50+
LastName = "Doe",
51+
City = "Falls Chruch",
52+
Country = "USA",
53+
State = "VA",
54+
Zip = "22044",
55+
DateAdded = new DateTime(2019, 01, 01),
56+
DOB = new DateTime(1980, 01, 01),
57+
EmailAddress = "[email protected]",
58+
Gender = "F",
59+
PhoneNumber = "000-000-000",
60+
UserID = userId,
61+
};
62+
63+
var res = await userRepository.UpdateUser(user);
64+
res.ShouldBeTrue();
65+
}
66+
67+
[Fact]
68+
public async Task TestDeleteUser_GivenCorrectParam_ReturnTrue()
69+
{
70+
var userId = AddNewUser().Result;
71+
var res = await userRepository.DeleteUser(userId);
72+
res.ShouldBeTrue();
73+
}
74+
75+
private async Task<int> AddNewUser()
76+
{
77+
var user = new Domain.Entities.User
78+
{
79+
FirstName = "John",
80+
LastName = "Doe",
81+
City = "Falls Chruch",
82+
Country = "USA",
83+
State = "VA",
84+
Zip = "22044",
85+
DateAdded = new DateTime(2019, 01, 01),
86+
DOB = new DateTime(1980, 01, 01),
87+
EmailAddress = "[email protected]",
88+
Gender = "M",
89+
PhoneNumber = "444-443-4444"
90+
};
91+
92+
return await userRepository.AddUser(user);
93+
}
94+
95+
public void Dispose()
96+
{
97+
userRepository.DeleteAllUser();
98+
}
99+
}
100+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace UserManagement.Persistance.IntegrationTests
2+
{
3+
using System.Data;
4+
using System.Data.SqlClient;
5+
using UserManagement.Domain.Repositories;
6+
using UserManagement.Persistence.Repositories;
7+
using Xunit;
8+
public class UserFixture
9+
{
10+
public IUserRepository UserRepository { get; }
11+
12+
public UserFixture()
13+
{
14+
IDbConnection dbConnection = new SqlConnection("Data Source=localhost\\SQLEXPRESS;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=TestFullstackHub");
15+
UserRepository = new UserRepository(dbConnection, null);
16+
}
17+
18+
[CollectionDefinition("UserCollection")]
19+
public class QueryCollection : ICollectionFixture<UserFixture>
20+
{
21+
}
22+
}
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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="MSTest.TestAdapter" Version="2.1.1" />
12+
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
13+
<PackageReference Include="coverlet.collector" Version="1.3.0" />
14+
<PackageReference Include="Shouldly" Version="3.0.2" />
15+
<PackageReference Include="System.Data.Common" Version="4.3.0" />
16+
<PackageReference Include="xunit" Version="2.4.1" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\UserManagement.Domain\UserManagement.Domain.csproj" />
25+
<ProjectReference Include="..\UserManagement.Persistence\UserManagement.Persistence.csproj" />
26+
</ItemGroup>
27+
28+
</Project>

UserManagement.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserManagement.Domain", "Us
1515
EndProject
1616
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserManagement.Persistence", "UserManagement.Persistence\UserManagement.Persistence.csproj", "{45C639CE-ED7B-4050-A71E-BB24DBDFE3AB}"
1717
EndProject
18-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManagement.Application.UnitTests", "UserManagement.Application.UnitTests\UserManagement.Application.UnitTests.csproj", "{4D0889FC-829F-4A29-8DE5-4051DDF0ED8B}"
18+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserManagement.Application.UnitTests", "UserManagement.Application.UnitTests\UserManagement.Application.UnitTests.csproj", "{4D0889FC-829F-4A29-8DE5-4051DDF0ED8B}"
19+
EndProject
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManagement.Persistence.IntegrationTests", "UserManagement.Persistence.IntegrationTests\UserManagement.Persistence.IntegrationTests.csproj", "{6FDA919F-2367-47DF-A308-29115F84F9FF}"
1921
EndProject
2022
Global
2123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -43,6 +45,10 @@ Global
4345
{4D0889FC-829F-4A29-8DE5-4051DDF0ED8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
4446
{4D0889FC-829F-4A29-8DE5-4051DDF0ED8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
4547
{4D0889FC-829F-4A29-8DE5-4051DDF0ED8B}.Release|Any CPU.Build.0 = Release|Any CPU
48+
{6FDA919F-2367-47DF-A308-29115F84F9FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49+
{6FDA919F-2367-47DF-A308-29115F84F9FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
50+
{6FDA919F-2367-47DF-A308-29115F84F9FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
51+
{6FDA919F-2367-47DF-A308-29115F84F9FF}.Release|Any CPU.Build.0 = Release|Any CPU
4652
EndGlobalSection
4753
GlobalSection(SolutionProperties) = preSolution
4854
HideSolutionNode = FALSE
@@ -53,6 +59,7 @@ Global
5359
{6650FED4-AB07-4916-8D46-04DBE78DBF6B} = {B9047929-76B2-4949-97FA-ABBA6A0F08FF}
5460
{45C639CE-ED7B-4050-A71E-BB24DBDFE3AB} = {B9047929-76B2-4949-97FA-ABBA6A0F08FF}
5561
{4D0889FC-829F-4A29-8DE5-4051DDF0ED8B} = {3CCCA724-B32F-4922-AAFF-933ABA3FBAE3}
62+
{6FDA919F-2367-47DF-A308-29115F84F9FF} = {3CCCA724-B32F-4922-AAFF-933ABA3FBAE3}
5663
EndGlobalSection
5764
GlobalSection(ExtensibilityGlobals) = postSolution
5865
SolutionGuid = {EEF049B4-7F13-4856-8723-E74D7812EB83}

0 commit comments

Comments
 (0)