public CreateCohortWithOtherPartyControllerTestFixture SetCreateCohortResponse(
                CreateCohortResponse createCohortResponse)
            {
                CommitmentsApiClientMock.Setup(c =>
                                               c.CreateCohort(It.IsAny <CreateCohortWithOtherPartyRequest>(), It.IsAny <CancellationToken>()))
                .ReturnsAsync(createCohortResponse);

                return(this);
            }
            public UnapprovedControllerTestFixture()
            {
                _autoFixture = new Fixture();

                _draftApprenticeshipHashedId = _autoFixture.Create <string>();
                _mediator        = new Mock <IMediator>();
                _mockModelMapper = new Mock <IModelMapper>();
                _linkGenerator   = new Mock <ILinkGenerator>();
                _encodingService = new Mock <IEncodingService>();

                _model = new AddDraftApprenticeshipViewModel
                {
                    ProviderId = _autoFixture.Create <int>(),
                    EmployerAccountLegalEntityPublicHashedId = _autoFixture.Create <string>(),
                    AccountLegalEntityId = _autoFixture.Create <long>(),
                    ReservationId        = _autoFixture.Create <Guid>()
                };

                _createCohortRequest = new CreateCohortRequest();
                _mockModelMapper
                .Setup(x => x.Map <CreateCohortRequest>(It.IsAny <AddDraftApprenticeshipViewModel>()))
                .ReturnsAsync(_createCohortRequest);

                _createCohortResponse = new CreateCohortResponse
                {
                    CohortId              = _autoFixture.Create <long>(),
                    CohortReference       = _autoFixture.Create <string>(),
                    DraftApprenticeshipId = null
                };

                _mediator.Setup(x => x.Send(It.IsAny <CreateCohortRequest>(), It.IsAny <CancellationToken>()))
                .ReturnsAsync(_createCohortResponse);

                _linkGeneratorRedirectUrl = _autoFixture.Create <string>();
                _linkGenerator.Setup(x => x.ProviderApprenticeshipServiceLink(It.IsAny <string>()))
                .Returns(_linkGeneratorRedirectUrl)
                .Callback((string value) => _linkGeneratorParameter = value);


                _controller = new CohortController(_mediator.Object, _mockModelMapper.Object, _linkGenerator.Object, Mock.Of <ICommitmentsApiClient>(), Mock.Of <IFeatureTogglesService <ProviderFeatureToggle> >(), _encodingService.Object);
            }
        public async Task PostMessage_WithValidRequest_ShouldAddCohortAndReturnRedirectResult(MessageViewModel model, CreateCohortResponse createCohortResponse)
        {
            _fixture.SetCreateCohortResponse(createCohortResponse);

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

            _fixture.VerifyAddCohortIsCalledWithCorrectMappedValues(model);


            var redirect = result.VerifyReturnsRedirectToActionResult();

            Assert.AreEqual(redirect.ActionName, "Finished");
            Assert.AreEqual(redirect.RouteValues["AccountHashedId"], model.AccountHashedId);
            Assert.AreEqual(redirect.RouteValues["CohortReference"], createCohortResponse.CohortReference);
        }
 public async Task Act()
 {
     _result = await _handler.Handle(_requestClone, CancellationToken.None);
 }