Template
180 lines
6.5 KiB
C#
180 lines
6.5 KiB
C#
using FluentAssertions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Strata.ApiLib.Standard.Models;
|
|
using Strata.ContinuousImprovement.Api.Controllers;
|
|
using Strata.ContinuousImprovement.Biz.DbContexts;
|
|
using Strata.ContinuousImprovement.Biz.FreeForm.Initiatives;
|
|
using Strata.ContinuousImprovement.Biz.FreeForm.Opportunities;
|
|
using Strata.ContinuousImprovement.Biz.FreeForm.Opportunities.Filters;
|
|
using Strata.ContinuousImprovement.Biz.Initiatives;
|
|
using Strata.ContinuousImprovement.Biz.Pagination;
|
|
using Strata.ContinuousImprovement.JazzEntityFrameworkStub;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Strata.ContinuousImprovement.Api.Test.Unit.Controllers
|
|
{
|
|
[TestFixture, Category("Unit"), Category("Controller")]
|
|
public class FreeFormOpportunitiesControllerTests
|
|
{
|
|
public JazzEntityFrameworkFactory jazzEntityFrameworkFactory { get; set; }
|
|
public JazzDbContext DbContext { get; set; }
|
|
public IFFOpportunityService FFOpportunityService { get; set; }
|
|
public IFFInitiativeService FFInitiativeService { get; set; }
|
|
public IInitiativeService InitiativeService { get; set; }
|
|
public FreeFormOpportunitiesController Controller { get; set; }
|
|
|
|
|
|
[OneTimeSetUp]
|
|
public async Task FreeFormOpportunitiesControllerTestSetup()
|
|
{
|
|
jazzEntityFrameworkFactory = new JazzEntityFrameworkFactory();
|
|
DbContext = await jazzEntityFrameworkFactory.CreateDbContextAsync(nameof(ConfigurationsControllerTests), CancellationToken.None);
|
|
FFOpportunityService = Mock.Of<IFFOpportunityService>();
|
|
InitiativeService = Mock.Of<IInitiativeService>();
|
|
}
|
|
|
|
[SetUp]
|
|
public async Task Setup()
|
|
{
|
|
// Arrange
|
|
Controller = new FreeFormOpportunitiesController(FFOpportunityService, InitiativeService);
|
|
}
|
|
|
|
[Test()]
|
|
public async Task FreeFormOpportunitiesControllerTest()
|
|
{
|
|
// Act
|
|
|
|
// Assert
|
|
Controller.Should().NotBeNull();
|
|
}
|
|
|
|
[Test()]
|
|
public async Task GetOpportunitiesTest()
|
|
{
|
|
// Arrange
|
|
var opportunities = DbContext.FFOpportunities.Take(25).ToList();
|
|
var pagingOptions = new PagingOptions
|
|
{
|
|
First = 1,
|
|
Rows = 25,
|
|
SortField = nameof(FFOpportunity.IdentifiedSavings),
|
|
SortOrder = SortOrder.Asc
|
|
};
|
|
var loadOptions = new FFOpportunityLoadOptions
|
|
{
|
|
Filters = new FFFilters { ConfigurationGuid = JazzEntityFrameworkFactory.CurrentConfigurationGuid },
|
|
PagingOptions = pagingOptions,
|
|
};
|
|
var response = new PagedApiResponse<FFOpportunity>
|
|
{
|
|
PagingInfo = new PagingInfo
|
|
{
|
|
PageNumber = 1,
|
|
TotalNumberOfResults = opportunities.Count,
|
|
TotalPages = opportunities.Count / pagingOptions.Rows,
|
|
ResultsPerPage = pagingOptions.Rows
|
|
},
|
|
Data = opportunities
|
|
};
|
|
Mock.Get(FFOpportunityService)
|
|
.Setup(x => x.GetPagedAsync(It.IsAny<PagingOptions>(), It.IsAny<FFFilters>(), It.IsAny<CancellationToken>()))
|
|
.Returns<PagingOptions, FFFilters, CancellationToken>(
|
|
(pagingOptions, filters, token) =>
|
|
Task.FromResult(response)
|
|
);
|
|
|
|
// Act
|
|
var controllerResponse = await Controller.GetOpportunities(loadOptions, CancellationToken.None);
|
|
|
|
|
|
// Assert
|
|
controllerResponse.Should().NotBeNull();
|
|
}
|
|
|
|
[Test()]
|
|
public async Task GetByIdTest()
|
|
{
|
|
// Arrange
|
|
var opportunities = DbContext.FreeFormOpportunities.ToList();
|
|
var firstOpportunity = opportunities.First();
|
|
if (firstOpportunity.Configuration == null)
|
|
{
|
|
var configuration = DbContext.Configurations.First();
|
|
if (configuration.FiscalMonthResolver == null)
|
|
{
|
|
var fmr = jazzEntityFrameworkFactory.FiscalMonthResolver;
|
|
configuration.FiscalMonthResolver = fmr;
|
|
}
|
|
firstOpportunity.Configuration = configuration;
|
|
}
|
|
var dfltOpportunity = default(FFOpportunityDataModel);
|
|
var fmResolver = jazzEntityFrameworkFactory.FiscalMonthResolver;
|
|
Mock.Get(FFOpportunityService)
|
|
.Setup(x => x.GetDataModelById(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
|
.Returns<Guid, CancellationToken>(
|
|
(opportunityGuid, token) =>
|
|
opportunityGuid != firstOpportunity.OpportunityGuid
|
|
? Task.FromResult(dfltOpportunity)
|
|
: Task.FromResult(firstOpportunity)
|
|
);
|
|
var detailModel = firstOpportunity.MapToDetailModel(fmResolver);
|
|
|
|
// Act
|
|
var controllerResponse = await Controller.GetById(firstOpportunity.OpportunityGuid, CancellationToken.None);
|
|
|
|
// Assert
|
|
controllerResponse.Should().NotBeNull();
|
|
controllerResponse.Result.Should().NotBeNull();
|
|
controllerResponse.Result.Should().BeOfType<OkObjectResult>();
|
|
var result = (OkObjectResult)controllerResponse.Result;
|
|
result.Should().NotBeNull();
|
|
result.Should().BeOfType<OkObjectResult>();
|
|
result.Value.Should().NotBeNull();
|
|
result.Value.Should().BeOfType<FFOpportunityDetailModel>();
|
|
var detail = (FFOpportunityDetailModel)result.Value;
|
|
detail.Should().BeEquivalentTo(detailModel);
|
|
}
|
|
|
|
[Test()]
|
|
public async Task CreateTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
|
|
[Test()]
|
|
public async Task DeleteTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
|
|
[Test()]
|
|
public async Task GetInitiativeTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
|
|
[Test()]
|
|
public async Task SetGoalsAsyncTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
|
|
[Test()]
|
|
public async Task ExportTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
|
|
[Test()]
|
|
public async Task GetFilterOptionsAsyncTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
}
|
|
} |