Skip to content

Commit

Permalink
Merge pull request #125 from SkillsFundingAgency/CV-771_AnalyticsOrgName
Browse files Browse the repository at this point in the history
CV-771 analytics org name Employer
  • Loading branch information
Najamuddin-Muhammad authored Jun 25, 2020
2 parents 099d06e + 1750cb4 commit 834944f
Show file tree
Hide file tree
Showing 57 changed files with 298 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Threading.Tasks;
using AutoFixture;
using AutoFixture.NUnit3;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
Expand Down Expand Up @@ -33,12 +35,27 @@ public void Arrange()
[Test, AutoData]
public async Task GetMessage_ValidModel_ShouldReturnMessageViewModelWithMappedValues(MessageRequest request)
{
_fixture.WithLegalEntityNameStoredInTempData();

var result = await _fixture.Sut.Message(request);

var model = result.VerifyReturnsViewModel().WithModel<MessageViewModel>();
_fixture.VerifyViewModelIsMappedCorrectly(model);
}

[Test, AutoData]
public async Task GetMessage_ValidModel_ForProvider_ShouldPopulateLegalEntityNameFromTempData(
[Frozen] MessageRequest request)
{
request.LegalEntityName = null;
_fixture.WithLegalEntityNameStoredInTempData();

var result = await _fixture.Sut.Message(request);

var model = result.VerifyReturnsViewModel().WithModel<MessageViewModel>();
_fixture.VerifyLegalEntityNamePopulatedFromTempData(model);
}

[Test, AutoData]
public async Task PostMessage_WithValidRequest_ShouldAddCohortAndReturnRedirectResult(MessageViewModel model, CreateCohortResponse createCohortResponse)
{
Expand Down Expand Up @@ -80,7 +97,8 @@ public CreateCohortWithOtherPartyControllerTestFixture()

MapperResult = new CreateCohortWithOtherPartyRequest();
ModelMapperMock = new Mock<IModelMapper>();
ModelMapperMock.Setup(x => x.Map<CreateCohortWithOtherPartyRequest>(It.IsAny<object>()))
ModelMapperMock
.Setup(x => x.Map<CreateCohortWithOtherPartyRequest>(It.IsAny<object>()))
.ReturnsAsync(() => MapperResult);

MessageViewModel = autoFixture.Create<MessageViewModel>();
Expand Down Expand Up @@ -108,6 +126,14 @@ public CreateCohortWithOtherPartyControllerTestFixture WithInvalidModel()
return this;
}

public CreateCohortWithOtherPartyControllerTestFixture WithLegalEntityNameStoredInTempData()
{
var tempData = new TempDataDictionary(new DefaultHttpContext(), Mock.Of<ITempDataProvider>());
tempData[nameof(MessageRequest.LegalEntityName)] = MessageViewModel.LegalEntityName;
Sut.TempData = tempData;
return this;
}

public CreateCohortWithOtherPartyControllerTestFixture SetCreateCohortResponse(
CreateCohortResponse createCohortResponse)
{
Expand Down Expand Up @@ -159,6 +185,12 @@ public CreateCohortWithOtherPartyControllerTestFixture VerifyViewModelIsMappedCo

return this;
}

public CreateCohortWithOtherPartyControllerTestFixture VerifyLegalEntityNamePopulatedFromTempData(MessageViewModel model)
{
Assert.AreEqual(MessageViewModel.LegalEntityName, model.LegalEntityName);
return this;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using AutoFixture.NUnit3;
using System.Collections.Generic;
using System.ComponentModel.Design;
using AutoFixture.NUnit3;
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Routing;
using Moq;
using NUnit.Framework;
Expand Down Expand Up @@ -64,6 +68,32 @@ public void And_Provider_Adding_Apprentices_Then_Redirect_To_Message(
result.RouteValues.Should().BeEquivalentTo(expectedRouteValues);
}

[Test, MoqAutoData]
public void And_Provider_Adding_Apprentices_Then_Legal_Entity_Name_Stored_In_TempData(
[Frozen] AssignViewModel viewModel,
[Frozen] Mock<ITempDataProvider> tempDataProvider,
[Frozen] CohortController controller)
{
var tempdata = new TempDataDictionary(new DefaultHttpContext(), tempDataProvider.Object);
controller.TempData = tempdata;
var expectedRouteValues = new RouteValueDictionary(new
{
viewModel.AccountHashedId,
viewModel.AccountLegalEntityHashedId,
viewModel.ReservationId,
viewModel.StartMonthYear,
viewModel.CourseCode,
viewModel.ProviderId,
viewModel.TransferSenderId,
Origin = viewModel.ReservationId.HasValue ? Origin.Reservations : Origin.Apprentices
});
viewModel.WhoIsAddingApprentices = WhoIsAddingApprentices.Provider;

var result = controller.Assign(viewModel) as RedirectToActionResult;

Assert.True(controller.TempData.Contains(new KeyValuePair<string, object>(nameof(viewModel.LegalEntityName), viewModel.LegalEntityName)));
}

[Test, MoqAutoData]
public void And_Unknown_Adding_Apprentices_Then_Redirect_To_Error(
AssignViewModel viewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public void AccountLegalEntityHashedIdIsMappedCorrectly()
Assert.AreEqual(_source.AccountLegalEntityHashedId, _result.AccountLegalEntityHashedId);
}

[Test]
public void AccountLegalEntityNameIsMappedCorrectly()
{
Assert.AreEqual(_accountLegalEntityResponse.LegalEntityName, _result.LegalEntityName);
}

[Test]
public void StartDateIsMappedCorrectly()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public async Task ProviderNameIsMappedCorrectly()
Assert.AreEqual(fixture.Cohort.ProviderName, result.ProviderName);
}

[Test]
public async Task LegalEntityNameIsMappedCorrectly()
{
var fixture = new ConfirmDeleteViewModelMapperTestsFixture();
var result = await fixture.Map();
Assert.AreEqual(fixture.Cohort.LegalEntityName, result.LegalEntityName);
}

[Test]
public async Task DraftApprenticeshipTotalCountIsReportedCorrectly()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public void ThenAccountLegalEntityHashedIdIsMapperCorrectly()
Assert.AreEqual(_source.AccountLegalEntityHashedId, _result.AccountLegalEntityHashedId);
}
[Test]
public void ThenLegalEntityNameIsMappedCorrectly()
{
Assert.AreEqual(_source.LegalEntityName, _source.LegalEntityName);
}
[Test]
public void ThenCourseCodeIsMapperCorrectly()
{
Assert.AreEqual(_source.CourseCode, _result.CourseCode);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using System.Threading.Tasks;
using AutoFixture.NUnit3;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.Testing.AutoFixture;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Cohort
{
public class WhenMappingAssignRequestToViewModel
{
[Test, AutoData]
[Test, MoqAutoData]
public async Task Then_Maps_AccountHashedId(
AssignRequest request,
AssignViewModelMapper mapper)
Expand All @@ -19,7 +23,7 @@ public async Task Then_Maps_AccountHashedId(
viewModel.AccountHashedId.Should().Be(request.AccountHashedId);
}

[Test, AutoData]
[Test, MoqAutoData]
public async Task Then_Maps_EmployerAccountLegalEntityPublicHashedId(
AssignRequest request,
AssignViewModelMapper mapper)
Expand All @@ -29,7 +33,23 @@ public async Task Then_Maps_EmployerAccountLegalEntityPublicHashedId(
viewModel.AccountLegalEntityHashedId.Should().Be(request.AccountLegalEntityHashedId);
}

[Test, AutoData]
[Test, MoqAutoData]
public async Task Then_Maps_LegalEntityName(
[Frozen] AssignRequest request,
[Frozen] AccountLegalEntityResponse response,
[Frozen] Mock<ICommitmentsApiClient> commitmentsApiClientMock,
AssignViewModelMapper mapper)
{
commitmentsApiClientMock
.Setup(x => x.GetAccountLegalEntity(request.AccountLegalEntityId, default))
.ReturnsAsync(response);

var viewModel = await mapper.Map(request);

viewModel.LegalEntityName.Should().Be(response.LegalEntityName);
}

[Test, MoqAutoData]
public async Task Then_Maps_ReservationId(
AssignRequest request,
AssignViewModelMapper mapper)
Expand All @@ -39,7 +59,7 @@ public async Task Then_Maps_ReservationId(
viewModel.ReservationId.Should().Be(request.ReservationId);
}

[Test, AutoData]
[Test, MoqAutoData]
public async Task Then_Maps_StartMonthYear(
AssignRequest request,
AssignViewModelMapper mapper)
Expand All @@ -49,7 +69,7 @@ public async Task Then_Maps_StartMonthYear(
viewModel.StartMonthYear.Should().Be(request.StartMonthYear);
}

[Test, AutoData]
[Test, MoqAutoData]
public async Task Then_Maps_CourseCode(
AssignRequest request,
AssignViewModelMapper mapper)
Expand All @@ -59,7 +79,7 @@ public async Task Then_Maps_CourseCode(
viewModel.CourseCode.Should().Be(request.CourseCode);
}

[Test, AutoData]
[Test, MoqAutoData]
public async Task Then_Maps_UkPrn(
AssignRequest request,
AssignViewModelMapper mapper)
Expand All @@ -69,7 +89,7 @@ public async Task Then_Maps_UkPrn(
viewModel.ProviderId.Should().Be(request.ProviderId);
}

[Test, AutoData]
[Test, MoqAutoData]
public async Task Then_Maps_TransferSenderId(
AssignRequest request,
AssignViewModelMapper mapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public async Task ThenMapsEmployerAccountLegalEntityPublicHashedId(
Assert.AreEqual(viewModel.AccountLegalEntityHashedId, result.AccountLegalEntityHashedId);
}

[Test, MoqAutoData]
public async Task ThenMapsLegalEntityName(
SelectProviderViewModel viewModel,
long providerId,
ConfirmProviderRequestMapper mapper)
{
viewModel.ProviderId = providerId.ToString();

var result = await mapper.Map(viewModel);

Assert.AreEqual(viewModel.LegalEntityName, result.LegalEntityName);
}

[Test, MoqAutoData]
public async Task ThenMapsStartMonthYear(
SelectProviderViewModel viewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public async Task Then_Maps_EmployerAccountLegalEntityPublicHashedId(
viewModel.AccountLegalEntityHashedId.Should().Be(request.AccountLegalEntityHashedId);
}

[Test, MoqAutoData]
public async Task Then_Maps_LegalEntityName(
ConfirmProviderRequest request,
[Frozen] Mock<ICommitmentsApiClient> commitmentsApiClient,
ConfirmProviderViewModelMapper mapper)
{
var viewModel = await mapper.Map(request);

viewModel.LegalEntityName.Should().Be(request.LegalEntityName);
}

[Test, MoqAutoData]
public async Task Then_Maps_ReservationId(
ConfirmProviderRequest request,
Expand Down
Loading

0 comments on commit 834944f

Please sign in to comment.