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); }
public async Task MemberUploadSubmissionHandler_SubmitMemberUpload_DoesNotUpdateRegisteredProducerRecord_ForDifferentScheme() { using (var database = new DatabaseWrapper()) { var helper = new ModelHelper(database.Model); string registrationNumber = "AAAA"; int complianceYear = 2016; var scheme1 = helper.CreateScheme(); var memberUpload1 = helper.CreateMemberUpload(scheme1); memberUpload1.ComplianceYear = complianceYear; memberUpload1.IsSubmitted = true; var registeredProducer1 = helper.GetOrCreateRegisteredProducer(scheme1, complianceYear, registrationNumber); var producerSubmission1 = helper.CreateProducerAsCompany(memberUpload1, registrationNumber); var scheme2 = helper.CreateScheme(); var memberUpload2 = helper.CreateMemberUpload(scheme2); memberUpload2.ComplianceYear = complianceYear; memberUpload2.IsSubmitted = false; var registeredProducer2 = helper.GetOrCreateRegisteredProducer(scheme2, complianceYear, registrationNumber); var producerSubmission2 = helper.CreateProducerAsCompany(memberUpload2, registrationNumber); // At least one user is required in the database. helper.GetOrCreateUser("A user"); database.Model.SaveChanges(); User user = await database.WeeeContext.Users.FirstAsync(); IDomainUserContext domainUserContext = A.Fake <IDomainUserContext>(); A.CallTo(() => domainUserContext.GetCurrentUserAsync()).Returns(user); var handler = new MemberUploadSubmissionHandler(A.Dummy <IWeeeAuthorization>(), database.WeeeContext, domainUserContext); await handler.HandleAsync(new MemberUploadSubmission(scheme2.OrganisationId, memberUpload2.Id)); var registeredProducerDb1 = FindRegisteredProducer(database, registeredProducer1.Id); var registeredProducerDb2 = FindRegisteredProducer(database, registeredProducer2.Id); Assert.Equal(registeredProducerDb1.CurrentSubmission.Id, producerSubmission1.Id); Assert.Equal(registeredProducerDb2.CurrentSubmission.Id, producerSubmission2.Id); } }
public async Task <IssuePendingChargesResult> HandleAsync(Requests.Charges.IssuePendingCharges message) { authorization.EnsureCanAccessInternalArea(true); authorization.EnsureUserInRole(Roles.InternalAdmin); UKCompetentAuthority authority = await dataAccess.FetchCompetentAuthority(message.Authority); IReadOnlyList <MemberUpload> memberUploads = await dataAccess.FetchSubmittedNonInvoicedMemberUploadsAsync(authority); User issuingUser = await domainUserContext.GetCurrentUserAsync(); InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, issuingUser); var result = new IssuePendingChargesResult(); result.Errors = new List <string>(); if (authority.Name == "Environment Agency") { ulong fileId = await GetNextIbisFileId(); IbisFileDataGeneratorResult ibisFileDataGeneratorResult = await ibisFileDataGenerator.CreateFileDataAsync(fileId, invoiceRun); result.Errors.AddRange(ibisFileDataGeneratorResult.Errors); if (result.Errors.Count == 0) { IbisFileData ibisFileData = ibisFileDataGeneratorResult.IbisFileData; invoiceRun.SetIbisFileData(ibisFileData); } } if (result.Errors.Count == 0) { await dataAccess.SaveAsync(invoiceRun); result.InvoiceRunId = invoiceRun.Id; } return(result); }
public async Task MemberUploadSubmissionHandler_SubmitMemberUpload_NewRegisteredProducer_ContainsCorrectValueFor_CurrentSubmission() { using (var database = new DatabaseWrapper()) { var helper = new ModelHelper(database.Model); var scheme = helper.CreateScheme(); string registrationNumber = "AAAA"; int complianceYear = 2016; var registeredProducer = helper.GetOrCreateRegisteredProducer(scheme, complianceYear, registrationNumber); var memberUpload = helper.CreateMemberUpload(scheme); memberUpload.ComplianceYear = complianceYear; memberUpload.IsSubmitted = false; var producerSubmission = helper.CreateProducerAsCompany(memberUpload, registrationNumber); // At least one user is required in the database. helper.GetOrCreateUser("A user"); database.Model.SaveChanges(); User user = await database.WeeeContext.Users.FirstAsync(); IDomainUserContext domainUserContext = A.Fake <IDomainUserContext>(); A.CallTo(() => domainUserContext.GetCurrentUserAsync()).Returns(user); var handler = new MemberUploadSubmissionHandler(A.Dummy <IWeeeAuthorization>(), database.WeeeContext, domainUserContext); await handler.HandleAsync(new MemberUploadSubmission(scheme.OrganisationId, memberUpload.Id)); var registeredProducerDb = FindRegisteredProducer(database, registeredProducer.Id); Assert.Equal(registeredProducerDb.CurrentSubmission.Id, producerSubmission.Id); } }