private async Task <ActionResult> SaveAndContinue(SchemeDataList existingSchemes, List <Guid> schemeIdsToAdd, Guid returnId)
        {
            using (var client = this.apiClient())
            {
                foreach (var scheme in existingSchemes.SchemeDataItems)
                {
                    if (schemeIdsToAdd.Contains(scheme.Id))
                    {
                        schemeIdsToAdd.Remove(scheme.Id);
                    }
                }

                if (schemeIdsToAdd != null && schemeIdsToAdd.Count > 0)
                {
                    var request = new AddReturnScheme
                    {
                        ReturnId  = returnId,
                        SchemeIds = schemeIdsToAdd
                    };
                    await client.SendAsync(this.User.GetAccessToken(), request);
                }

                return(AatfRedirect.TaskList(returnId));
            }
        }
        public async Task HandleAsync_GivenAddReturnSchemeRequest_ReturnShouldBeRetrieved()
        {
            var returnId = Guid.NewGuid();

            var request = new AddReturnScheme {
                ReturnId = returnId, SchemeIds = new List <Guid>()
            };

            await handler.HandleAsync(request);

            A.CallTo(() => returnDataAccess.GetById(returnId)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public async Task HandleAsync_GivenAddReturnSchemeRequest_ReturnSchemeIdShouldBeReturned()
        {
            var request = new AddReturnScheme {
                ReturnId = Guid.NewGuid(), SchemeIds = fixture.CreateMany <Guid>().ToList()
            };
            var id = fixture.CreateMany <Guid>().ToList();

            A.CallTo(() => returnSchemeDataAccess.Submit(A <List <ReturnScheme> > ._)).Returns(id);

            var result = await handler.HandleAsync(request);

            result.Should().Equal(id);
        }
        public async Task HandleAsync_GivenAddReturnSchemeRequest_SchemeShouldBeRetrieved()
        {
            var schemeIds = fixture.CreateMany <Guid>().ToList();

            var request = new AddReturnScheme {
                SchemeIds = schemeIds
            };

            await handler.HandleAsync(request);

            foreach (var schemeId in schemeIds)
            {
                A.CallTo(() => schemeDataAccess.GetSchemeOrDefault(schemeId)).MustHaveHappened(Repeated.Exactly.Once);
            }
        }
Beispiel #5
0
        public async Task <List <Guid> > HandleAsync(AddReturnScheme message)
        {
            authorization.EnsureCanAccessExternalArea();

            var @return = await returnDataAccess.GetById(message.ReturnId);

            var returnSchemes = new List <ReturnScheme>();

            foreach (var schemeId in message.SchemeIds)
            {
                var scheme = await schemeDataAccess.GetSchemeOrDefault(schemeId);

                returnSchemes.Add(new ReturnScheme(scheme, @return));
            }

            return(await returnSchemeDataAccess.Submit(returnSchemes));
        }
        public async Task HandleAsync_GivenAddReturnSchemeRequest_DataAccessSubmitsIsCalled()
        {
            var schemeId = Guid.NewGuid();
            var request  = new AddReturnScheme {
                ReturnId = Guid.NewGuid(), SchemeIds = new List <Guid> {
                    schemeId
                }
            };

            var @return = A.Dummy <Return>();
            var scheme  = A.Fake <Domain.Scheme.Scheme>();

            A.CallTo(() => schemeDataAccess.GetSchemeOrDefault(schemeId)).Returns(scheme);

            A.CallTo(() => returnDataAccess.GetById(request.ReturnId)).Returns(@return);

            await handler.HandleAsync(request);

            A.CallTo(() => returnSchemeDataAccess.Submit(A <List <ReturnScheme> > .That.Matches(c => c.First().ReturnId == @return.Id && c.First().SchemeId == scheme.Id))).MustHaveHappened(Repeated.Exactly.Once);
        }