public async Task HandleAsync_Always_ReturnsSchemesOrderedBySchemeName() { // Arrange IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights(); IMap <Scheme, SchemeData> schemeMap = new SchemeMap(A.Dummy <IMapper>(), A.Fake <IMap <Address, AddressData> >(), A.Fake <IMap <Contact, ContactData> >()); Organisation organisation = Organisation.CreateSoleTrader("Test Organisation"); Scheme scheme1 = new Scheme(organisation); scheme1.UpdateScheme("Scheme C", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>()); scheme1.SetStatus(SchemeStatus.Approved); Scheme scheme2 = new Scheme(organisation); scheme2.UpdateScheme("Scheme A", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>()); scheme2.SetStatus(SchemeStatus.Approved); Scheme scheme3 = new Scheme(organisation); scheme3.UpdateScheme("Scheme D", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>()); scheme3.SetStatus(SchemeStatus.Approved); Scheme scheme4 = new Scheme(organisation); scheme4.UpdateScheme("Scheme B", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>()); scheme4.SetStatus(SchemeStatus.Approved); IGetSchemesDataAccess dataAccess = A.Fake <IGetSchemesDataAccess>(); A.CallTo(() => dataAccess.GetSchemes()).Returns( new List <Scheme>() { scheme1, scheme2, scheme3, scheme4 }); GetSchemesHandler handler = new GetSchemesHandler( authorization, schemeMap, dataAccess); // Act GetSchemes request = new GetSchemes(GetSchemes.FilterType.Approved); List <SchemeData> results = await handler.HandleAsync(request); // Assert Assert.NotNull(results); Assert.Equal(4, results.Count); Assert.Collection(results, r => Assert.Equal("Scheme A", r.SchemeName), r => Assert.Equal("Scheme B", r.SchemeName), r => Assert.Equal("Scheme C", r.SchemeName), r => Assert.Equal("Scheme D", r.SchemeName)); }
public async Task <List <SchemeData> > HandleAsync(Requests.Admin.GetSchemes request) { authorization.EnsureCanAccessInternalArea(); List <Scheme> schemes = await dataAccess.GetSchemes(); Func <Scheme, bool> filter; switch (request.Filter) { case Requests.Admin.GetSchemes.FilterType.Approved: filter = s => s.SchemeStatus == SchemeStatus.Approved; break; case Requests.Admin.GetSchemes.FilterType.ApprovedOrWithdrawn: filter = s => (s.SchemeStatus == SchemeStatus.Approved) || (s.SchemeStatus == SchemeStatus.Withdrawn); break; default: throw new NotSupportedException(); } return(schemes .Where(filter) .OrderBy(s => s.SchemeName) .Select(s => schemeMap.Map(s)) .ToList()); }
public async Task HandleAsync_WithFilterSetToApprovedOrWithdrawn_ReturnsSchemesWithStatusOfApprovedOrWithdrawn() { // Arrange IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights(); var mapper = new SchemeMap(A.Fake <IMapper>(), A.Fake <IMap <Address, AddressData> >(), A.Fake <IMap <Contact, ContactData> >()); Organisation organisation = Organisation.CreateSoleTrader("Test Organisation"); Scheme schemePending = new Scheme(organisation); schemePending.UpdateScheme("Scheme Pending", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>()); Scheme schemeApproved = new Scheme(organisation); schemeApproved.UpdateScheme("Scheme Approved", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>()); schemeApproved.SetStatus(SchemeStatus.Approved); Scheme schemeRejected = new Scheme(organisation); schemeRejected.UpdateScheme("Scheme Rejected", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>()); schemeRejected.SetStatus(SchemeStatus.Rejected); Scheme schemeWithdrawn = new Scheme(organisation); schemeWithdrawn.UpdateScheme("Scheme Withdrawn", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>()); schemeWithdrawn.SetStatus(SchemeStatus.Approved); schemeWithdrawn.SetStatus(SchemeStatus.Withdrawn); IGetSchemesDataAccess dataAccess = A.Fake <IGetSchemesDataAccess>(); A.CallTo(() => dataAccess.GetSchemes()).Returns( new List <Scheme>() { schemePending, schemeApproved, schemeRejected, schemeWithdrawn }); GetSchemesHandler handler = new GetSchemesHandler( authorization, mapper, dataAccess); // Act GetSchemes request = new GetSchemes(GetSchemes.FilterType.ApprovedOrWithdrawn); List <SchemeData> results = await handler.HandleAsync(request); // Assert Assert.NotNull(results); Assert.Equal(2, results.Count); Assert.Contains(results, r => r.SchemeName == "Scheme Approved"); Assert.Contains(results, r => r.SchemeName == "Scheme Withdrawn"); }
public async Task<List<SchemeData>> HandleAsync(Requests.Admin.GetSchemesByOrganisationId request) { authorization.EnsureCanAccessInternalArea(); List<Scheme> schemes = await dataAccess.GetSchemes(); return schemes .Where(s => s.OrganisationId == request.OrganisationId && s.SchemeStatus.Value != (int)SchemeStatus.Pending) .OrderBy(s => s.SchemeName) .Select(s => schemeMap.Map(s)) .ToList(); }
public async Task HandleAsync_GivenRequest_GetSchemesShouldBeCalled() { var result = await handler.HandleAsync(A.Dummy <GetSchemesByOrganisationId>()); A.CallTo(() => dataAccess.GetSchemes()).MustHaveHappened(Repeated.Exactly.Once); }