public async Task <IReadOnlyList <int> > HandleAsync(Requests.Charges.FetchComplianceYearsWithInvoices message) { authorization.EnsureCanAccessInternalArea(); UKCompetentAuthority authority = await dataAccess.FetchCompetentAuthority(message.Authority); IEnumerable <MemberUpload> invoicedMemberUploads = await dataAccess.FetchInvoicedMemberUploadsAsync(authority); return(invoicedMemberUploads .Select(mu => mu.ComplianceYear.Value) .Distinct() .OrderByDescending(x => x) .ToList()); }
public async Task GetAllComplianceYearsHandler_ReturnsYearsInDescendingOrder() { // Arrange UKCompetentAuthority competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Environment Agency", "EA", new Country(Guid.NewGuid(), "UK - England"), "*****@*****.**"); var scheme1 = A.Fake<Scheme>(); A.CallTo(() => scheme1.SchemeName).Returns("Test1"); A.CallTo(() => scheme1.CompetentAuthority).Returns(competentAuthority); var scheme2 = A.Fake<Scheme>(); A.CallTo(() => scheme2.SchemeName).Returns("Test2"); A.CallTo(() => scheme2.CompetentAuthority).Returns(competentAuthority); var scheme3 = A.Fake<Scheme>(); A.CallTo(() => scheme3.SchemeName).Returns("Test3"); A.CallTo(() => scheme3.CompetentAuthority).Returns(competentAuthority); InvoiceRun invoice = A.Fake<InvoiceRun>(); var memberUpload1 = A.Fake<MemberUpload>(); A.CallTo(() => memberUpload1.ComplianceYear).Returns(2015); A.CallTo(() => memberUpload1.Scheme).Returns(scheme1); A.CallTo(() => memberUpload1.InvoiceRun).Returns(invoice); var memberUpload2 = A.Fake<MemberUpload>(); A.CallTo(() => memberUpload2.ComplianceYear).Returns(2017); A.CallTo(() => memberUpload2.Scheme).Returns(scheme2); A.CallTo(() => memberUpload2.InvoiceRun).Returns(invoice); var memberUpload3 = A.Fake<MemberUpload>(); A.CallTo(() => memberUpload3.ComplianceYear).Returns(2016); A.CallTo(() => memberUpload3.Scheme).Returns(scheme3); A.CallTo(() => memberUpload3.InvoiceRun).Returns(invoice); ICommonDataAccess dataAccess = A.Fake<ICommonDataAccess>(); A.CallTo(() => dataAccess.FetchInvoicedMemberUploadsAsync(competentAuthority)) .Returns(new List<MemberUpload>() { memberUpload1, memberUpload2, memberUpload3 }); IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights(); FetchComplianceYearsWithInvoicesHandler handler = new FetchComplianceYearsWithInvoicesHandler(authorization, dataAccess); Requests.Charges.FetchComplianceYearsWithInvoices request = new Requests.Charges.FetchComplianceYearsWithInvoices(CompetentAuthority.England); A.CallTo(() => dataAccess.FetchCompetentAuthority(CompetentAuthority.England)).Returns(competentAuthority); // Act var yearsList = await handler.HandleAsync(request); Assert.NotNull(yearsList); Assert.Equal(3, yearsList.Count); Assert.Collection(yearsList, r1 => Assert.Equal("2017", r1.ToString()), r2 => Assert.Equal("2016", r2.ToString()), r3 => Assert.Equal("2015", r3.ToString())); }
public async Task GetAllComplianceYearsHandler_ReturnsYearsInDescendingOrder() { // Arrange UKCompetentAuthority competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Environment Agency", "EA", new Country(Guid.NewGuid(), "UK - England"), "*****@*****.**", 0); var scheme1 = A.Fake <Scheme>(); A.CallTo(() => scheme1.SchemeName).Returns("Test1"); A.CallTo(() => scheme1.CompetentAuthority).Returns(competentAuthority); var scheme2 = A.Fake <Scheme>(); A.CallTo(() => scheme2.SchemeName).Returns("Test2"); A.CallTo(() => scheme2.CompetentAuthority).Returns(competentAuthority); var scheme3 = A.Fake <Scheme>(); A.CallTo(() => scheme3.SchemeName).Returns("Test3"); A.CallTo(() => scheme3.CompetentAuthority).Returns(competentAuthority); InvoiceRun invoice = A.Fake <InvoiceRun>(); var memberUpload1 = A.Fake <MemberUpload>(); A.CallTo(() => memberUpload1.ComplianceYear).Returns(2015); A.CallTo(() => memberUpload1.Scheme).Returns(scheme1); A.CallTo(() => memberUpload1.InvoiceRun).Returns(invoice); var memberUpload2 = A.Fake <MemberUpload>(); A.CallTo(() => memberUpload2.ComplianceYear).Returns(2017); A.CallTo(() => memberUpload2.Scheme).Returns(scheme2); A.CallTo(() => memberUpload2.InvoiceRun).Returns(invoice); var memberUpload3 = A.Fake <MemberUpload>(); A.CallTo(() => memberUpload3.ComplianceYear).Returns(2016); A.CallTo(() => memberUpload3.Scheme).Returns(scheme3); A.CallTo(() => memberUpload3.InvoiceRun).Returns(invoice); ICommonDataAccess dataAccess = A.Fake <ICommonDataAccess>(); A.CallTo(() => dataAccess.FetchInvoicedMemberUploadsAsync(competentAuthority)) .Returns(new List <MemberUpload>() { memberUpload1, memberUpload2, memberUpload3 }); IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights(); FetchComplianceYearsWithInvoicesHandler handler = new FetchComplianceYearsWithInvoicesHandler(authorization, dataAccess); Requests.Charges.FetchComplianceYearsWithInvoices request = new Requests.Charges.FetchComplianceYearsWithInvoices(CompetentAuthority.England); A.CallTo(() => dataAccess.FetchCompetentAuthority(CompetentAuthority.England)).Returns(competentAuthority); // Act var yearsList = await handler.HandleAsync(request); Assert.NotNull(yearsList); Assert.Equal(3, yearsList.Count); Assert.Collection(yearsList, r1 => Assert.Equal("2017", r1.ToString()), r2 => Assert.Equal("2016", r2.ToString()), r3 => Assert.Equal("2015", r3.ToString())); }