Skip to content

Commit

Permalink
#124 Added UI Service and Unit Tests for GetDocumentList
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonGeering committed Sep 2, 2020
1 parent 214d56a commit e04de1a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
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
1 change: 1 addition & 0 deletions src/AdminAssistant.UI/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static void AddAdminAssistantUI(this IServiceCollection services)

// Add Documents UI ...
services.AddSingleton<IDocumentsViewModel, DocumentsViewModel>();
services.AddTransient<IDocumentsService, DocumentsService>();

// Add Mail UI ...
services.AddSingleton<IMailViewModel, MailViewModel>();
Expand Down
29 changes: 29 additions & 0 deletions src/AdminAssistant.UI/Modules/DocumentsModule/DocumentsService.cs
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 src/AdminAssistant/UI/Modules/DocumentsModule/IDocumentsService.cs
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();
}
}

0 comments on commit e04de1a

Please sign in to comment.