Exemple #1
0
        public async Task And_Throws_Exception_Then_Returns_Bad_Request(
            long accountId,
            long accountLegalEntityId,
            GetEligibleApprenticeshipsSearchResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] EligibleApprenticeshipSearchController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetEligibleApprenticeshipsSearchQuery>(),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

            var controllerResult = await controller.GetEligibleApprentices(accountId, accountLegalEntityId) as StatusCodeResult;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Exemple #2
0
        public async Task Then_Gets_Eligible_Apprentices_From_Mediator(
            long accountId,
            long accountLegalEntityId,
            GetEligibleApprenticeshipsSearchResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] EligibleApprenticeshipSearchController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetEligibleApprenticeshipsSearchQuery>(c =>
                                                                     c.AccountId.Equals(accountId) &&
                                                                     c.AccountLegalEntityId.Equals(accountLegalEntityId)),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.GetEligibleApprentices(accountId, accountLegalEntityId) as ObjectResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as IEnumerable <EligibleApprenticeshipDto>;

            Assert.IsNotNull(model);
            model.Count().Should().Be(mediatorResult.Apprentices.Length);
        }