public WhenGettingReadyForReviewFixture()
        {
            var autoFixture = new Fixture();

            _request   = autoFixture.Create <CohortsByAccountRequest>();
            _viewModel = autoFixture.Create <ReviewViewModel>();

            var modelMapper = new Mock <IModelMapper>();

            modelMapper.Setup(x => x.Map <ReviewViewModel>(It.Is <CohortsByAccountRequest>(r => r == _request)))
            .ReturnsAsync(_viewModel);

            _linkGeneratorResult = autoFixture.Create <string>();
            var linkGenerator = new Mock <ILinkGenerator>();

            linkGenerator.Setup(x => x.CommitmentsLink(It.IsAny <string>()))
            .Returns(_linkGeneratorResult);

            CohortController = new CohortController(Mock.Of <ICommitmentsApiClient>(),
                                                    Mock.Of <ILogger <CohortController> >(),
                                                    linkGenerator.Object,
                                                    modelMapper.Object,
                                                    Mock.Of <IAuthorizationService>(),
                                                    Mock.Of <IEncodingService>());
        }
Esempio n. 2
0
        public void ThenValidatesAccountHashedId(string accountHashedId, bool expectedValid)
        {
            var request = new CohortsByAccountRequest {
                AccountHashedId = accountHashedId
            };

            AssertValidationResult(x => x.AccountHashedId, request, expectedValid);
        }
        public async Task ThenMapperIsCalled(
            [Frozen] Mock <IModelMapper> modelMapper,
            CohortsByAccountRequest request,
            CohortController controller)
        {
            await controller.Draft(request);

            modelMapper.Verify(x => x.Map <DraftViewModel>(request), Times.Once);
        }
        public async Task ThenViewIsReturned(
            [Frozen] Mock <IModelMapper> modelMapper,
            CohortsByAccountRequest request,
            DraftViewModel viewModel,
            CohortController controller)
        {
            modelMapper
            .Setup(x => x.Map <DraftViewModel>(request))
            .ReturnsAsync(viewModel);

            var result = await controller.Draft(request) as ViewResult;

            Assert.NotNull(result);
            Assert.AreEqual(result.Model, viewModel);
        }
        public WhenMappingWithTrainingProviderRequestToViewModelFixture()
        {
            EncodingService      = new Mock <IEncodingService>();
            CommitmentsApiClient = new Mock <ICommitmentsApiClient>();

            CohortsByAccountRequest = new CohortsByAccountRequest()
            {
                AccountId = AccountId, AccountHashedId = AccountHashedId
            };
            GetCohortsResponse = CreateGetCohortsResponse();

            CommitmentsApiClient.Setup(c => c.GetCohorts(It.Is <GetCohortsRequest>(r => r.AccountId == AccountId), CancellationToken.None)).Returns(Task.FromResult(GetCohortsResponse));
            EncodingService.Setup(x => x.Encode(It.IsAny <long>(), EncodingType.CohortReference)).Returns((long y, EncodingType z) => y + "_Encoded");

            Mapper = new WithTrainingProviderRequestViewModelMapper(CommitmentsApiClient.Object, EncodingService.Object, Mock.Of <IUrlHelper>());
        }
        public WhenGettingCohortsWithTransferSenderFixture()
        {
            var autoFixture = new Fixture();

            _request   = autoFixture.Create <CohortsByAccountRequest>();
            _viewModel = autoFixture.Create <WithTransferSenderViewModel>();

            var modelMapper = new Mock <IModelMapper>();

            modelMapper.Setup(x => x.Map <WithTransferSenderViewModel>(It.Is <CohortsByAccountRequest>(r => r == _request)))
            .ReturnsAsync(_viewModel);

            CohortController = new CohortController(Mock.Of <ICommitmentsApiClient>(),
                                                    Mock.Of <ILogger <CohortController> >(),
                                                    Mock.Of <ILinkGenerator>(),
                                                    modelMapper.Object,
                                                    Mock.Of <IAuthorizationService>());
        }
        public WhenMappingDraftRequestToViewModelFixture()
        {
            EncodingService      = new Mock <IEncodingService>();
            CommitmentsApiClient = new Mock <ICommitmentsApiClient>();

            DraftRequest = new CohortsByAccountRequest()
            {
                AccountId = AccountId, AccountHashedId = AccountHashedId
            };
            GetCohortsResponse = CreateGetCohortsResponse();

            CommitmentsApiClient.Setup(c => c.GetCohorts(It.Is <GetCohortsRequest>(r => r.AccountId == AccountId), CancellationToken.None)).Returns(Task.FromResult(GetCohortsResponse));
            EncodingService.Setup(x => x.Encode(It.IsAny <long>(), EncodingType.CohortReference)).Returns((long y, EncodingType z) => y + "_Encoded");

            UrlHelper = new Mock <IUrlHelper>();
            UrlHelper.Setup(x => x.Action(It.IsAny <UrlActionContext>())).Returns <UrlActionContext>((ac) => $"http://{ac.Controller}/{ac.Action}/");

            Mapper = new DraftRequestMapper(CommitmentsApiClient.Object, EncodingService.Object, UrlHelper.Object);
        }
Esempio n. 8
0
        public async Task <IActionResult> WithTransferSender(CohortsByAccountRequest request)
        {
            var viewModel = await _modelMapper.Map <WithTransferSenderViewModel>(request);

            return(View(viewModel));
        }
Esempio n. 9
0
        public async Task <IActionResult> Draft(CohortsByAccountRequest request)
        {
            var viewModel = await _modelMapper.Map <DraftViewModel>(request);

            return(View(viewModel));
        }
Esempio n. 10
0
        public async Task <IActionResult> Review(CohortsByAccountRequest request)
        {
            var reviewViewModel = await _modelMapper.Map <ReviewViewModel>(request);

            return(View(reviewViewModel));
        }
Esempio n. 11
0
        private void AssertValidationResult <T>(Expression <Func <CohortsByAccountRequest, T> > property, CohortsByAccountRequest instance, bool expectedValid)
        {
            var validator = new CohortsByAccountRequestValidator();

            if (expectedValid)
            {
                validator.ShouldNotHaveValidationErrorFor(property, instance);
            }
            else
            {
                validator.ShouldHaveValidationErrorFor(property, instance);
            }
        }