Exemplo n.º 1
0
        public async Task <List <Guid> > Submit(List <ReturnScheme> schemes)
        {
            context.ReturnScheme.AddRange(schemes);

            await context.SaveChangesAsync();

            return(schemes.Select(s => s.Id).ToList());
        }
Exemplo n.º 2
0
        public async Task <Guid> Add <TEntity>(TEntity entity) where TEntity : Entity
        {
            context.Set <TEntity>().Add(entity);

            await context.SaveChangesAsync();

            return(entity.Id);
        }
Exemplo n.º 3
0
        public async Task SetFixedDate(DateTime date)
        {
            var systemData = await systemDataDataAccess.Get();

            systemData.UpdateFixedCurrentDate(date);

            await context.SaveChangesAsync();
        }
        public async void AddCompetentAuthorityUserHandler_ReturnsCompetentAuthorityId()
        {
            AddCompetentAuthorityUser message = new AddCompetentAuthorityUser(InternalUserId.ToString());
            var id = await handler.HandleAsync(message);

            A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened();
            Assert.NotNull(id);
        }
        public Task Submit(IEnumerable <NonObligatedWeee> nonObligated)
        {
            foreach (var nonObligatedWeee in nonObligated)
            {
                context.NonObligatedWeee.Add(nonObligatedWeee);
            }

            return(context.SaveChangesAsync());
        }
Exemplo n.º 6
0
        public void Submit_GivenReusedSiteData_SaveChangesAsyncShouldBeCalled()
        {
            var site = new WeeeReusedSite();

            dataAccess.Submit(site);

            A.CallTo(() => context.WeeeReusedSite.Add(site)).MustHaveHappened(Repeated.Exactly.Once)
            .Then(A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once));
        }
        public async Task Submit_GivenSchemeAddedToContext_ChangesShouldBeSaved()
        {
            var items = A.Fake <List <ReturnScheme> >();

            await dataAccess.Submit(items);

            A.CallTo(() => context.ReturnScheme.AddRange(items)).MustHaveHappened().Then(
                A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once));
        }
Exemplo n.º 8
0
        public async Task <Guid> HandleAsync(CopyReturn message)
        {
            authorization.EnsureCanAccessExternalArea();

            var returnCopy = await context.Returns.Include(r => r.Organisation).FirstOrDefaultAsync(r => r.Id == message.ReturnId);

            if (returnCopy == null)
            {
                throw new ArgumentException($"No return was found with id {message.ReturnId}.");
            }

            authorization.EnsureOrganisationAccess(returnCopy.Organisation.Id);

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    await CopyReturnReportsOn(message, returnCopy);

                    await CopyReturnSchemes(message, returnCopy);

                    await CopyReturnNonObligated(message, returnCopy);

                    CopyReturnReceived(message, returnCopy);

                    CopyReturnSentOn(message, returnCopy);

                    CopyReturnReused(message, returnCopy);

                    CopyReturn(message, returnCopy);

                    await context.SaveChangesAsync();

                    await RemoveAatfsWithInvalidApprovalDate(returnCopy);

                    await context.SaveChangesAsync();

                    await RemoveAnyDuplicateNonObligatedAndSave(returnCopy);

                    transaction.Commit();

                    return(@returnCopy.Id);
                }
                catch
                {
                    transaction.Rollback();

                    throw;
                }
                finally
                {
                    transaction.Dispose();
                }
            }
        }
Exemplo n.º 9
0
        public void Submit_GivenAmounts_AddRangeAndSaveChangesShouldBeCalled()
        {
            var list = new List <WeeeReceivedAmount>();

            A.CallTo(() => context.Set <WeeeReceivedAmount>()).Returns(dbHelper.GetAsyncEnabledDbSet(list));

            dataAccess.Submit(list);

            A.CallTo(() => context.Set <WeeeReceivedAmount>().AddRange(A <IEnumerable <WeeeReceivedAmount> > .That.Matches(c => c.Equals(list)))).MustHaveHappened(Repeated.Exactly.Once).Then(
                A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once));
        }
Exemplo n.º 10
0
        public async Task HandleAsync_GivenReturn_StatusShouldBeUpdated(bool nilReturn)
        {
            var message = new SubmitReturn(Guid.NewGuid(), nilReturn);
            var @return = A.Fake <Return>();
            var userId  = Guid.NewGuid();

            A.CallTo(() => @return.ReturnStatus).Returns(Domain.AatfReturn.ReturnStatus.Created);
            A.CallTo(() => genericDataAccess.GetById <Return>(message.ReturnId)).Returns(@return);
            A.CallTo(() => userContext.UserId).Returns(userId);

            await handler.HandleAsync(message);

            A.CallTo(() => @return.UpdateSubmitted(userId.ToString(), nilReturn)).MustHaveHappened(Repeated.Exactly.Once)
            .Then(A.CallTo(() => weeeContext.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once));
        }
Exemplo n.º 11
0
        public async Task <Guid> HandleAsync(MemberUploadSubmission message)
        {
            authorization.EnsureOrganisationAccess(message.OrganisationId);

            var memberUpload = await context.MemberUploads.SingleOrDefaultAsync(m => m.Id == message.MemberUploadId);

            if (memberUpload == null)
            {
                throw new ArgumentNullException(string.Format("Could not find a MemberUpload with id {0}", message.MemberUploadId));
            }

            if (memberUpload.OrganisationId != message.OrganisationId)
            {
                throw new ArgumentException(string.Format("Member upload {0} is not owned by PCS {1}", message.MemberUploadId, message.OrganisationId));
            }

            if (!memberUpload.IsSubmitted)
            {
                User submittingUser = await domainUserContext.GetCurrentUserAsync();

                memberUpload.Submit(submittingUser);
                await context.SaveChangesAsync();
            }

            return(memberUpload.Id);
        }
Exemplo n.º 12
0
        public async Task <bool> HandleAsync(RemoveWeeeSentOn message)
        {
            authorization.EnsureCanAccessExternalArea();

            var weeeSentOn = await genericDataAccess.GetById <WeeeSentOn>(message.WeeeSentOnId);

            if (weeeSentOn == null)
            {
                return(false);
            }

            var weeeSentOnAmount = await obligatedWeeeDataAccess.FetchObligatedWeeeSentOnForReturn(message.WeeeSentOnId);

            genericDataAccess.Remove(weeeSentOn.SiteAddress);

            genericDataAccess.Remove(weeeSentOn.OperatorAddress);

            genericDataAccess.Remove(weeeSentOn);

            genericDataAccess.RemoveMany(weeeSentOnAmount);

            await context.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 13
0
        public async Task <bool> HandleAsync(SubmitReturn message)
        {
            authorization.EnsureCanAccessExternalArea();

            var @return = await genericDataAccess.GetById <Return>(message.ReturnId);

            if (@return == null)
            {
                throw new ArgumentException($"No return was found with id {message.ReturnId}.");
            }

            if (@return.ReturnStatus == ReturnStatus.Submitted)
            {
                return(true);
            }

            authorization.EnsureOrganisationAccess(@return.Organisation.Id);

            @return.UpdateSubmitted(userContext.UserId.ToString(), message.NilReturn);

            var aatfs = await fetchAatfDataAccess.FetchAatfByReturnQuarterWindow(@return);

            var returnAatfs = aatfs.Select(a => new ReturnAatf(a, @return));

            await genericDataAccess.AddMany <ReturnAatf>(returnAatfs);

            await weeeContext.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 14
0
        public async Task <Guid> HandleAsync(AddContactPerson message)
        {
            authorization.EnsureOrganisationAccess(message.OrganisationId);

            var contactPerson = ValueObjectInitializer.CreateContact(message.ContactPerson);

            Guid id;

            if (message.ContactId.HasValue)
            {
                var contact = await dataAccess.GetById <Contact>(message.ContactId.Value);

                contact.Overwrite(contactPerson);

                id = contact.Id;
            }
            else
            {
                id = await dataAccess.Add <Contact>(contactPerson);
            }

            await db.SaveChangesAsync();

            return(id);
        }
        public async Task <int> UpdateUserRoleAndStatus(CompetentAuthorityUser user, Role role, UserStatus status)
        {
            user.UpdateUserStatus(status.ToDomainEnumeration <Domain.User.UserStatus>());
            user.UpdateRole(role);

            return(await context.SaveChangesAsync());
        }
Exemplo n.º 16
0
        public async Task <Guid> Submit(Return aatfReturn)
        {
            context.Returns.Add(aatfReturn);

            await context.SaveChangesAsync();

            return(aatfReturn.Id);
        }
Exemplo n.º 17
0
        public async Task <Guid> HandleAsync(CreatePartnershipRequest message)
        {
            authorization.EnsureCanAccessExternalArea();

            var organisation = Organisation.CreatePartnership(message.TradingName);

            db.Organisations.Add(organisation);

            await db.SaveChangesAsync();

            var organisationUser = new OrganisationUser(userContext.UserId, organisation.Id, UserStatus.Active);

            db.OrganisationUsers.Add(organisationUser);

            await db.SaveChangesAsync();

            return(organisation.Id);
        }
Exemplo n.º 18
0
        public Task Submit(IEnumerable <WeeeReusedAmount> aatfWeeeReusedAmounts)
        {
            foreach (var aatfWeeeReused in aatfWeeeReusedAmounts)
            {
                context.WeeeReusedAmount.Add(aatfWeeeReused);
            }

            return(context.SaveChangesAsync());
        }
Exemplo n.º 19
0
        private static async Task <Scheme> CreateScheme(WeeeContext context, Organisation organisation)
        {
            var scheme = ObligatedWeeeIntegrationCommon.CreateScheme(organisation);

            context.Schemes.Add(scheme);

            await context.SaveChangesAsync();

            return(scheme);
        }
Exemplo n.º 20
0
        public void UpdateDetails_GivenNewData_SaveChangesAsyncShouldBeCalled()
        {
            var oldDetails = A.Fake <Aatf>();
            var newDetails = fixture.Create <Aatf>();

            dataAccess.UpdateDetails(oldDetails, newDetails);

            A.CallTo(() => oldDetails.UpdateDetails(
                         newDetails.Name,
                         newDetails.CompetentAuthority,
                         newDetails.ApprovalNumber,
                         newDetails.AatfStatus,
                         newDetails.Organisation,
                         newDetails.Size,
                         newDetails.ApprovalDate,
                         newDetails.LocalArea,
                         newDetails.PanArea)).MustHaveHappenedOnceExactly()
            .Then(A.CallTo(() => context.SaveChangesAsync()).MustHaveHappenedOnceExactly());
        }
Exemplo n.º 21
0
        public async Task <Guid> HandleAsync(CreateRegisteredCompanyRequest message)
        {
            authorization.EnsureCanAccessExternalArea();

            var organisation = Organisation.CreateRegisteredCompany(message.BusinessName,
                                                                    message.CompanyRegistrationNumber, message.TradingName);

            db.Organisations.Add(organisation);

            await db.SaveChangesAsync();

            var organisationUser = new OrganisationUser(userContext.UserId, organisation.Id, UserStatus.Active);

            db.OrganisationUsers.Add(organisationUser);

            await db.SaveChangesAsync();

            return(organisation.Id);
        }
Exemplo n.º 22
0
        public async void JoinOrganisation_OrganisationUserExistsWithNonRejectedStatus_ReturnsFailure_AndDoesNotSaveAnyChanges(Core.Shared.UserStatus userStatus)
        {
            var organisationId = Guid.NewGuid();
            var userId         = Guid.NewGuid();

            A.CallTo(() => context.OrganisationUsers)
            .Returns(contextHelper.GetAsyncEnabledDbSet(new List <OrganisationUser>
            {
                ValidOrganisationUser(userId, organisationId, userStatus)
            }));

            var result =
                await JoinOrganisationDataAccess()
                .JoinOrganisation(new OrganisationUser(userId, organisationId, UserStatus.Pending));

            Assert.False((result).Successful);

            A.CallTo(() => context.SaveChangesAsync())
            .MustNotHaveHappened();
        }
Exemplo n.º 23
0
        private static async Task <Return> CreateReturn(WeeeContext context, DatabaseWrapper database, Organisation organisation)
        {
            var @return = ObligatedWeeeIntegrationCommon.CreateReturn(organisation, database.Model.AspNetUsers.First().Id);

            context.Organisations.Add(organisation);
            context.Returns.Add(@return);

            await context.SaveChangesAsync();

            return(@return);
        }
Exemplo n.º 24
0
        public async Task InsertNonObligatedWeee(Guid returnId, IEnumerable <NonObligatedWeee> nonObligatedWeees)
        {
            var allAssociatedWithReturn = await FetchNonObligatedWeeeForReturn(returnId);

            foreach (var noWeee in nonObligatedWeees)
            {
                var group = allAssociatedWithReturn.Where(e => e.Dcf == noWeee.Dcf && e.CategoryId == noWeee.CategoryId);
                if (group.Count() == 0)
                {
                    context.NonObligatedWeee.Add(noWeee);
                }
                else
                {
                    group.First().UpdateTonnage(noWeee.Tonnage);
                    context.NonObligatedWeee.RemoveRange(group.Skip(1)); // Remove any additional ones
                }
            }

            await context.SaveChangesAsync();

            return;
        }
Exemplo n.º 25
0
        public async void ProcessXmlfile_ParsesXMLFile_SavesValidProducers()
        {
            IEnumerable <ProducerSubmission> generatedProducers = new[] { TestProducer("ForestMoonOfEndor") };

            A.CallTo(() => generator.GenerateProducers(Message, A <MemberUpload> .Ignored, A <Dictionary <string, ProducerCharge> > .Ignored))
            .Returns(Task.FromResult(generatedProducers));
            SetupSchemeTypeComplianceYear();

            await handler.HandleAsync(Message);

            A.CallTo(() => producerSubmissionDataAccess.AddRange(generatedProducers)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened();
        }
Exemplo n.º 26
0
        public async Task SaveAsync_Always_CallsSaveOnContext()
        {
            // Arrange
            WeeeContext context = A.Fake <WeeeContext>();

            OrganisationDetailsDataAccess dataAccess = new OrganisationDetailsDataAccess(context);

            // Act
            await dataAccess.SaveAsync();

            // Assert
            A.CallTo(() => context.SaveChangesAsync())
            .MustHaveHappened(Repeated.Exactly.Once);
        }
Exemplo n.º 27
0
        public async void SchemeDoesExist_SetsSchemeStatus_AndSavesChanges(SchemeStatus status)
        {
            var scheme = new Scheme(Guid.NewGuid());

            A.CallTo(() => context.Schemes)
            .Returns(dbContextHelper.GetAsyncEnabledDbSet(new List <Scheme>
            {
                scheme
            }));

            await SetSchemeStatusHandler().HandleAsync(new SetSchemeStatus(scheme.Id, status));

            Assert.Equal(status.ToDomainEnumeration <Domain.Scheme.SchemeStatus>(), context.Schemes.Single().SchemeStatus);
            A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once);
        }
Exemplo n.º 28
0
        private async Task <List <WeeeSentOnAmount> > AppendWeeeSentOnAmountToWeeeSentOn(WeeeContext context, WeeeSentOn weeeSentOn)
        {
            var weeeSentOnAmountList = new List <WeeeSentOnAmount>();

            foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>())
            {
                weeeSentOnAmountList.Add(new WeeeSentOnAmount(weeeSentOn, (int)category, (decimal?)category, (decimal?)category + 1));
            }

            context.WeeeSentOnAmount.AddRange(weeeSentOnAmountList);

            await context.SaveChangesAsync();

            return(weeeSentOnAmountList);
        }
        public async Task <Guid> HandleAsync(AddAddressToOrganisation message)
        {
            authorization.EnsureOrganisationAccess(message.OrganisationId);

            var addresstype = ValueObjectInitializer.GetAddressType(message.TypeOfAddress);

            if (await db.Organisations.FirstOrDefaultAsync(o => o.Id == message.OrganisationId) == null)
            {
                throw new ArgumentException(string.Format("Could not find an organisation with id {0}",
                                                          message.OrganisationId));
            }

            var organisation = await db.Organisations.SingleAsync(o => o.Id == message.OrganisationId);

            if (await db.Countries.FirstOrDefaultAsync(c => c.Id == message.Address.CountryId) == null)
            {
                throw new ArgumentException(string.Format("Could not find country with id {0}",
                                                          message.Address.CountryId));
            }

            var country = await db.Countries.SingleAsync(c => c.Id == message.Address.CountryId);

            message.Address.CountryName = country.Name;
            var address = ValueObjectInitializer.CreateAddress(message.Address, country);

            if (addresstype.Equals(AddressType.SchemeAddress))
            {
                if (message.AddressId.HasValue)
                {
                    var findAddress = await db.Addresses.SingleAsync(a => a.Id == message.AddressId.Value);

                    findAddress.Overwrite(address);
                    address = findAddress;
                }
                else
                {
                    db.Addresses.Add(address);
                }
            }
            else
            {
                organisation.AddOrUpdateAddress(addresstype, address);
            }

            await db.SaveChangesAsync();

            return(GetAddressId(addresstype, organisation, address));
        }
Exemplo n.º 30
0
        public async Task <Guid> HandleAsync(SetSchemeStatus message)
        {
            authorization.EnsureCanAccessInternalArea();

            var scheme = await context.Schemes.SingleOrDefaultAsync(s => s.Id == message.PcsId);

            if (scheme != null)
            {
                scheme.SetStatus(message.Status.ToDomainEnumeration <SchemeStatus>());
                await context.SaveChangesAsync();

                return(message.PcsId);
            }

            throw new InvalidOperationException(string.Format("Scheme with Id '{0}' does not exist", message.PcsId));
        }