public async Task HandleAsync_WithNoInternalAccess_ThrowsSecurityException() { // Arrange IWeeeAuthorization authorization = new AuthorizationBuilder().DenyInternalAreaAccess().Build(); FetchPendingChargesHandler handler = new FetchPendingChargesHandler( authorization, A.Dummy <ICommonDataAccess>()); // Act Func <Task <ManagePendingCharges> > testCode = async() => await handler.HandleAsync(A.Dummy <Requests.Charges.FetchPendingCharges>()); // Assert await Assert.ThrowsAsync <SecurityException>(testCode); }
public async Task HandleAsync_WithNoInternalAccess_ThrowsSecurityException() { // Arrange IWeeeAuthorization authorization = new AuthorizationBuilder().DenyInternalAreaAccess().Build(); FetchPendingChargesHandler handler = new FetchPendingChargesHandler( authorization, A.Dummy<ICommonDataAccess>()); // Act Func<Task<ManagePendingCharges>> testCode = async () => await handler.HandleAsync(A.Dummy<Requests.Charges.FetchPendingCharges>()); // Assert await Assert.ThrowsAsync<SecurityException>(testCode); }
public async Task HandleAsync_ReturnsFalseForCanUserIssueCharges_WhenCurrentUserIsNotInternalAdmin() { // Arrange var weeeAuthorization = new AuthorizationBuilder() .AllowInternalAreaAccess() .DenyRole(Roles.InternalAdmin) .Build(); var handler = new FetchPendingChargesHandler( weeeAuthorization, A.Dummy <ICommonDataAccess>()); // Act var result = await handler.HandleAsync(A.Dummy <Requests.Charges.FetchPendingCharges>()); // Assert Assert.False(result.CanUserIssueCharges); }
public async Task HandleAsync_ReturnsFalseForCanUserIssueCharges_WhenCurrentUserIsNotInternalAdmin() { // Arrange var weeeAuthorization = new AuthorizationBuilder() .AllowInternalAreaAccess() .DenyRole(Roles.InternalAdmin) .Build(); var handler = new FetchPendingChargesHandler( weeeAuthorization, A.Dummy<ICommonDataAccess>()); // Act var result = await handler.HandleAsync(A.Dummy<Requests.Charges.FetchPendingCharges>()); // Assert Assert.False(result.CanUserIssueCharges); }
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); }); }
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>(); MemberUpload memberUpload1 = new MemberUpload( A.Dummy<Guid>(), A.Dummy<string>(), A.Dummy<List<MemberUploadError>>(), 10, 2017, scheme1, A.Dummy<string>()); MemberUpload memberUpload2 = new MemberUpload( A.Dummy<Guid>(), A.Dummy<string>(), A.Dummy<List<MemberUploadError>>(), 20, 2017, scheme1, A.Dummy<string>()); MemberUpload memberUpload3 = new MemberUpload( A.Dummy<Guid>(), A.Dummy<string>(), A.Dummy<List<MemberUploadError>>(), 40, 2016, scheme1, A.Dummy<string>()); MemberUpload memberUpload4 = new MemberUpload( A.Dummy<Guid>(), A.Dummy<string>(), A.Dummy<List<MemberUploadError>>(), 80, 2017, scheme2, A.Dummy<string>()); memberUploads.Add(memberUpload1); memberUploads.Add(memberUpload2); memberUploads.Add(memberUpload3); memberUploads.Add(memberUpload4); 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); }, r2 => { Assert.Equal("AAAA", r2.SchemeName); Assert.Equal(2016, r2.ComplianceYear); Assert.Equal(40, r2.TotalGBP); }, r3 => { Assert.Equal("BBBB", r3.SchemeName); Assert.Equal(2017, r3.ComplianceYear); Assert.Equal(80, r3.TotalGBP); }); }