public async Task HandleAsync_WithSchemeSpecified_GeneratesCorrectFileName() { IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights(); IStoredProcedures storedProcedures = A.Fake <IStoredProcedures>(); SpgSchemeWeeeCsvResult storedProcedureResult = new SpgSchemeWeeeCsvResult(); storedProcedureResult.Schemes.Add(new SpgSchemeWeeeCsvResult.SchemeResult() { SchemeId = new Guid("C5AD2FF9-941D-4D6F-B68B-9805DD7E1FD1"), ApprovalNumber = "WEE/AA1111AA/SCH" }); A.CallTo(() => storedProcedures.SpgSchemeWeeeCsvAsync(A <int> ._, A <Guid?> ._, A <string> ._)) .Returns(storedProcedureResult); GetSchemeWeeeCsvHandler handler = new GetSchemeWeeeCsvHandler( storedProcedures, authorization, A.Dummy <CsvWriterFactory>()); GetSchemeWeeeCsv request = new GetSchemeWeeeCsv(2016, new Guid("C5AD2FF9-941D-4D6F-B68B-9805DD7E1FD1"), ObligationType.B2C); // Act SystemTime.Freeze(new DateTime(2016, 12, 31, 23, 59, 0)); FileInfo result = await handler.HandleAsync(request); SystemTime.Unfreeze(); // Assert Assert.Equal("2016_WEEAA1111AASCH_B2C_schemeWEEE_31122016_2359.csv", result.FileName); }
public async Task HandleAsync_WithNonInternalUser_ThrowsSecurityException() { // Arrange IWeeeAuthorization authorization = new AuthorizationBuilder().DenyInternalAreaAccess().Build(); GetSchemeWeeeCsvHandler handler = new GetSchemeWeeeCsvHandler( A.Dummy<IStoredProcedures>(), authorization, A.Dummy<CsvWriterFactory>()); GetSchemeWeeeCsv request = new GetSchemeWeeeCsv(A.Dummy<int>(), A.Dummy<Guid?>(), A.Dummy<ObligationType>()); // Act Func<Task<FileInfo>> testCode = async () => await handler.HandleAsync(request); // Assert await Assert.ThrowsAsync<SecurityException>(testCode); }
public async Task HandleAsync_WithNonInternalUser_ThrowsSecurityException() { // Arrange IWeeeAuthorization authorization = new AuthorizationBuilder().DenyInternalAreaAccess().Build(); GetSchemeWeeeCsvHandler handler = new GetSchemeWeeeCsvHandler( A.Dummy <IStoredProcedures>(), authorization, A.Dummy <CsvWriterFactory>()); GetSchemeWeeeCsv request = new GetSchemeWeeeCsv(A.Dummy <int>(), A.Dummy <Guid?>(), A.Dummy <ObligationType>()); // Act Func <Task <FileInfo> > testCode = async() => await handler.HandleAsync(request); // Assert await Assert.ThrowsAsync <SecurityException>(testCode); }
public async Task HandleAsync_WithNoSchemeSpecified_GeneratesCorrectFileName() { // Arrange IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights(); GetSchemeWeeeCsvHandler handler = new GetSchemeWeeeCsvHandler( A.Dummy<IStoredProcedures>(), authorization, A.Dummy<CsvWriterFactory>()); GetSchemeWeeeCsv request = new GetSchemeWeeeCsv(2016, null, ObligationType.B2C); // Act SystemTime.Freeze(new DateTime(2016, 12, 31, 23, 59, 0)); FileInfo result = await handler.HandleAsync(request); SystemTime.Unfreeze(); // Assert Assert.Equal("2016_B2C_schemeWEEE_31122016_2359.csv", result.FileName); }
public async Task HandleAsync_WithNoSchemeSpecified_GeneratesCorrectFileName() { // Arrange IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights(); GetSchemeWeeeCsvHandler handler = new GetSchemeWeeeCsvHandler( A.Dummy <IStoredProcedures>(), authorization, A.Dummy <CsvWriterFactory>()); GetSchemeWeeeCsv request = new GetSchemeWeeeCsv(2016, null, ObligationType.B2C); // Act SystemTime.Freeze(new DateTime(2016, 12, 31, 23, 59, 0)); FileInfo result = await handler.HandleAsync(request); SystemTime.Unfreeze(); // Assert Assert.Equal("2016_B2C_schemeWEEE_31122016_2359.csv", result.FileName); }
public async void GivenVariousDifferingParameters_RunningTimeIsUnderTenSeconds(int complianceYear, ObligationType obligationType) { using (var databaseWrapper = new DatabaseWrapper()) { // Arrange Stopwatch stopWatch = new Stopwatch(); GetSchemeWeeeCsvHandler handler = new GetSchemeWeeeCsvHandler( databaseWrapper.WeeeContext.StoredProcedures, AuthorizationBuilder.CreateUserWithAllRights(), new CsvWriterFactory(new NoFormulaeExcelSanitizer())); // Act GetSchemeWeeeCsv request = new GetSchemeWeeeCsv(complianceYear, null, obligationType); stopWatch.Start(); await handler.HandleAsync(request); stopWatch.Stop(); // Assert Assert.InRange(stopWatch.ElapsedMilliseconds, 0, 10000); } }
public async Task HandleAsync_WithSchemeSpecified_GeneratesCorrectFileName() { IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights(); IStoredProcedures storedProcedures = A.Fake<IStoredProcedures>(); SpgSchemeWeeeCsvResult storedProcedureResult = new SpgSchemeWeeeCsvResult(); storedProcedureResult.Schemes.Add(new SpgSchemeWeeeCsvResult.SchemeResult() { SchemeId = new Guid("C5AD2FF9-941D-4D6F-B68B-9805DD7E1FD1"), ApprovalNumber = "WEE/AA1111AA/SCH" }); A.CallTo(() => storedProcedures.SpgSchemeWeeeCsvAsync(A<int>._, A<Guid?>._, A<string>._)) .Returns(storedProcedureResult); GetSchemeWeeeCsvHandler handler = new GetSchemeWeeeCsvHandler( storedProcedures, authorization, A.Dummy<CsvWriterFactory>()); GetSchemeWeeeCsv request = new GetSchemeWeeeCsv(2016, new Guid("C5AD2FF9-941D-4D6F-B68B-9805DD7E1FD1"), ObligationType.B2C); // Act SystemTime.Freeze(new DateTime(2016, 12, 31, 23, 59, 0)); FileInfo result = await handler.HandleAsync(request); SystemTime.Unfreeze(); // Assert Assert.Equal("2016_WEEAA1111AASCH_B2C_schemeWEEE_31122016_2359.csv", result.FileName); }