public async Task HandleAsync_GivenAddReturnSchemeRequest_SchemeShouldBeRetrieved() { var schemeIds = fixture.CreateMany <Guid>().ToList(); var request = new AddReturnScheme { SchemeIds = schemeIds }; await handler.HandleAsync(request); foreach (var schemeId in schemeIds) { A.CallTo(() => schemeDataAccess.GetSchemeOrDefault(schemeId)).MustHaveHappened(Repeated.Exactly.Once); } }
public async void GetSchemeByIdHandler_WithUnknownId_ThrowsArgumentException() { // Arrage Guid badSchemeId = new Guid("88C60FAC-1172-43F2-9AA5-7E79A8877F92"); ISchemeDataAccess dataAccess = A.Fake <ISchemeDataAccess>(); A.CallTo(() => dataAccess.GetSchemeOrDefault(badSchemeId)).Returns((Scheme)null); IWeeeAuthorization authorization = new AuthorizationBuilder() .AllowInternalAreaAccess() .Build(); var mapper = A.Fake <IMapper>(); GetSchemeByIdHandler handler = new GetSchemeByIdHandler(dataAccess, mapper, authorization); GetSchemeById request = new GetSchemeById(badSchemeId); // Act Func <Task <SchemeData> > action = () => handler.HandleAsync(request); // Assert await Assert.ThrowsAsync <ArgumentException>(action); }
public async void GetSchemeByIdHandler_WithNonInternalUser_ThrowsSecurityException(AuthorizationBuilder.UserType userType) { // Arrage Guid schemeId = new Guid("AC9116BC-5732-4F80-9AED-A6E2A0C4C1F1"); ISchemeDataAccess dataAccess = A.Fake <ISchemeDataAccess>(); Scheme scheme = A.Fake <Scheme>(); A.CallTo(() => dataAccess.GetSchemeOrDefault(schemeId)).Returns(scheme); IWeeeAuthorization authorization = AuthorizationBuilder.CreateFromUserType(userType); var mapper = A.Fake <IMapper>(); SchemeData schemeData = A.Fake <SchemeData>(); A.CallTo(() => mapper.Map <Scheme, SchemeData>(scheme)) .Returns(schemeData); GetSchemeByIdHandler handler = new GetSchemeByIdHandler(dataAccess, mapper, authorization); GetSchemeById request = new GetSchemeById(schemeId); // Act Func <Task <SchemeData> > action = () => handler.HandleAsync(request); // Assert await Assert.ThrowsAsync <SecurityException>(action); }
public async void GetSchemeByIdHandler_HappyPath_ReturnsSchemeData() { // Arrage Guid schemeId = new Guid("AC9116BC-5732-4F80-9AED-A6E2A0C4C1F1"); ISchemeDataAccess dataAccess = A.Fake <ISchemeDataAccess>(); Scheme scheme = A.Fake <Scheme>(); A.CallTo(() => dataAccess.GetSchemeOrDefault(schemeId)).Returns(scheme); IWeeeAuthorization authorization = new AuthorizationBuilder() .AllowInternalAreaAccess() .Build(); var mapper = A.Fake <IMapper>(); SchemeData schemeData = A.Fake <SchemeData>(); A.CallTo(() => mapper.Map <Scheme, SchemeData>(scheme)) .Returns(schemeData); GetSchemeByIdHandler handler = new GetSchemeByIdHandler(dataAccess, mapper, authorization); GetSchemeById request = new GetSchemeById(schemeId); // Act SchemeData result = await handler.HandleAsync(request); // Assert Assert.Equal(schemeData, result); }
public async Task <SchemeData> HandleAsync(GetSchemeById request) { authorization.EnsureCanAccessInternalArea(); var scheme = await dataAccess.GetSchemeOrDefault(request.SchemeId); if (scheme == null) { string message = string.Format("No scheme was found with id \"{0}\".", request.SchemeId); throw new ArgumentException(message); } var schemeData = mapper.Map <Scheme, SchemeData>(scheme); var complianceYearsWithSubmittedMemberUploads = await dataAccess.GetComplianceYearsWithSubmittedMemberUploads(request.SchemeId); var complianceYearsWithSubmittedDataReturns = await dataAccess.GetComplianceYearsWithSubmittedDataReturns(request.SchemeId); var schemeDownloadsByYears = mapper.Map <Core.Scheme.SchemeDataAvailability>( Domain.Scheme.SchemeDataAvailability.Create( complianceYearsWithSubmittedMemberUploads, complianceYearsWithSubmittedDataReturns)); schemeData.SchemeDataAvailability = schemeDownloadsByYears; schemeData.CanEdit = authorization.CheckUserInRole(Roles.InternalAdmin); return(schemeData); }
public async Task <SchemePublicInfo> HandleAsync(Requests.Scheme.GetSchemePublicInfoBySchemeId request) { var scheme = await dataAccess.GetSchemeOrDefault(request.SchemeId); if (scheme == null) { throw new ArgumentException($"No scheme was found with id \"{request.SchemeId}\"."); } return(new SchemePublicInfo() { SchemeId = scheme.Id, OrganisationId = scheme.OrganisationId, Name = scheme.SchemeName, ApprovalNo = scheme.ApprovalNumber }); }
public async Task <List <Guid> > HandleAsync(AddReturnScheme message) { authorization.EnsureCanAccessExternalArea(); var @return = await returnDataAccess.GetById(message.ReturnId); var returnSchemes = new List <ReturnScheme>(); foreach (var schemeId in message.SchemeIds) { var scheme = await schemeDataAccess.GetSchemeOrDefault(schemeId); returnSchemes.Add(new ReturnScheme(scheme, @return)); } return(await returnSchemeDataAccess.Submit(returnSchemes)); }