Skip to content

Commit

Permalink
Con 3093 migrate stop date (#190)
Browse files Browse the repository at this point in the history
* CON-3093-Migrate Edit Stop Date

* CON-3093-Fix mapping and test

* CON-3093

* con-3093

* CON-3093 - PR comment

* Revert "Merge branch 'master' into CON-3093-migrate-stop-date"

This reverts commit 374ed6c, reversing
changes made to 0a08096.

* Revert "Revert "Merge branch 'master' into CON-3093-migrate-stop-date""

This reverts commit c8bda47.

* Revert "Revert "Revert "Merge branch 'master' into CON-3093-migrate-stop-date"""

This reverts commit 669f94a.

* Revert "Revert "Revert "Revert "Merge branch 'master' into CON-3093-migrate-stop-date""""

This reverts commit 915a117.

* con-3093

* CON-3093-  changed to V2 link

* CON-3093

* CON-3093-updated package
  • Loading branch information
VasanthaKasirajan3008 authored Apr 21, 2021
1 parent 45457da commit 8b40e41
Show file tree
Hide file tree
Showing 16 changed files with 670 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using AutoFixture;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice;
using System.Threading.Tasks;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests
{
public class WhenCallingEditStopDateTests
{
WhenCallingEditStopDateTestsFixture _fixture;

[SetUp]
public void Arrange()
{
_fixture = new WhenCallingEditStopDateTestsFixture();
}

[Test]
public async Task ThenTheCorrectViewIsReturned()
{
//Act
var result = await _fixture.EditStopDate();

//Assert
_fixture.VerifyViewModel(result as ViewResult);
}
}

public class WhenCallingEditStopDateTestsFixture : ApprenticeControllerTestFixtureBase
{
private readonly EditStopDateRequest _request;
private readonly EditStopDateViewModel _viewModel;

public WhenCallingEditStopDateTestsFixture() : base()
{
_request = _autoFixture.Create<EditStopDateRequest>();
_autoFixture.Customize<EditStopDateViewModel>(c => c.Without(x => x.NewStopDate));
_viewModel = _autoFixture.Create<EditStopDateViewModel>();
_viewModel.NewStopDate = new CommitmentsV2.Shared.Models.MonthYearModel("062020");

_mockMapper.Setup(m => m.Map<EditStopDateViewModel>(_request))
.ReturnsAsync(_viewModel);
}

public async Task<IActionResult> EditStopDate()
{
return await _controller.EditStopDate(_request);
}

public void VerifyViewModel(ViewResult viewResult)
{
var viewModel = viewResult.Model as EditStopDateViewModel;

Assert.IsInstanceOf<EditStopDateViewModel>(viewModel);
Assert.AreEqual(_viewModel, viewModel);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using AutoFixture;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using SFA.DAS.Authorization.Services;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice;
using SFA.DAS.EmployerUrlHelper;
using System.Threading;
using System.Threading.Tasks;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests
{
public class WhenPostingEditStopDateTests : ApprenticeControllerTestBase
{
private const string ApprenticeEditStopDate = "New stop date confirmed";
private const string FlashMessage = "FlashMessage";
private const string FlashMessageLevel = "FlashMessageLevel";
private Fixture _autoFixture;
private EditStopDateViewModel _viewModel;

[SetUp]
public void Arrange()
{
_mockModelMapper = new Mock<IModelMapper>();
_mockCookieStorageService = new Mock<ICookieStorageService<IndexRequest>>();
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>();
_mockLinkGenerator = new Mock<ILinkGenerator>();
_autoFixture = new Fixture();
_autoFixture.Customize<EditStopDateViewModel>(c => c.Without(x => x.NewStopDate));
_viewModel = _autoFixture.Create<EditStopDateViewModel>();
_viewModel.NewStopDate = new CommitmentsV2.Shared.Models.MonthYearModel("062020");

_controller = new ApprenticeController(_mockModelMapper.Object,
_mockCookieStorageService.Object,
_mockCommitmentsApiClient.Object,
_mockLinkGenerator.Object,
Mock.Of<ILogger<ApprenticeController>>(),
Mock.Of<IAuthorizationService>());
_controller.TempData = new TempDataDictionary(new Mock<HttpContext>().Object, new Mock<ITempDataProvider>().Object);
}

[Test]
public async Task AndSubmit_ThenCommitmentsApiUpdateApprenticeshipStopDateIsCalled()
{
//Act
var result = await _controller.UpdateApprenticeshipStopDate(_viewModel) as RedirectToActionResult;

//Assert
_mockCommitmentsApiClient.Verify(p =>
p.UpdateApprenticeshipStopDate(It.IsAny<long>(), It.IsAny<ApprenticeshipStopDateRequest>(), It.IsAny<CancellationToken>()), Times.Once);
}

[Test]
public async Task AndAfterUpdateDate_ThenRedirectToApprenticeDetailsPage()
{
//Act
var result = await _controller.UpdateApprenticeshipStopDate(_viewModel) as RedirectToActionResult;

//Assert
Assert.AreEqual("ApprenticeshipDetails", result.ActionName);
}

[Test]
public async Task AndAfterUpdateDate_ThenRedirectToApprenticeDetailsPageWithFlashMessage()
{
//Act
var result = await _controller.UpdateApprenticeshipStopDate(_viewModel) as RedirectToActionResult;

//Assert
Assert.AreEqual("ApprenticeshipDetails", result.ActionName);
Assert.IsTrue(_controller.TempData.Values.Contains(ApprenticeEditStopDate));
Assert.IsTrue(_controller.TempData.ContainsKey(FlashMessage));
Assert.IsTrue(_controller.TempData.ContainsKey(FlashMessageLevel));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using AutoFixture;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice;
using System.Threading;
using System.Threading.Tasks;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice
{
public class EditStopDateRequestToViewModelMapperTests
{
private Mock<ICommitmentsApiClient> _mockCommitmentsApiClient;
private Mock<ILogger<EditStopDateRequestToViewModelMapper>> _logger;
private EditStopDateRequest _request;
private GetApprenticeshipResponse _apprenticeshipResponse;
private EditStopDateRequestToViewModelMapper _mapper;

[SetUp]
public void Arrange()
{
var _autoFixture = new Fixture();
_request = _autoFixture.Create<EditStopDateRequest>();

_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>();
_logger = new Mock<ILogger<EditStopDateRequestToViewModelMapper>>();
_apprenticeshipResponse = _autoFixture.Create<GetApprenticeshipResponse>();
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>();
_mockCommitmentsApiClient.Setup(m => m.GetApprenticeship(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(_apprenticeshipResponse);


_mapper = new EditStopDateRequestToViewModelMapper(_mockCommitmentsApiClient.Object, _logger.Object);
}

[Test]
public async Task ApprenticeshipHashedId_IsMapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
Assert.AreEqual(_request.ApprenticeshipHashedId, result.ApprenticeshipHashedId);
}

[Test]
public async Task AccountHashedId_IsMapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
Assert.AreEqual(_request.AccountHashedId, result.AccountHashedId);
}

[Test]
public async Task ApprenticeshipId_IsMapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
Assert.AreEqual(_request.ApprenticeshipId, result.ApprenticeshipId);
}

[Test]
public async Task WhenRequestingEditStopDate_ThenTheGetApprenticeshipIsCalled()
{
//Act
var result = await _mapper.Map(_request);

//Assert
_mockCommitmentsApiClient.Verify(m => m.GetApprenticeship(_request.ApprenticeshipId, It.IsAny<CancellationToken>()), Times.Once());
}

[Test]
public async Task ApprenticeshipULN_IsMapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
Assert.AreEqual(_apprenticeshipResponse.Uln, result.ApprenticeshipULN);
}

[Test]
public async Task ApprenticeshipStartDate_IsMapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
Assert.AreEqual(_apprenticeshipResponse.StartDate, result.ApprenticeshipStartDate);
}

[Test]
public async Task CurrentStopDate_IsMapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
Assert.AreEqual(_apprenticeshipResponse.StopDate.Value, result.CurrentStopDate);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using AutoFixture;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Authentication;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice;
using System;
using System.Threading.Tasks;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice
{
public class EditStopDateViewModelToApprenticeshipStopDateRequestMapperTests
{
private EditStopDateViewModelToApprenticeshipStopDateRequestMapper _mapper;
private Mock<IAuthenticationService> _mockAuthenticationService;
private Fixture _autoFixture;
private EditStopDateViewModel _viewModel;

[SetUp]
public void Arrange()
{
_mockAuthenticationService = new Mock<IAuthenticationService>();
_mockAuthenticationService.Setup(x => x.UserInfo).Returns(It.IsAny<UserInfo>());
_autoFixture = new Fixture();
_autoFixture.Customize<EditStopDateViewModel>(c => c.Without(x => x.NewStopDate));
_mapper = new EditStopDateViewModelToApprenticeshipStopDateRequestMapper(_mockAuthenticationService.Object);
_viewModel = _autoFixture.Create<EditStopDateViewModel>();
_viewModel.NewStopDate = new CommitmentsV2.Shared.Models.MonthYearModel("062020");
}

[Test]
public async Task ApprenticeshipHashedId_IsMapped()
{
//Act
var result = await _mapper.Map(_viewModel);

//Assert
Assert.AreEqual(_viewModel.AccountId, result.AccountId);
}

[Test]
public async Task NewStopDate_IsMapped()
{
//Act
var result = await _mapper.Map(_viewModel);

//Assert
Assert.AreEqual(new DateTime(_viewModel.NewStopDate.Year.Value, _viewModel.NewStopDate.Month.Value, _viewModel.NewStopDate.Day.Value), result.NewStopDate);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="7.13.2" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="7.13.2" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="7.17.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="7.17.0" />
<PackageReference Include="SFA.DAS.Testing" Version="3.0.22" />
<PackageReference Include="SFA.DAS.Testing.AutoFixture" Version="3.0.121" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 8b40e41

Please sign in to comment.