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
|
ApplicationSeed.Run(DatabaseFixture.Storage, DatabaseFixture.UserManager, DatabaseFixture.RoleManager);
|
35
|
}
|
36
|
|
37
|
[Fact]
|
38
|
public async void CreateNewAreaTestAdmin()
|
39
|
{
|
40
|
await _semaphore.WaitAsync();
|
41
|
|
42
|
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture,TestUtils.adminName);
|
43
|
var handler = new CreateNewArea.Handler(
|
44
|
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(),
|
45
|
AuthenticationStateProviderMock.Object,
|
46
|
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>());
|
47
|
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default);
|
48
|
|
49
|
result.IsSuccess.Should().BeTrue();
|
50
|
|
51
|
_semaphore.Release();
|
52
|
}
|
53
|
|
54
|
//TODO: change user
|
55
|
[Fact]
|
56
|
public async void CreateNewAreaTestTL()
|
57
|
{
|
58
|
await _semaphore.WaitAsync();
|
59
|
|
60
|
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.adminName);
|
61
|
var handler = new CreateNewArea.Handler(
|
62
|
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(),
|
63
|
AuthenticationStateProviderMock.Object,
|
64
|
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>());
|
65
|
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default);
|
66
|
|
67
|
result.IsSuccess.Should().BeTrue();
|
68
|
|
69
|
_semaphore.Release();
|
70
|
}
|
71
|
|
72
|
//TODO: change user
|
73
|
[Fact]
|
74
|
public async void CreateNewAreaTestMA()
|
75
|
{
|
76
|
await _semaphore.WaitAsync();
|
77
|
|
78
|
var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.adminName);
|
79
|
var handler = new CreateNewArea.Handler(
|
80
|
DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(),
|
81
|
AuthenticationStateProviderMock.Object,
|
82
|
DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>());
|
83
|
var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default);
|
84
|
|
85
|
result.IsSuccess.Should().BeTrue();
|
86
|
|
87
|
_semaphore.Release();
|
88
|
}
|
89
|
|
90
|
//private async Task<Mock<AuthenticatedUserProvider>> AuthenticationMock(string username)
|
91
|
//{
|
92
|
// var user = await DatabaseFixture.UserManager.FindByEmailAsync(username);
|
93
|
// (user != null).Should().BeTrue();
|
94
|
|
95
|
// var AuthenticationStateProviderMock = new Mock<AuthenticatedUserProvider>(Mock.Of<AuthenticationStateProvider>());
|
96
|
// AuthenticationStateProviderMock.Setup(e => e.RequiredUserId).Returns(user.Id);
|
97
|
// return AuthenticationStateProviderMock;
|
98
|
//}
|
99
|
}
|
100
|
}
|