Projekt

Obecné

Profil

Stáhnout (5.28 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
            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
        
55
        [Fact]
56
        public async void CreateNewAreaTestTL()
57
        {
58
            await _semaphore.WaitAsync();
59

    
60
            var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.TLName);
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
        
73
        [Fact]
74
        public async void CreateNewAreaTestMA()
75
        {
76
            await _semaphore.WaitAsync();
77

    
78
            var AuthenticationStateProviderMock = await TestUtils.AuthenticationMock(DatabaseFixture, TestUtils.MAName);
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
        [Fact]
91
        public async void CreateNewAreaTestOverlap()
92
        {
93
            await _semaphore.WaitAsync();
94

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

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

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

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

    
108
            _semaphore.Release();
109
        }
110

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

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

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

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