Projekt

Obecné

Profil

Stáhnout (5.34 KB) Statistiky
| Větev: | Tag: | Revize:
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
}
(1-1/5)