public async Task HandleAsync_GivenWeeeReceivedDeselected_DeleteMethodsCalled()
        {
            var request = new AddReturnReportOn()
            {
                ReturnId          = Guid.NewGuid(),
                SelectedOptions   = CreateSelectedOptions(),
                DeselectedOptions = new List <int>()
                {
                    1
                },
                Options          = CreateReportQuestions(),
                DcfSelectedValue = true
            };

            var weeeReceived = A.Fake <WeeeReceived>();

            A.CallTo(() => weeeReceived.Id).Returns(Guid.NewGuid());
            A.CallTo(() => dataAccess.GetManyByReturnId <WeeeReceived>(request.ReturnId)).Returns(new List <WeeeReceived>()
            {
                weeeReceived
            });

            await handler.HandleAsync(request);

            A.CallTo(() => dataAccess.GetManyByExpression(A <WeeeReceivedAmountByWeeeReceivedIdSpecification> ._)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => dataAccess.RemoveMany <WeeeReceivedAmount>(A <IList <WeeeReceivedAmount> > ._)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => dataAccess.RemoveMany <WeeeReceived>(A <IList <WeeeReceived> > ._)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => dataAccess.RemoveMany <ReturnScheme>(A <IList <ReturnScheme> > ._)).MustHaveHappened(Repeated.Exactly.Once);
        }
Example #2
0
        public async Task <bool> HandleAsync(AddReturnReportOn message)
        {
            authorization.EnsureCanAccessExternalArea();

            if (message.DeselectedOptions != null && message.DeselectedOptions.Count != 0)
            {
                foreach (var deselected in message.DeselectedOptions)
                {
                    switch (deselected)
                    {
                    case (int)ReportOnQuestionEnum.WeeeReceived:
                        await DeleteWeeeReceivedData(message.ReturnId);

                        break;

                    case (int)ReportOnQuestionEnum.WeeeSentOn:
                        await DeleteWeeeSentOnData(message.ReturnId);

                        break;

                    case (int)ReportOnQuestionEnum.WeeeReused:
                        await DeleteWeeeReusedData(message.ReturnId);

                        break;

                    case (int)ReportOnQuestionEnum.NonObligated:
                        await DeleteNonObligatedData(message.ReturnId, false);

                        break;

                    case (int)ReportOnQuestionEnum.NonObligatedDcf:
                        await DeleteNonObligatedData(message.ReturnId, true);

                        break;

                    default:
                        break;
                    }
                }
            }

            var oldReturnOptions = await dataAccess.GetManyByReturnId <ReturnReportOn>(message.ReturnId);

            dataAccess.RemoveMany <ReturnReportOn>(oldReturnOptions);

            await context.SaveChangesAsync();

            if (message.SelectedOptions != null && message.SelectedOptions.Any())
            {
                var returnReportOn = new List <ReturnReportOn>();

                foreach (var option in message.SelectedOptions)
                {
                    returnReportOn.Add(new ReturnReportOn(message.ReturnId, option));
                }

                if (message.DcfSelectedValue)
                {
                    var isParentSelected = message.SelectedOptions.Contains((int?)ReportOnQuestionEnum.NonObligated ?? default(int));

                    if (isParentSelected)
                    {
                        returnReportOn.Add(new ReturnReportOn(message.ReturnId, (int)ReportOnQuestionEnum.NonObligatedDcf));
                    }
                }

                await dataAccess.AddMany <ReturnReportOn>(returnReportOn);
            }
            return(true);
        }