-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#124 Added UI Service and Unit Tests for GetDocumentList
- Loading branch information
1 parent
214d56a
commit e04de1a
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/AdminAssistant.Test/UI/Modules/DocumentsModule/DocumentsService_UnitTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma warning disable CA1707 // Identifiers should not contain underscores | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AdminAssistant.DomainModel.Modules.DocumentsModule; | ||
using AdminAssistant.UI.Shared.WebAPIClient.v1; | ||
using AutoMapper; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace AdminAssistant.UI.Modules.DocumentsModule | ||
{ | ||
public class DocumentsService_GetDocumentListAsync | ||
{ | ||
[Fact] | ||
[Trait("Category", "Unit")] | ||
public async Task ReturnAListOfDocuments_GivenNoArguments() | ||
{ | ||
// Arrange | ||
ICollection<DocumentResponseDto> documentsList = new List<DocumentResponseDto>() | ||
{ | ||
new DocumentResponseDto { DocumentID = 1, FileName = "test.pdf" }, | ||
new DocumentResponseDto { DocumentID = 2, FileName = "test2.docx" }, | ||
}; | ||
|
||
var mockWebAPIClient = new Mock<IAdminAssistantWebAPIClient>(); | ||
mockWebAPIClient.Setup(x => x.GetDocumentAsync()) | ||
.Returns(Task.FromResult(documentsList)); | ||
|
||
var services = new ServiceCollection(); | ||
services.AddAdminAssistantUI(); | ||
services.AddMockClientSideLogging(); | ||
services.AddAutoMapper(typeof(MappingProfile)); | ||
services.AddTransient((sp) => mockWebAPIClient.Object); | ||
|
||
// Act | ||
var result = await services.BuildServiceProvider().GetRequiredService<IDocumentsService>().GetDocumentListAsync().ConfigureAwait(false); | ||
|
||
// Assert | ||
result.Should().BeEquivalentTo(new List<Document>() | ||
{ | ||
new Document { DocumentID = 1, FileName = "test.pdf" }, | ||
new Document { DocumentID = 2, FileName = "test2.docx" }, | ||
}); | ||
} | ||
} | ||
} | ||
#pragma warning restore CA1707 // Identifiers should not contain underscores |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/AdminAssistant.UI/Modules/DocumentsModule/DocumentsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AdminAssistant.DomainModel.Modules.DocumentsModule; | ||
using AdminAssistant.Infra.Providers; | ||
using AdminAssistant.UI.Shared.WebAPIClient.v1; | ||
using AutoMapper; | ||
|
||
namespace AdminAssistant.UI.Modules.DocumentsModule | ||
{ | ||
[SuppressMessage("Build", "CA1812", Justification = "Compiler dosen't understand dependency injection")] | ||
internal class DocumentsService : ServiceBase, IDocumentsService | ||
{ | ||
public DocumentsService(IAdminAssistantWebAPIClient adminAssistantWebAPIClient, IMapper mapper, ILoggingProvider log) | ||
: base(adminAssistantWebAPIClient, mapper, log) | ||
{ | ||
} | ||
|
||
public async Task<List<Document>> GetDocumentListAsync() | ||
{ | ||
Log.Start(); | ||
|
||
var response = await AdminAssistantWebAPIClient.GetDocumentAsync().ConfigureAwait(false); | ||
var result = new List<Document>(Mapper.Map<IEnumerable<Document>>(response)); | ||
|
||
return Log.Finish(result); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/AdminAssistant/UI/Modules/DocumentsModule/IDocumentsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AdminAssistant.DomainModel.Modules.DocumentsModule; | ||
|
||
namespace AdminAssistant.UI.Modules.DocumentsModule | ||
{ | ||
public interface IDocumentsService | ||
{ | ||
Task<List<Document>> GetDocumentListAsync(); | ||
} | ||
} |