-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApplicationAppServiceTests.cs
More file actions
159 lines (134 loc) · 6.31 KB
/
ApplicationAppServiceTests.cs
File metadata and controls
159 lines (134 loc) · 6.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using Shouldly;
using System;
using System.Linq;
using System.Threading.Tasks;
using Unity.GrantManager.Applications;
using Unity.GrantManager.Comments;
using Unity.GrantManager.Exceptions;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
using Volo.Abp.Identity.Integration;
using Volo.Abp.Uow;
using Volo.Abp.Users;
using Xunit;
using Xunit.Abstractions;
namespace Unity.GrantManager.GrantApplications;
public class ApplicationAppServiceTests : GrantManagerApplicationTestBase
{
private readonly GrantApplicationAppService _grantApplicationAppServiceTest;
private readonly IGrantApplicationAppService _grantApplicationAppService;
private readonly IRepository<Application, Guid> _applicationsRepository;
private readonly IRepository<ApplicationComment, Guid> _applicationCommentsRepository;
private readonly IApplicationAssignmentRepository _userAssignmentRepository;
private readonly IIdentityUserIntegrationService _identityUserLookupAppService;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public ApplicationAppServiceTests(ITestOutputHelper outputHelper) : base(outputHelper)
{
_grantApplicationAppServiceTest = GetRequiredService<GrantApplicationAppService>();
_grantApplicationAppService = GetRequiredService<IGrantApplicationAppService>();
_applicationsRepository = GetRequiredService<IRepository<Application, Guid>>();
_applicationCommentsRepository = GetRequiredService<IRepository<ApplicationComment, Guid>>();
_identityUserLookupAppService = GetRequiredService<IIdentityUserIntegrationService>();
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
_userAssignmentRepository = GetRequiredService<IApplicationAssignmentRepository>();
}
[Fact]
public async Task AddRemoveAssigneeAsync_Should_AddRemove_Assignee()
{
// Arrange
using var uow = _unitOfWorkManager.Begin();
var application = (await _applicationsRepository.GetListAsync())[0];
var users = await _identityUserLookupAppService.SearchAsync(new UserLookupSearchInputDto());
if (users != null && users.Items.Count > 0)
{
UserData uData = users.Items[0];
// Act
await _grantApplicationAppServiceTest.InsertAssigneeAsync(application.Id, uData.Id,"");
await uow.SaveChangesAsync();
// Assert
IQueryable<ApplicationAssignment> queryableAssignment = await _userAssignmentRepository.GetQueryableAsync();
var assignments = queryableAssignment.ToList();
assignments.Count.ShouldBe(1);
// Act
await _grantApplicationAppServiceTest.DeleteAssigneeAsync(application.Id, uData.Id);
await uow.SaveChangesAsync();
IQueryable<ApplicationAssignment> queryableAssignment2 = await _userAssignmentRepository.GetQueryableAsync();
var assignments2 = queryableAssignment2.ToList();
assignments2.Count.ShouldBe(0);
}
}
[Fact]
[Trait("Category", "Integration")]
public async Task CreateCommentAsync_Should_Create_Comment()
{
// Arrange
Login(GrantManagerTestData.User1_UserId);
using var uow = _unitOfWorkManager.Begin();
var application = (await _applicationsRepository.GetListAsync())[0];
var applicationComments = (await _applicationCommentsRepository.GetQueryableAsync()).Where(s => s.ApplicationId == application.Id).ToList();
var count = applicationComments.Count;
var comment = "Test Application Comment Integration";
// Act
_ = await _grantApplicationAppService.CreateCommentAsync(application.Id, new CreateCommentDto()
{
Comment = comment
});
// Assert
var afterAssessmentComments = (await _applicationCommentsRepository.GetQueryableAsync()).Where(s => s.ApplicationId == application.Id).ToList();
afterAssessmentComments.Count.ShouldBe(count + 1);
}
[Fact]
[Trait("Category", "Integration")]
public async Task UpdateCommentAsync_Should_Update_Comment()
{
// Arrange
using var uow = _unitOfWorkManager.Begin();
var application = (await _applicationsRepository.GetListAsync())[0];
var applicationComment = (await _applicationCommentsRepository.GetQueryableAsync()).Where(s => s.ApplicationId == application.Id).ToList()[0];
var updateComment = "Updated Comment";
// Act
var updatedCommentDto = await _grantApplicationAppService.UpdateCommentAsync(application.Id, new UpdateCommentDto()
{
CommentId = applicationComment.Id,
Comment = updateComment
});
// Assert
var updatedComment = await _applicationCommentsRepository.GetAsync(updatedCommentDto.Id);
updatedComment.Comment.ShouldBe(updateComment);
}
[Fact]
[Trait("Category", "Integration")]
public async Task GetCommentListAsync_Should_Return_ApplicationComments()
{
// Arrange
using var uow = _unitOfWorkManager.Begin();
var application = (await _applicationsRepository.GetListAsync())[0];
// Act
var assessmentComments = (await _grantApplicationAppService.GetCommentsAsync(application.Id)).ToList();
// Assert
assessmentComments.ShouldNotBeNull();
assessmentComments.Count.ShouldBeGreaterThan(0);
}
[Fact]
[Trait("Category", "Integration")]
public async Task UpdateCommentAsync_Invalid_Should_Throw()
{
// Arrange
// Act
// Assert
await Assert.ThrowsAsync<InvalidCommentParametersException>(() => _grantApplicationAppService.UpdateCommentAsync(Guid.NewGuid(), new UpdateCommentDto()
{
CommentId = Guid.NewGuid(),
Comment = "Foobar"
}));
}
[Fact]
[Trait("Category", "Integration")]
public async Task GetCommentAsync_Invalid_Should_Throw()
{
// Arrange
// Act
// Assert
await Assert.ThrowsAsync<InvalidCommentParametersException>(() => _grantApplicationAppService.GetCommentAsync(Guid.NewGuid(), Guid.NewGuid()));
}
}