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
            DatabaseFixture.Storage.Database.EnsureDeleted();
35
            ApplicationSeed.Run(DatabaseFixture.Storage, DatabaseFixture.UserManager, DatabaseFixture.RoleManager);
36
        }
37

    
38
        [Fact]
39
        public async void CreateNewAreaTestAdmin()
40
        {
41
            await _semaphore.WaitAsync();
42

    
43
            var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture,TestUtils.adminName);
44
            var handler = new CreateNewArea.Handler(
45
                DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(),
46
                AuthenticationStateProviderMock.Object,
47
                DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>());
48
            var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default);
49

    
50
            result.IsSuccess.Should().BeTrue();
51

    
52
            _semaphore.Release();
53
        }
54

    
55
        
56
        [Fact]
57
        public async void CreateNewAreaTestTL()
58
        {
59
            await _semaphore.WaitAsync();
60

    
61
            var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.TLName);
62
            var handler = new CreateNewArea.Handler(
63
                DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(),
64
                AuthenticationStateProviderMock.Object,
65
                DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>());
66
            var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default);
67

    
68
            result.IsSuccess.Should().BeTrue();
69

    
70
            _semaphore.Release();
71
        }
72

    
73
        
74
        [Fact]
75
        public async void CreateNewAreaTestMA()
76
        {
77
            await _semaphore.WaitAsync();
78

    
79
            var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.MAName);
80
            var handler = new CreateNewArea.Handler(
81
                DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(),
82
                AuthenticationStateProviderMock.Object,
83
                DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>());
84
            var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default);
85

    
86
            result.IsSuccess.Should().BeTrue();
87

    
88
            _semaphore.Release();
89
        }
90

    
91
        [Fact]
92
        public async void CreateNewAreaTestOverlap()
93
        {
94
            await _semaphore.WaitAsync();
95

    
96
            var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.TLName);
97
            var handler = new CreateNewArea.Handler(
98
                DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(),
99
                AuthenticationStateProviderMock.Object,
100
                DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>());
101
            var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today, DateTime.Today.AddDays(1), 0.0), default);
102

    
103
            result.IsSuccess.Should().BeTrue();
104

    
105
            result = await handler.Handle(new CreateNewArea.Command(DateTime.Today.AddDays(1), DateTime.Today.AddDays(2), 0.0), default);
106

    
107
            result.IsSuccess.Should().BeFalse();
108

    
109
            _semaphore.Release();
110
        }
111

    
112
        [Fact]
113
        public async void CreateNewAreaTestWrongRange()
114
        {
115
            await _semaphore.WaitAsync();
116

    
117
            var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.MAName);
118
            var handler = new CreateNewArea.Handler(
119
                DatabaseFixture.Services.GetRequiredService<IGlobalDefinitionAreaRepository>(),
120
                AuthenticationStateProviderMock.Object,
121
                DatabaseFixture.Services.GetRequiredService<IDomainUserRepository>());
122
            var result = await handler.Handle(new CreateNewArea.Command(DateTime.Today.AddDays(1), DateTime.Today, 0.0), default);
123

    
124
            result.IsSuccess.Should().BeFalse();
125

    
126
            _semaphore.Release();
127
        }
128
    }
129
}
(1-1/5)