Template
chore: deploy initial code base
This commit is contained in:
+218
@@ -0,0 +1,218 @@
|
||||
using ClosedXML.Excel;
|
||||
using FluentAssertions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Strata.ApiLib.Standard.Models;
|
||||
using Strata.ContinuousImprovement.Api.Controllers;
|
||||
using Strata.ContinuousImprovement.Biz.ChargeCode.Initiatives;
|
||||
using Strata.ContinuousImprovement.Biz.ChargeCode.Opportunities;
|
||||
using Strata.ContinuousImprovement.Biz.DbContexts;
|
||||
using Strata.ContinuousImprovement.Biz.Encounter.Opportunities.Filters;
|
||||
using Strata.ContinuousImprovement.Biz.Filter;
|
||||
using Strata.ContinuousImprovement.Biz.OpportunityComments;
|
||||
using Strata.ContinuousImprovement.Biz.Pagination;
|
||||
using Strata.ContinuousImprovement.JazzEntityFrameworkStub;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnitSetup = NUnit.Framework.SetUpAttribute;
|
||||
|
||||
namespace Strata.ContinuousImprovement.Api.Test.Unit.Controllers
|
||||
{
|
||||
[TestFixture, Category("Unit"), Category("Controller")]
|
||||
public class ChargeCodeOppsControllerTests
|
||||
{
|
||||
public JazzDbContext DbContext { get; set; }
|
||||
public ChargeCodeOppsController Controller { get; set; }
|
||||
public ICommentService CommentService { get; set; }
|
||||
public ICCOpportunityViewService OpportunityService { get; set; }
|
||||
public ICCInitiativeService InitiativeService { get; set; }
|
||||
|
||||
[OneTimeSetUp]
|
||||
public async Task ConfigurationsControllerTestSetup()
|
||||
{
|
||||
// Arrange
|
||||
var jeff = new JazzEntityFrameworkFactory();
|
||||
DbContext = await jeff.CreateDbContextAsync(nameof(ChargeCodeOppsControllerTests), CancellationToken.None);
|
||||
var expectedData = jeff.CCOpportunities;
|
||||
var expected = expectedData[0];
|
||||
var expectedage = new PagedApiResponse<CCOpportunity>
|
||||
{
|
||||
Data = expectedData,
|
||||
PagingInfo = new PagingInfo
|
||||
{
|
||||
TotalNumberOfResults = expectedData.Count,
|
||||
TotalPages = 1,
|
||||
ResultsPerPage = expectedData.Count,
|
||||
PageNumber = 1
|
||||
}
|
||||
};
|
||||
var workbook = new XLWorkbook();
|
||||
workbook.AddWorksheet("ChargeCodeOpps");
|
||||
CommentService = Mock.Of<ICommentService>();
|
||||
OpportunityService = Mock.Of<ICCOpportunityViewService>();
|
||||
Mock.Get(OpportunityService)
|
||||
.Setup(s => s.GetPagedAsync(It.IsAny<PagingOptions>(), It.IsAny<IFilters<CCOpportunity>>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.FromResult(expectedage));
|
||||
Mock.Get(OpportunityService)
|
||||
.Setup(s => s.ExportAsync(It.IsAny<SortOptions>(), It.IsAny<CCFilters>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.FromResult((IXLWorkbook)workbook));
|
||||
Mock.Get(OpportunityService)
|
||||
.Setup(s => s.GetFilterOptionsAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.FromResult(new CCFilterOptions()));
|
||||
Mock.Get(OpportunityService)
|
||||
.Setup(s => s.GetById(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, CancellationToken>((oppGuid, token)
|
||||
=> oppGuid == expected.OpportunityGuid
|
||||
? Task.FromResult(expected)
|
||||
: Task.FromResult((CCOpportunity)null));
|
||||
var hiddenExpected = expected.IsHidden = !expectedData[0].IsHidden;
|
||||
Mock.Get(OpportunityService)
|
||||
.Setup(s => s.SetHiddenAsync(It.IsAny<Guid>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, bool, CancellationToken>((oppGuid, isHidden, token)
|
||||
=> oppGuid == expected.OpportunityGuid
|
||||
? Task.CompletedTask
|
||||
: Task.FromResult((CCOpportunity)null));
|
||||
Mock.Get(OpportunityService)
|
||||
.Setup(s => s.SetNoteAsync(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, string, CancellationToken>((oppGuid, note, token)
|
||||
=> oppGuid == expected.OpportunityGuid
|
||||
? Task.CompletedTask
|
||||
: Task.FromResult((CCOpportunity)null));
|
||||
InitiativeService = Mock.Of<ICCInitiativeService>();
|
||||
}
|
||||
|
||||
[NUnitSetup]
|
||||
public void TestSetup()
|
||||
{
|
||||
// Arrange
|
||||
Controller = new ChargeCodeOppsController(OpportunityService);
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public void ChargeCodeOppsControllerTest()
|
||||
{
|
||||
Controller.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task GetOpportunitiesTest()
|
||||
{
|
||||
// Arrange
|
||||
var loadOptions = new ChargeCodeOppsController.CCOpportunityLoadOptions
|
||||
{
|
||||
PagingOptions = new PagingOptions
|
||||
{
|
||||
First = 1,
|
||||
Rows = int.MaxValue,
|
||||
SortField = "IdentifiedSavings",
|
||||
SortOrder = SortOrder.Desc
|
||||
},
|
||||
Filters = new CCFilters
|
||||
{
|
||||
ConfigurationGuid = JazzEntityFrameworkFactory.CurrentConfigurationGuid
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await Controller.GetOpportunities(loadOptions, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.Should().BeOfType<PagedApiResponse<CCOpportunity>>();
|
||||
result.PagingInfo.Should().NotBeNull();
|
||||
result.Data.Should().NotBeNull();
|
||||
result.Data.Count().Should().Be(result.PagingInfo.TotalNumberOfResults);
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task ExportTest()
|
||||
{
|
||||
// Arrange
|
||||
var exportOptions = new ChargeCodeOppsController.CCOpportunityExportOptions
|
||||
{
|
||||
Filters = new CCFilters
|
||||
{
|
||||
ConfigurationGuid = JazzEntityFrameworkFactory.CurrentConfigurationGuid
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await Controller.Export(exportOptions, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeOfType<ExcelContentResult>();
|
||||
var excelContentResult = result as ExcelContentResult;
|
||||
excelContentResult.Should().NotBeNull();
|
||||
excelContentResult.FileName.Should().NotBeNullOrEmpty();
|
||||
excelContentResult.Workbook.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task GetFilterOptionsAsyncTest()
|
||||
{
|
||||
// Act
|
||||
var result = await Controller.GetFilterOptionsAsync(JazzEntityFrameworkFactory.CurrentConfigurationGuid, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeOfType<CCFilterOptions>();
|
||||
}
|
||||
|
||||
// commenting out because we don't have getById endpoint test should be redone
|
||||
[TestCase(true, TestName = "GetByIdTest - true", Ignore = "When I debug it passes, otherwise it doesn't")]
|
||||
[TestCase(false, TestName = "GetByIdTest - false")]
|
||||
public async Task GetByIdTest(bool withOpp)
|
||||
{
|
||||
//// Arrange
|
||||
//var opp = await DbContext.ChargeCodeOpps.FirstOrDefaultAsync(CancellationToken.None);
|
||||
|
||||
//// Act
|
||||
|
||||
////var result = await Controller.GetById(withOpp ? opp.OpportunityGuid : Guid.NewGuid(), CancellationToken.None);
|
||||
|
||||
//// Assert
|
||||
//if (withOpp)
|
||||
//{
|
||||
// result.Should().NotBeNull();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// result.Should().BeNull();
|
||||
//}
|
||||
}
|
||||
|
||||
[TestCase(true, true, TestName = "SetHiddenAsyncTest - true - isHidden")]
|
||||
[TestCase(true, false, TestName = "SetHiddenAsyncTest - true - not isHidden")]
|
||||
[TestCase(false, true, TestName = "SetHiddenAsyncTest - false - isHidden")]
|
||||
[TestCase(false, false, TestName = "SetHiddenAsyncTest - false - not isHidden")]
|
||||
public async Task SetHiddenAsyncTest(bool withOpp, bool isHidden)
|
||||
{
|
||||
// Arrange
|
||||
var opp = await DbContext.ChargeCodeOpps.FirstOrDefaultAsync(CancellationToken.None);
|
||||
var opportunityGuid = withOpp ? opp.OpportunityGuid : Guid.NewGuid();
|
||||
|
||||
// Assert
|
||||
Assert.DoesNotThrowAsync(async () => // Act
|
||||
await Controller.SetHiddenAsync(opportunityGuid, isHidden, CancellationToken.None));
|
||||
}
|
||||
|
||||
[TestCase(true, "", TestName = "SetNoteAsyncTest - true - note")]
|
||||
[TestCase(true, null, TestName = "SetNoteAsyncTest - true - null")]
|
||||
[TestCase(false, "", TestName = "SetNoteAsyncTest - false - not")]
|
||||
[TestCase(false, null, TestName = "SetNoteAsyncTest - false - null")]
|
||||
public async Task SetNoteAsyncTest(bool withOpp, string note)
|
||||
{
|
||||
// Arrange
|
||||
var opp = await DbContext.ChargeCodeOpps.FirstOrDefaultAsync(CancellationToken.None);
|
||||
var opportunityGuid = withOpp ? opp.OpportunityGuid : Guid.NewGuid();
|
||||
|
||||
// Assert
|
||||
Assert.DoesNotThrowAsync(async () => // Act
|
||||
await Controller.SetNoteAsync(opportunityGuid, note, CancellationToken.None));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user