-
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.
- Loading branch information
1 parent
da4defe
commit 454329b
Showing
6 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/AdminAssistant.Blazor/Server/WebAPI/v1/BudgetModule/BudgetController.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,36 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AdminAssistant.DomainModel.Modules.BudgetModule.CQRS; | ||
using AdminAssistant.Framework.Providers; | ||
using AutoMapper; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
|
||
namespace AdminAssistant.WebAPI.v1 | ||
{ | ||
[ApiController] | ||
[Route("api/v1/core/[controller]")] | ||
[ApiExplorerSettings(GroupName = "Budgets - Budget")] | ||
public class BudgetController : WebAPIControllerBase | ||
{ | ||
public BudgetController(IMapper mapper, IMediator mediator, ILoggingProvider loggingProvider) | ||
: base(mapper, mediator, loggingProvider) | ||
{ | ||
} | ||
|
||
[HttpGet] | ||
[SwaggerOperation("Lists all budgets.", OperationId = "GetBudget")] | ||
[SwaggerResponse(StatusCodes.Status200OK, "Ok - returns a list of BudgetResponseDto", type: typeof(IEnumerable<BudgetResponseDto>))] | ||
public async Task<ActionResult<IEnumerable<BudgetResponseDto>>> GetBudgets() | ||
{ | ||
Log.Start(); | ||
|
||
var result = await Mediator.Send(new BudgetQuery()).ConfigureAwait(false); | ||
var response = Mapper.Map<IEnumerable<BudgetResponseDto>>(result.Value); | ||
|
||
return Log.Finish(Ok(response)); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/AdminAssistant.Blazor/Server/WebAPI/v1/BudgetModule/BudgetResponseDto.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 AdminAssistant.DomainModel.Modules.BudgetModule; | ||
using AdminAssistant.Framework.TypeMapping; | ||
|
||
namespace AdminAssistant.WebAPI.v1 | ||
{ | ||
public class BudgetResponseDto : IMapFrom<Budget> | ||
{ | ||
public int BudgetID { get; set; } | ||
public string BudgetName { get; set; } = string.Empty; | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
src/AdminAssistant.Test/WebAPI/v1/Budget/BudgetController_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,67 @@ | ||
#pragma warning disable CA1707 // Identifiers should not contain underscores | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AdminAssistant.DomainModel; | ||
using AdminAssistant.DomainModel.Modules.BudgetModule; | ||
using AdminAssistant.DomainModel.Modules.BudgetModule.CQRS; | ||
using Ardalis.Result; | ||
using AutoMapper; | ||
using FluentAssertions; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace AdminAssistant.WebAPI.v1.BudgetModule | ||
{ | ||
public class BudgetController_UnitTest_Should | ||
{ | ||
[Fact] | ||
[Trait("Category", "Unit")] | ||
public async Task Return_Status200OK_With_AListOfBudgets_Given_NoArguments() | ||
{ | ||
// Arrange | ||
var budgets = new List<Budget>() | ||
{ | ||
Factory.Budget.WithTestData(10).Build(), | ||
Factory.Budget.WithTestData(20).Build() | ||
}; | ||
|
||
var services = new ServiceCollection(); | ||
services.AddMockServerSideLogging(); | ||
services.AddAutoMapper(typeof(MappingProfile)); | ||
|
||
var mockMediator = new Mock<IMediator>(); | ||
mockMediator.Setup(x => x.Send(It.IsAny<BudgetQuery>(), It.IsAny<CancellationToken>())) | ||
.Returns(Task.FromResult(Result<IEnumerable<Budget>>.Success(budgets))); | ||
|
||
services.AddTransient((sp) => mockMediator.Object); | ||
services.AddTransient<BudgetController>(); | ||
|
||
// Act | ||
var response = await services.BuildServiceProvider().GetRequiredService<BudgetController>().GetBudgets().ConfigureAwait(false); | ||
|
||
// Assert | ||
response.Result.Should().BeOfType<OkObjectResult>(); | ||
response.Value.Should().BeNull(); | ||
|
||
var result = (OkObjectResult)response.Result; | ||
result.Value.Should().BeAssignableTo<IEnumerable<BudgetResponseDto>>(); | ||
|
||
//var value = ((IEnumerable<CurrencyResponseDto>)result.Value).ToArray(); | ||
//value.Should().HaveCount(currencies.Count); | ||
|
||
//var expected = currencies.ToArray(); | ||
//for (int i = 0; i < expected.Length; i++) | ||
//{ | ||
// value[i].CurrencyID.Should().Be(expected[i].CurrencyID); | ||
// value[i].Symbol.Should().Be(expected[i].Symbol); | ||
// value[i].DecimalFormat.Should().Be(expected[i].DecimalFormat); | ||
//} | ||
} | ||
} | ||
} | ||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
using AdminAssistant.Infra.DAL; | ||
|
||
namespace AdminAssistant.DomainModel.Modules.BudgetModule | ||
{ | ||
public class Budget | ||
public class Budget : IDatabasePersistable | ||
{ | ||
public const int BudgetNameMaxLength = Constants.NameMaxLength; | ||
|
||
public int BudgetID { get; set; } | ||
public string BudgetName { get; set; } = string.Empty; | ||
|
||
public int PrimaryKey => BudgetID; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/AdminAssistant/DomainModel/Modules/BudgetModule/CQRS/BudgetQuery.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,10 @@ | ||
using System.Collections.Generic; | ||
using Ardalis.Result; | ||
using MediatR; | ||
|
||
namespace AdminAssistant.DomainModel.Modules.BudgetModule.CQRS | ||
{ | ||
public class BudgetQuery : IRequest<Result<IEnumerable<Budget>>> | ||
{ | ||
} | ||
} |