public async Task HandleAsync_GivenAddReturnRequest_DataAccessSubmitsIsCalled(QuarterType quarterType, FacilityType facility) { var request = new AddReturn { OrganisationId = Guid.NewGuid(), Quarter = quarterType, Year = year, FacilityType = Core.AatfReturn.FacilityType.Aatf }; var @return = A.Dummy <Return>(); var organisation = new Organisation(); var userId = Guid.NewGuid(); A.CallTo(() => userContext.UserId).Returns(userId); A.CallTo(() => genericDataAccess.GetById <Organisation>(request.OrganisationId)).Returns(organisation); A.CallTo(() => returnFactory.GetReturnQuarter(A <Guid> ._, A <FacilityType> ._)).Returns(new Quarter(year, quarterType)); await handler.HandleAsync(request); A.CallTo(() => returnDataAccess.Submit(A <Return> .That.Matches(c => c.Quarter.Year == request.Year && (int)c.Quarter.Q == (int)quarterType && c.Organisation.Equals(organisation) && c.CreatedById.Equals(userId.ToString())))).MustHaveHappened(Repeated.Exactly.Once); }
public async Task HandleAsync_NoOrganisationAccess_ThrowsSecurityException() { var authorization = new AuthorizationBuilder().DenyOrganisationAccess().Build(); handler = new AddReturnHandler(authorization, A.Dummy <IReturnDataAccess>(), A.Dummy <IGenericDataAccess>(), A.Dummy <IUserContext>(), A.Dummy <IReturnFactoryDataAccess>(), A.Dummy <IReturnFactory>()); Func <Task> action = async() => await handler.HandleAsync(A.Dummy <AddReturn>()); await action.Should().ThrowAsync <SecurityException>(); }