Revize 866bd55c
Přidáno uživatelem Milan Hotovec před téměř 4 roky(ů)
Leuze.Tests.Modules.Goal/GoalDefinitionAreasTests.cs | ||
---|---|---|
1 |
//#define TEST |
|
2 |
|
|
3 |
using System; |
|
4 |
using System.Threading; |
|
5 |
using System.Threading.Tasks; |
|
6 |
using FluentAssertions; |
|
7 |
using Leuze.Core.Application.Authentication; |
|
8 |
using Leuze.Core.Domain.Repositories; |
|
9 |
using Leuze.Core.Infrastructure.Persistence.Repository; |
|
10 |
using Leuze.Core.Infrastructure.Persistence.Seeds; |
|
11 |
using Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Commands; |
|
12 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
13 |
using Leuze.Modules.Goal.Infrastructure.Persistence.Repositories; |
|
14 |
using Leuze.Tests.Configuration; |
|
15 |
using Microsoft.AspNetCore.Components.Authorization; |
|
16 |
using Microsoft.Extensions.DependencyInjection; |
|
17 |
using Moq; |
|
18 |
using Xunit; |
|
19 |
|
|
20 |
namespace Leuze.Tests.Modules.Goal |
|
21 |
{ |
|
22 |
[Trait("Category", "Goals")] |
|
23 |
public class GoalDefinitionAreasTests : TestWithDatabase |
|
24 |
{ |
|
25 |
public GoalDefinitionAreasTests() |
|
26 |
{ |
|
27 |
var services = new ServiceCollection(); |
|
28 |
services.AddTransient<IGlobalDefinitionAreaRepository, GlobalDefinitionAreaRepository>(); |
|
29 |
services.AddTransient<IGoalItemRepository, GoalItemRepository>(); |
|
30 |
services.AddTransient<IGoalDefinitionRepository, GoalDefinitionRepository>(); |
|
31 |
services.AddTransient<IDomainUserRepository, DomainUserRepository>(); |
|
32 |
Initialize(services); |
|
33 |
|
|
34 |
|
|
35 |
DatabaseFixture.Storage.Database.EnsureDeleted(); |
|
36 |
ApplicationSeed.Run(DatabaseFixture.Storage, DatabaseFixture.UserManager, DatabaseFixture.RoleManager); |
|
37 |
} |
|
38 |
|
|
39 |
[Fact] |
|
40 |
public async void CreateNewAreaTestAdmin() |
|
41 |
{ |
|
42 |
await _semaphore.WaitAsync(); |
|
43 |
|
|
44 |
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture,TestUtils.adminName); |
|
45 |
var handler = new CreateNewArea.Handler( |
|
46 |
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(), |
|
47 |
AuthenticationStateProviderMock.Object, |
|
48 |
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>()); |
|
49 |
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default); |
|
50 |
|
|
51 |
result.IsSuccess.Should().BeTrue(); |
|
52 |
|
|
53 |
_semaphore.Release(); |
|
54 |
} |
|
55 |
|
|
56 |
|
|
57 |
[Fact] |
|
58 |
public async void CreateNewAreaTestTL() |
|
59 |
{ |
|
60 |
await _semaphore.WaitAsync(); |
|
61 |
|
|
62 |
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.TLName); |
|
63 |
var handler = new CreateNewArea.Handler( |
|
64 |
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(), |
|
65 |
AuthenticationStateProviderMock.Object, |
|
66 |
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>()); |
|
67 |
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default); |
|
68 |
|
|
69 |
result.IsSuccess.Should().BeTrue(); |
|
70 |
|
|
71 |
_semaphore.Release(); |
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
[Fact] |
|
76 |
public async void CreateNewAreaTestMA() |
|
77 |
{ |
|
78 |
await _semaphore.WaitAsync(); |
|
79 |
|
|
80 |
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.MAName); |
|
81 |
var handler = new CreateNewArea.Handler( |
|
82 |
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(), |
|
83 |
AuthenticationStateProviderMock.Object, |
|
84 |
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>()); |
|
85 |
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default); |
|
86 |
|
|
87 |
result.IsSuccess.Should().BeTrue(); |
|
88 |
|
|
89 |
_semaphore.Release(); |
|
90 |
} |
|
91 |
|
|
92 |
[Fact] |
|
93 |
public async void CreateNewAreaTestOverlap() |
|
94 |
{ |
|
95 |
await _semaphore.WaitAsync(); |
|
96 |
|
|
97 |
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.TLName); |
|
98 |
var handler = new CreateNewArea.Handler( |
|
99 |
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(), |
|
100 |
AuthenticationStateProviderMock.Object, |
|
101 |
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>()); |
|
102 |
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default); |
|
103 |
|
|
104 |
result.IsSuccess.Should().BeTrue(); |
|
105 |
|
|
106 |
result = await handler.Handle(new CreateNewArea.Command(DateTime.Today.AddDays(1), DateTime.Today.AddDays(2), 0.0), default); |
|
107 |
|
|
108 |
result.IsSuccess.Should().BeFalse(); |
|
109 |
|
|
110 |
_semaphore.Release(); |
|
111 |
} |
|
112 |
|
|
113 |
[Fact] |
|
114 |
public async void CreateNewAreaTestWrongRange() |
|
115 |
{ |
|
116 |
await _semaphore.WaitAsync(); |
|
117 |
|
|
118 |
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.MAName); |
|
119 |
var handler = new CreateNewArea.Handler( |
|
120 |
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(), |
|
121 |
AuthenticationStateProviderMock.Object, |
|
122 |
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>()); |
|
123 |
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today.AddDays(1), DateTime.Today, 0.0), default); |
|
124 |
|
|
125 |
result.IsSuccess.Should().BeFalse(); |
|
126 |
|
|
127 |
_semaphore.Release(); |
|
128 |
} |
|
129 |
} |
|
130 |
} |
Leuze.Tests.Modules.Goal/GoalDefinitionsTests.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
4 |
|
|
5 |
namespace Leuze.Tests.Modules.Goal |
|
6 |
{ |
|
7 |
class GoalDefinitionsTests |
|
8 |
{ |
|
9 |
} |
|
10 |
} |
Leuze.Tests.Modules.Goal/GoalsTests.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
4 |
|
|
5 |
namespace Leuze.Tests.Modules.Goal |
|
6 |
{ |
|
7 |
class GoalsTests |
|
8 |
{ |
|
9 |
} |
|
10 |
} |
Leuze.Tests.Modules.Goal/Leuze.Tests.Modules.Goal.csproj | ||
---|---|---|
1 |
<Project Sdk="Microsoft.NET.Sdk"> |
|
2 |
|
|
3 |
<PropertyGroup> |
|
4 |
<TargetFramework>net5.0</TargetFramework> |
|
5 |
|
|
6 |
<IsPackable>false</IsPackable> |
|
7 |
<DefineConstants>TEST</DefineConstants> |
|
8 |
<Configurations>Debug;Release;Test</Configurations> |
|
9 |
</PropertyGroup> |
|
10 |
|
|
11 |
<ItemGroup> |
|
12 |
<PackageReference Include="FluentAssertions" Version="5.10.3" /> |
|
13 |
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" /> |
|
14 |
<PackageReference Include="Moq" Version="4.16.1" /> |
|
15 |
<PackageReference Include="xunit" Version="2.4.1" /> |
|
16 |
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> |
|
17 |
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
|
18 |
<PrivateAssets>all</PrivateAssets> |
|
19 |
</PackageReference> |
|
20 |
<PackageReference Include="coverlet.collector" Version="3.0.3"> |
|
21 |
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
|
22 |
<PrivateAssets>all</PrivateAssets> |
|
23 |
</PackageReference> |
|
24 |
</ItemGroup> |
|
25 |
|
|
26 |
<ItemGroup> |
|
27 |
<ProjectReference Include="..\src\Modules\Goal\Application\Leuze.Modules.Goal.Application\Leuze.Modules.Goal.Application.csproj" /> |
|
28 |
<ProjectReference Include="..\src\Modules\Goal\Infrastructure\Leuze.Modules.Goal.Infrastructure.Persistence\Leuze.Modules.Goal.Infrastructure.Persistence.csproj" /> |
|
29 |
<ProjectReference Include="..\tests\Leuze.Tests.Configuration\Leuze.Tests.Configuration.csproj" /> |
|
30 |
</ItemGroup> |
|
31 |
|
|
32 |
</Project> |
Leuze.Tests.Modules.Goal/TestUtils.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
using FluentAssertions; |
|
7 |
using Leuze.Core.Application.Authentication; |
|
8 |
using Leuze.Tests.Configuration; |
|
9 |
using Microsoft.AspNetCore.Components.Authorization; |
|
10 |
using Moq; |
|
11 |
|
|
12 |
namespace Leuze.Tests.Modules.Goal |
|
13 |
{ |
|
14 |
public static class TestUtils |
|
15 |
{ |
|
16 |
public const string adminName = "admin@test.cz"; |
|
17 |
public const string TLName = "silent@test.cz"; |
|
18 |
public const string MAName = "orlicek@test.cz"; |
|
19 |
|
|
20 |
public static async Task<Mock<AuthenticatedUserProvider>> AuthenticationMock(DatabaseInMemoryFixture DatabaseFixture, string username) |
|
21 |
{ |
|
22 |
var user = await DatabaseFixture.UserManager.FindByEmailAsync(username); |
|
23 |
(user != null).Should().BeTrue(); |
|
24 |
|
|
25 |
var AuthenticationStateProviderMock = new Mock<AuthenticatedUserProvider>(Mock.Of<AuthenticationStateProvider>()); |
|
26 |
AuthenticationStateProviderMock.Setup(e => e.RequiredUserId).Returns(user.Id); |
|
27 |
return AuthenticationStateProviderMock; |
|
28 |
} |
|
29 |
} |
|
30 |
} |
Leuze.sln | ||
---|---|---|
55 | 55 |
EndProject |
56 | 56 |
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Goals", "Goals", "{B89031F6-163B-417B-B90E-2DC90A30E7A1}" |
57 | 57 |
EndProject |
58 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Leuze.Tests.Modules.Goal", "Leuze.Tests.Modules.Goal\Leuze.Tests.Modules.Goal.csproj", "{2824A507-5BBD-44B7-9F3A-643F29C7E597}"
|
|
58 |
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Leuze.Tests.Modules.Goal", "tests\Goals\Leuze.Tests.Modules.Goal\Leuze.Tests.Modules.Goal.csproj", "{885D5C4E-2C97-4F8B-97BF-16D2A28BDE4D}"
|
|
59 | 59 |
EndProject |
60 | 60 |
Global |
61 | 61 |
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
62 | 62 |
Debug|Any CPU = Debug|Any CPU |
63 | 63 |
Release|Any CPU = Release|Any CPU |
64 |
Test|Any CPU = Test|Any CPU |
|
64 | 65 |
EndGlobalSection |
65 | 66 |
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
66 | 67 |
{B316B6E4-2898-4F23-9D96-97A90F41BFDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
67 | 68 |
{B316B6E4-2898-4F23-9D96-97A90F41BFDC}.Debug|Any CPU.Build.0 = Debug|Any CPU |
68 | 69 |
{B316B6E4-2898-4F23-9D96-97A90F41BFDC}.Release|Any CPU.ActiveCfg = Release|Any CPU |
69 | 70 |
{B316B6E4-2898-4F23-9D96-97A90F41BFDC}.Release|Any CPU.Build.0 = Release|Any CPU |
71 |
{B316B6E4-2898-4F23-9D96-97A90F41BFDC}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
72 |
{B316B6E4-2898-4F23-9D96-97A90F41BFDC}.Test|Any CPU.Build.0 = Test|Any CPU |
|
70 | 73 |
{66EEF1C2-9476-4FF6-86F7-2C1035C7DC66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
71 | 74 |
{66EEF1C2-9476-4FF6-86F7-2C1035C7DC66}.Debug|Any CPU.Build.0 = Debug|Any CPU |
72 | 75 |
{66EEF1C2-9476-4FF6-86F7-2C1035C7DC66}.Release|Any CPU.ActiveCfg = Release|Any CPU |
73 | 76 |
{66EEF1C2-9476-4FF6-86F7-2C1035C7DC66}.Release|Any CPU.Build.0 = Release|Any CPU |
77 |
{66EEF1C2-9476-4FF6-86F7-2C1035C7DC66}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
78 |
{66EEF1C2-9476-4FF6-86F7-2C1035C7DC66}.Test|Any CPU.Build.0 = Test|Any CPU |
|
74 | 79 |
{D4908C8E-6488-457B-B045-4D769D9ACA76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
75 | 80 |
{D4908C8E-6488-457B-B045-4D769D9ACA76}.Debug|Any CPU.Build.0 = Debug|Any CPU |
76 | 81 |
{D4908C8E-6488-457B-B045-4D769D9ACA76}.Release|Any CPU.ActiveCfg = Release|Any CPU |
77 | 82 |
{D4908C8E-6488-457B-B045-4D769D9ACA76}.Release|Any CPU.Build.0 = Release|Any CPU |
83 |
{D4908C8E-6488-457B-B045-4D769D9ACA76}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
84 |
{D4908C8E-6488-457B-B045-4D769D9ACA76}.Test|Any CPU.Build.0 = Test|Any CPU |
|
78 | 85 |
{B443BE7B-7A75-4BAE-872B-85C13D528C3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
79 | 86 |
{B443BE7B-7A75-4BAE-872B-85C13D528C3C}.Debug|Any CPU.Build.0 = Debug|Any CPU |
80 | 87 |
{B443BE7B-7A75-4BAE-872B-85C13D528C3C}.Release|Any CPU.ActiveCfg = Release|Any CPU |
81 | 88 |
{B443BE7B-7A75-4BAE-872B-85C13D528C3C}.Release|Any CPU.Build.0 = Release|Any CPU |
89 |
{B443BE7B-7A75-4BAE-872B-85C13D528C3C}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
90 |
{B443BE7B-7A75-4BAE-872B-85C13D528C3C}.Test|Any CPU.Build.0 = Test|Any CPU |
|
82 | 91 |
{3926F2A1-547E-48E4-B87F-29C21E7FC625}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
83 | 92 |
{3926F2A1-547E-48E4-B87F-29C21E7FC625}.Debug|Any CPU.Build.0 = Debug|Any CPU |
84 | 93 |
{3926F2A1-547E-48E4-B87F-29C21E7FC625}.Release|Any CPU.ActiveCfg = Release|Any CPU |
85 | 94 |
{3926F2A1-547E-48E4-B87F-29C21E7FC625}.Release|Any CPU.Build.0 = Release|Any CPU |
95 |
{3926F2A1-547E-48E4-B87F-29C21E7FC625}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
96 |
{3926F2A1-547E-48E4-B87F-29C21E7FC625}.Test|Any CPU.Build.0 = Test|Any CPU |
|
86 | 97 |
{674168B3-2D4C-4746-A1A7-FE890BD59C1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
87 | 98 |
{674168B3-2D4C-4746-A1A7-FE890BD59C1A}.Debug|Any CPU.Build.0 = Debug|Any CPU |
88 | 99 |
{674168B3-2D4C-4746-A1A7-FE890BD59C1A}.Release|Any CPU.ActiveCfg = Release|Any CPU |
89 | 100 |
{674168B3-2D4C-4746-A1A7-FE890BD59C1A}.Release|Any CPU.Build.0 = Release|Any CPU |
101 |
{674168B3-2D4C-4746-A1A7-FE890BD59C1A}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
102 |
{674168B3-2D4C-4746-A1A7-FE890BD59C1A}.Test|Any CPU.Build.0 = Test|Any CPU |
|
90 | 103 |
{D037B7D3-CA28-4EBD-9E2F-3F3D347950CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
91 | 104 |
{D037B7D3-CA28-4EBD-9E2F-3F3D347950CF}.Debug|Any CPU.Build.0 = Debug|Any CPU |
92 | 105 |
{D037B7D3-CA28-4EBD-9E2F-3F3D347950CF}.Release|Any CPU.ActiveCfg = Release|Any CPU |
93 | 106 |
{D037B7D3-CA28-4EBD-9E2F-3F3D347950CF}.Release|Any CPU.Build.0 = Release|Any CPU |
107 |
{D037B7D3-CA28-4EBD-9E2F-3F3D347950CF}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
108 |
{D037B7D3-CA28-4EBD-9E2F-3F3D347950CF}.Test|Any CPU.Build.0 = Test|Any CPU |
|
94 | 109 |
{8ECAEA01-61F3-402D-B94E-E54FC0C94C8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
95 | 110 |
{8ECAEA01-61F3-402D-B94E-E54FC0C94C8E}.Debug|Any CPU.Build.0 = Debug|Any CPU |
96 | 111 |
{8ECAEA01-61F3-402D-B94E-E54FC0C94C8E}.Release|Any CPU.ActiveCfg = Release|Any CPU |
97 | 112 |
{8ECAEA01-61F3-402D-B94E-E54FC0C94C8E}.Release|Any CPU.Build.0 = Release|Any CPU |
113 |
{8ECAEA01-61F3-402D-B94E-E54FC0C94C8E}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
114 |
{8ECAEA01-61F3-402D-B94E-E54FC0C94C8E}.Test|Any CPU.Build.0 = Test|Any CPU |
|
98 | 115 |
{D271989D-921D-486B-929C-6BBF1EC0EED4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
99 | 116 |
{D271989D-921D-486B-929C-6BBF1EC0EED4}.Debug|Any CPU.Build.0 = Debug|Any CPU |
100 | 117 |
{D271989D-921D-486B-929C-6BBF1EC0EED4}.Release|Any CPU.ActiveCfg = Release|Any CPU |
101 | 118 |
{D271989D-921D-486B-929C-6BBF1EC0EED4}.Release|Any CPU.Build.0 = Release|Any CPU |
119 |
{D271989D-921D-486B-929C-6BBF1EC0EED4}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
120 |
{D271989D-921D-486B-929C-6BBF1EC0EED4}.Test|Any CPU.Build.0 = Test|Any CPU |
|
102 | 121 |
{C49CA0F7-C0C2-4FCE-98C4-4E42765B4405}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
103 | 122 |
{C49CA0F7-C0C2-4FCE-98C4-4E42765B4405}.Debug|Any CPU.Build.0 = Debug|Any CPU |
104 | 123 |
{C49CA0F7-C0C2-4FCE-98C4-4E42765B4405}.Release|Any CPU.ActiveCfg = Release|Any CPU |
105 | 124 |
{C49CA0F7-C0C2-4FCE-98C4-4E42765B4405}.Release|Any CPU.Build.0 = Release|Any CPU |
125 |
{C49CA0F7-C0C2-4FCE-98C4-4E42765B4405}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
126 |
{C49CA0F7-C0C2-4FCE-98C4-4E42765B4405}.Test|Any CPU.Build.0 = Test|Any CPU |
|
106 | 127 |
{C6F9EFF2-30DA-4FA9-AEFF-4957F0260267}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
107 | 128 |
{C6F9EFF2-30DA-4FA9-AEFF-4957F0260267}.Debug|Any CPU.Build.0 = Debug|Any CPU |
108 | 129 |
{C6F9EFF2-30DA-4FA9-AEFF-4957F0260267}.Release|Any CPU.ActiveCfg = Release|Any CPU |
109 | 130 |
{C6F9EFF2-30DA-4FA9-AEFF-4957F0260267}.Release|Any CPU.Build.0 = Release|Any CPU |
131 |
{C6F9EFF2-30DA-4FA9-AEFF-4957F0260267}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
132 |
{C6F9EFF2-30DA-4FA9-AEFF-4957F0260267}.Test|Any CPU.Build.0 = Test|Any CPU |
|
110 | 133 |
{BAAC1AB6-C671-408C-94EF-96459D5403DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
111 | 134 |
{BAAC1AB6-C671-408C-94EF-96459D5403DD}.Debug|Any CPU.Build.0 = Debug|Any CPU |
112 | 135 |
{BAAC1AB6-C671-408C-94EF-96459D5403DD}.Release|Any CPU.ActiveCfg = Release|Any CPU |
113 | 136 |
{BAAC1AB6-C671-408C-94EF-96459D5403DD}.Release|Any CPU.Build.0 = Release|Any CPU |
137 |
{BAAC1AB6-C671-408C-94EF-96459D5403DD}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
138 |
{BAAC1AB6-C671-408C-94EF-96459D5403DD}.Test|Any CPU.Build.0 = Test|Any CPU |
|
114 | 139 |
{BEBFBA58-BCB7-4F44-9247-EAAAE748176A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
115 | 140 |
{BEBFBA58-BCB7-4F44-9247-EAAAE748176A}.Debug|Any CPU.Build.0 = Debug|Any CPU |
116 | 141 |
{BEBFBA58-BCB7-4F44-9247-EAAAE748176A}.Release|Any CPU.ActiveCfg = Release|Any CPU |
117 | 142 |
{BEBFBA58-BCB7-4F44-9247-EAAAE748176A}.Release|Any CPU.Build.0 = Release|Any CPU |
118 |
{2824A507-5BBD-44B7-9F3A-643F29C7E597}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|
119 |
{2824A507-5BBD-44B7-9F3A-643F29C7E597}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|
120 |
{2824A507-5BBD-44B7-9F3A-643F29C7E597}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|
121 |
{2824A507-5BBD-44B7-9F3A-643F29C7E597}.Release|Any CPU.Build.0 = Release|Any CPU |
|
143 |
{BEBFBA58-BCB7-4F44-9247-EAAAE748176A}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
144 |
{BEBFBA58-BCB7-4F44-9247-EAAAE748176A}.Test|Any CPU.Build.0 = Test|Any CPU |
|
145 |
{885D5C4E-2C97-4F8B-97BF-16D2A28BDE4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|
146 |
{885D5C4E-2C97-4F8B-97BF-16D2A28BDE4D}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|
147 |
{885D5C4E-2C97-4F8B-97BF-16D2A28BDE4D}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|
148 |
{885D5C4E-2C97-4F8B-97BF-16D2A28BDE4D}.Release|Any CPU.Build.0 = Release|Any CPU |
|
149 |
{885D5C4E-2C97-4F8B-97BF-16D2A28BDE4D}.Test|Any CPU.ActiveCfg = Test|Any CPU |
|
150 |
{885D5C4E-2C97-4F8B-97BF-16D2A28BDE4D}.Test|Any CPU.Build.0 = Test|Any CPU |
|
122 | 151 |
EndGlobalSection |
123 | 152 |
GlobalSection(SolutionProperties) = preSolution |
124 | 153 |
HideSolutionNode = FALSE |
... | ... | |
146 | 175 |
{BAAC1AB6-C671-408C-94EF-96459D5403DD} = {4A441C7D-2659-4FB5-8886-420728C229BF} |
147 | 176 |
{BEBFBA58-BCB7-4F44-9247-EAAAE748176A} = {E4134FEF-ECBC-4EEF-A65B-8E8D318DA8DA} |
148 | 177 |
{B89031F6-163B-417B-B90E-2DC90A30E7A1} = {C5588326-929D-42B3-912B-9D838373B48E} |
149 |
{2824A507-5BBD-44B7-9F3A-643F29C7E597} = {B89031F6-163B-417B-B90E-2DC90A30E7A1}
|
|
178 |
{885D5C4E-2C97-4F8B-97BF-16D2A28BDE4D} = {B89031F6-163B-417B-B90E-2DC90A30E7A1}
|
|
150 | 179 |
EndGlobalSection |
151 | 180 |
GlobalSection(ExtensibilityGlobals) = postSolution |
152 | 181 |
SolutionGuid = {849C3668-1CB9-4F98-ADFA-A71F5629384C} |
src/Core/Application/Leuze.Core.Application.UI/Properties/launchSettings.json | ||
---|---|---|
3 | 3 |
"windowsAuthentication": false, |
4 | 4 |
"anonymousAuthentication": true, |
5 | 5 |
"iisExpress": { |
6 |
"applicationUrl": "http://localhost:57867/",
|
|
7 |
"sslPort": 44379
|
|
6 |
"applicationUrl": "http://localhost:54304/",
|
|
7 |
"sslPort": 44336
|
|
8 | 8 |
} |
9 | 9 |
}, |
10 | 10 |
"profiles": { |
tests/Goals/Leuze.Tests.Modules.Goal/GoalDefinitionAreasTests.cs | ||
---|---|---|
1 |
//#define TEST |
|
2 |
|
|
3 |
using System; |
|
4 |
using System.Threading; |
|
5 |
using System.Threading.Tasks; |
|
6 |
using FluentAssertions; |
|
7 |
using Leuze.Core.Application.Authentication; |
|
8 |
using Leuze.Core.Domain.Repositories; |
|
9 |
using Leuze.Core.Infrastructure.Persistence.Repository; |
|
10 |
using Leuze.Core.Infrastructure.Persistence.Seeds; |
|
11 |
using Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Commands; |
|
12 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
13 |
using Leuze.Modules.Goal.Infrastructure.Persistence.Repositories; |
|
14 |
using Leuze.Tests.Configuration; |
|
15 |
using Microsoft.AspNetCore.Components.Authorization; |
|
16 |
using Microsoft.Extensions.DependencyInjection; |
|
17 |
using Moq; |
|
18 |
using Xunit; |
|
19 |
|
|
20 |
namespace Leuze.Tests.Modules.Goal |
|
21 |
{ |
|
22 |
[Trait("Category", "Goals")] |
|
23 |
public class GoalDefinitionAreasTests : TestWithDatabase |
|
24 |
{ |
|
25 |
public GoalDefinitionAreasTests() |
|
26 |
{ |
|
27 |
var services = new ServiceCollection(); |
|
28 |
services.AddTransient<IGlobalDefinitionAreaRepository, GlobalDefinitionAreaRepository>(); |
|
29 |
services.AddTransient<IGoalItemRepository, GoalItemRepository>(); |
|
30 |
services.AddTransient<IGoalDefinitionRepository, GoalDefinitionRepository>(); |
|
31 |
services.AddTransient<IDomainUserRepository, DomainUserRepository>(); |
|
32 |
Initialize(services); |
|
33 |
|
|
34 |
|
|
35 |
DatabaseFixture.Storage.Database.EnsureDeleted(); |
|
36 |
ApplicationSeed.Run(DatabaseFixture.Storage, DatabaseFixture.UserManager, DatabaseFixture.RoleManager); |
|
37 |
} |
|
38 |
|
|
39 |
[Fact] |
|
40 |
public async void CreateNewAreaTestAdmin() |
|
41 |
{ |
|
42 |
await _semaphore.WaitAsync(); |
|
43 |
|
|
44 |
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture,TestUtils.adminName); |
|
45 |
var handler = new CreateNewArea.Handler( |
|
46 |
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(), |
|
47 |
AuthenticationStateProviderMock.Object, |
|
48 |
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>()); |
|
49 |
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default); |
|
50 |
|
|
51 |
result.IsSuccess.Should().BeTrue(); |
|
52 |
|
|
53 |
_semaphore.Release(); |
|
54 |
} |
|
55 |
|
|
56 |
|
|
57 |
[Fact] |
|
58 |
public async void CreateNewAreaTestTL() |
|
59 |
{ |
|
60 |
await _semaphore.WaitAsync(); |
|
61 |
|
|
62 |
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.TLName); |
|
63 |
var handler = new CreateNewArea.Handler( |
|
64 |
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(), |
|
65 |
AuthenticationStateProviderMock.Object, |
|
66 |
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>()); |
|
67 |
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default); |
|
68 |
|
|
69 |
result.IsSuccess.Should().BeTrue(); |
|
70 |
|
|
71 |
_semaphore.Release(); |
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
[Fact] |
|
76 |
public async void CreateNewAreaTestMA() |
|
77 |
{ |
|
78 |
await _semaphore.WaitAsync(); |
|
79 |
|
|
80 |
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.MAName); |
|
81 |
var handler = new CreateNewArea.Handler( |
|
82 |
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(), |
|
83 |
AuthenticationStateProviderMock.Object, |
|
84 |
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>()); |
|
85 |
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default); |
|
86 |
|
|
87 |
result.IsSuccess.Should().BeTrue(); |
|
88 |
|
|
89 |
_semaphore.Release(); |
|
90 |
} |
|
91 |
|
|
92 |
[Fact] |
|
93 |
public async void CreateNewAreaTestOverlap() |
|
94 |
{ |
|
95 |
await _semaphore.WaitAsync(); |
|
96 |
|
|
97 |
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.TLName); |
|
98 |
var handler = new CreateNewArea.Handler( |
|
99 |
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(), |
|
100 |
AuthenticationStateProviderMock.Object, |
|
101 |
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>()); |
|
102 |
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default); |
|
103 |
|
|
104 |
result.IsSuccess.Should().BeTrue(); |
|
105 |
|
|
106 |
result = await handler.Handle(new CreateNewArea.Command(DateTime.Today.AddDays(1), DateTime.Today.AddDays(2), 0.0), default); |
|
107 |
|
|
108 |
result.IsSuccess.Should().BeFalse(); |
|
109 |
|
|
110 |
_semaphore.Release(); |
|
111 |
} |
|
112 |
|
|
113 |
[Fact] |
|
114 |
public async void CreateNewAreaTestWrongRange() |
|
115 |
{ |
|
116 |
await _semaphore.WaitAsync(); |
|
117 |
|
|
118 |
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.MAName); |
|
119 |
var handler = new CreateNewArea.Handler( |
|
120 |
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(), |
|
121 |
AuthenticationStateProviderMock.Object, |
|
122 |
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>()); |
|
123 |
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today.AddDays(1), DateTime.Today, 0.0), default); |
|
124 |
|
|
125 |
result.IsSuccess.Should().BeFalse(); |
|
126 |
|
|
127 |
_semaphore.Release(); |
|
128 |
} |
|
129 |
} |
|
130 |
} |
tests/Goals/Leuze.Tests.Modules.Goal/GoalDefinitionsTests.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
4 |
|
|
5 |
namespace Leuze.Tests.Modules.Goal |
|
6 |
{ |
|
7 |
class GoalDefinitionsTests |
|
8 |
{ |
|
9 |
} |
|
10 |
} |
tests/Goals/Leuze.Tests.Modules.Goal/GoalsTests.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
4 |
|
|
5 |
namespace Leuze.Tests.Modules.Goal |
|
6 |
{ |
|
7 |
class GoalsTests |
|
8 |
{ |
|
9 |
} |
|
10 |
} |
tests/Goals/Leuze.Tests.Modules.Goal/Leuze.Tests.Modules.Goal.csproj | ||
---|---|---|
1 |
<Project Sdk="Microsoft.NET.Sdk"> |
|
2 |
|
|
3 |
<PropertyGroup> |
|
4 |
<TargetFramework>net5.0</TargetFramework> |
|
5 |
|
|
6 |
<IsPackable>false</IsPackable> |
|
7 |
<DefineConstants>TEST</DefineConstants> |
|
8 |
<Configurations>Debug;Release;Test</Configurations> |
|
9 |
</PropertyGroup> |
|
10 |
|
|
11 |
<ItemGroup> |
|
12 |
<PackageReference Include="FluentAssertions" Version="5.10.3" /> |
|
13 |
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" /> |
|
14 |
<PackageReference Include="Moq" Version="4.16.1" /> |
|
15 |
<PackageReference Include="xunit" Version="2.4.1" /> |
|
16 |
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> |
|
17 |
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
|
18 |
<PrivateAssets>all</PrivateAssets> |
|
19 |
</PackageReference> |
|
20 |
<PackageReference Include="coverlet.collector" Version="3.0.3"> |
|
21 |
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
|
22 |
<PrivateAssets>all</PrivateAssets> |
|
23 |
</PackageReference> |
|
24 |
</ItemGroup> |
|
25 |
|
|
26 |
<ItemGroup> |
|
27 |
<ProjectReference Include="..\..\..\src\Modules\Goal\Application\Leuze.Modules.Goal.Application\Leuze.Modules.Goal.Application.csproj" /> |
|
28 |
<ProjectReference Include="..\..\..\src\Modules\Goal\Infrastructure\Leuze.Modules.Goal.Infrastructure.Persistence\Leuze.Modules.Goal.Infrastructure.Persistence.csproj" /> |
|
29 |
<ProjectReference Include="..\..\Leuze.Tests.Configuration\Leuze.Tests.Configuration.csproj" /> |
|
30 |
</ItemGroup> |
|
31 |
|
|
32 |
</Project> |
tests/Goals/Leuze.Tests.Modules.Goal/TestUtils.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
using FluentAssertions; |
|
7 |
using Leuze.Core.Application.Authentication; |
|
8 |
using Leuze.Tests.Configuration; |
|
9 |
using Microsoft.AspNetCore.Components.Authorization; |
|
10 |
using Moq; |
|
11 |
|
|
12 |
namespace Leuze.Tests.Modules.Goal |
|
13 |
{ |
|
14 |
public static class TestUtils |
|
15 |
{ |
|
16 |
public const string adminName = "admin@test.cz"; |
|
17 |
public const string TLName = "silent@test.cz"; |
|
18 |
public const string MAName = "orlicek@test.cz"; |
|
19 |
|
|
20 |
public static async Task<Mock<AuthenticatedUserProvider>> AuthenticationMock(DatabaseInMemoryFixture DatabaseFixture, string username) |
|
21 |
{ |
|
22 |
var user = await DatabaseFixture.UserManager.FindByEmailAsync(username); |
|
23 |
(user != null).Should().BeTrue(); |
|
24 |
|
|
25 |
var AuthenticationStateProviderMock = new Mock<AuthenticatedUserProvider>(Mock.Of<AuthenticationStateProvider>()); |
|
26 |
AuthenticationStateProviderMock.Setup(e => e.RequiredUserId).Returns(user.Id); |
|
27 |
return AuthenticationStateProviderMock; |
|
28 |
} |
|
29 |
} |
|
30 |
} |
Také k dispozici: Unified diff
Test location and paths fixed
@testFull