public async Task <ManagePendingCharges> HandleAsync(Requests.Charges.FetchPendingCharges message) { authorization.EnsureCanAccessInternalArea(true); UKCompetentAuthority authority = await dataAccess.FetchCompetentAuthority(message.Authority); IReadOnlyList <MemberUpload> memberUploads = await dataAccess.FetchSubmittedNonInvoicedMemberUploadsAsync(authority); var groups = memberUploads.GroupBy(mu => new { mu.Scheme, mu.ComplianceYear }); List <PendingCharge> pendingCharges = new List <PendingCharge>(); foreach (var group in groups) { PendingCharge pendingCharge = new PendingCharge() { SchemeName = group.Key.Scheme.SchemeName, SchemeApprovalNumber = group.Key.Scheme.ApprovalNumber, ComplianceYear = group.Key.ComplianceYear.Value, TotalGBP = group.Sum(p => p.TotalCharges), SubmittedDate = group.FirstOrDefault().SubmittedDate.Value }; pendingCharges.Add(pendingCharge); } var managePendingCharges = new ManagePendingCharges { PendingCharges = pendingCharges, CanUserIssueCharges = authorization.CheckUserInRole(Roles.InternalAdmin) }; return(managePendingCharges); }
public async Task HandleAsync_Always_GroupsMemberUploadsBySchemeAndComplianceYear() { // Arrange IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights(); Scheme scheme1 = new Scheme(A.Dummy <Guid>()); scheme1.UpdateScheme("AAAA", "WEE/AA1111AA/SCH", null, ObligationType.Both, A.Dummy <Guid>()); Scheme scheme2 = new Scheme(A.Dummy <Guid>()); scheme2.UpdateScheme("BBBB", "WEE/BB2222BB/SCH", null, ObligationType.Both, A.Dummy <Guid>()); List <MemberUpload> memberUploads = new List <MemberUpload>(); var submittedDate = new DateTime(2019, 2, 27, 0, 0, 0); MemberUpload memberUpload1 = new MemberUpload( A.Dummy <Guid>(), A.Dummy <string>(), A.Dummy <List <MemberUploadError> >(), 10, 2017, scheme1, A.Dummy <string>(), A.Dummy <string>(), false); MemberUpload memberUpload2 = new MemberUpload( A.Dummy <Guid>(), A.Dummy <string>(), A.Dummy <List <MemberUploadError> >(), 20, 2017, scheme1, A.Dummy <string>(), A.Dummy <string>(), false); MemberUpload memberUpload3 = new MemberUpload( A.Dummy <Guid>(), A.Dummy <string>(), A.Dummy <List <MemberUploadError> >(), 40, 2016, scheme1, A.Dummy <string>(), A.Dummy <string>(), false); MemberUpload memberUpload4 = new MemberUpload( A.Dummy <Guid>(), A.Dummy <string>(), A.Dummy <List <MemberUploadError> >(), 80, 2017, scheme2, A.Dummy <string>(), A.Dummy <string>(), false); memberUploads.Add(memberUpload1); memberUploads.Add(memberUpload2); memberUploads.Add(memberUpload3); memberUploads.Add(memberUpload4); memberUpload1.SetSubmittedDate(submittedDate); memberUpload2.SetSubmittedDate(submittedDate); memberUpload3.SetSubmittedDate(submittedDate); memberUpload4.SetSubmittedDate(submittedDate); ICommonDataAccess dataAccess = A.Fake <ICommonDataAccess>(); A.CallTo(() => dataAccess.FetchSubmittedNonInvoicedMemberUploadsAsync(A <UKCompetentAuthority> ._)) .Returns(memberUploads); FetchPendingChargesHandler handler = new FetchPendingChargesHandler( authorization, dataAccess); // Act var results = await handler.HandleAsync(A.Dummy <Requests.Charges.FetchPendingCharges>()); // Assert Assert.NotNull(results); Assert.Equal(3, results.PendingCharges.Count); Assert.Collection(results.PendingCharges, r1 => { Assert.Equal("AAAA", r1.SchemeName); Assert.Equal(2017, r1.ComplianceYear); Assert.Equal(30, r1.TotalGBP); Assert.Equal(submittedDate, r1.SubmittedDate); }, r2 => { Assert.Equal("AAAA", r2.SchemeName); Assert.Equal(2016, r2.ComplianceYear); Assert.Equal(40, r2.TotalGBP); Assert.Equal(submittedDate, r2.SubmittedDate); }, r3 => { Assert.Equal("BBBB", r3.SchemeName); Assert.Equal(2017, r3.ComplianceYear); Assert.Equal(80, r3.TotalGBP); Assert.Equal(submittedDate, r3.SubmittedDate); }); }