Пример #1
0
        public async Task HandleAsync_GivenMessage_AatfDeleteFlagsShouldBeValidated()
        {
            var message = fixture.Create <CheckAatfCanBeDeleted>();
            var aatf    = GetAatf(message.AatfId);

            A.CallTo(() => aatfDataAccess.GetDetails(message.AatfId)).Returns(aatf);

            await handler.HandleAsync(message);

            A.CallTo(() => aatfDeletionStatus.Validate(aatf.Id)).MustHaveHappenedOnceExactly();
        }
Пример #2
0
        public async Task HandleAsync_GivenAatfCannotBeDeleted_InvalidOperationExceptionExpectedAndAatfShouldNotBeDeleted()
        {
            using (var databaseWrapper = new DatabaseWrapper())
            {
                var message      = fixture.Create <DeleteAnAatf>();
                var organisation = EA.Weee.Domain.Organisation.Organisation.CreatePartnership("trading");
                var aatf         = ObligatedWeeeIntegrationCommon.CreateAatf(databaseWrapper, organisation);

                databaseWrapper.WeeeContext.Aatfs.Add(aatf);

                await databaseWrapper.WeeeContext.SaveChangesAsync();

                databaseWrapper.WeeeContext.Aatfs.Where(a => a.Id == aatf.Id).Should().NotBeEmpty();

                var canAatfBeDeletedFlags = new CanAatfBeDeletedFlags();
                A.CallTo(() => getAatfDeletionStatus.Validate(message.AatfId)).Returns(canAatfBeDeletedFlags);

                var result = await Xunit.Record.ExceptionAsync(() => Handler(databaseWrapper).HandleAsync(message));

                result.Should().BeOfType <InvalidOperationException>();
            }
        }
        public async Task <AatfDeletionData> HandleAsync(CheckAatfCanBeDeleted message)
        {
            authorization.EnsureCanAccessInternalArea();
            authorization.EnsureUserInRole(Roles.InternalAdmin);

            var aatf = await aatfDataAccess.GetDetails(message.AatfId);

            var aatfDeletion = await getAatfDeletionStatus.Validate(aatf.Id);

            var organisationDeletion = await getOrganisationDeletionStatus.Validate(aatf.Organisation.Id, aatf.ComplianceYear, aatf.FacilityType);

            return(new AatfDeletionData(organisationDeletion, aatfDeletion));
        }
Пример #4
0
        public async Task <bool> HandleAsync(DeleteAnAatf message)
        {
            authorization.EnsureCanAccessInternalArea();
            authorization.EnsureUserInRole(Roles.InternalAdmin);

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    var aatfDeletionStatus = await getAatfDeletionStatus.Validate(message.AatfId);

                    if (!aatfDeletionStatus.HasFlag(CanAatfBeDeletedFlags.CanDelete))
                    {
                        throw new InvalidOperationException();
                    }

                    await aatfDataAccess.RemoveAatf(message.AatfId);

                    if (aatfDeletionStatus.HasFlag(CanAatfBeDeletedFlags.CanDeleteOrganisation))
                    {
                        await organisationDataAccess.Delete(message.OrganisationId);
                    }

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();

                    if (ex.InnerException != null)
                    {
                        throw ex.InnerException;
                    }

                    throw;
                }
                finally
                {
                    transaction.Dispose();
                }
            }

            return(true);
        }