public async Task ProcessCourseFile_RowHasErrors_SetStatusToProcessedWithErrors() { // Arrange var blobServiceClient = new Mock <BlobServiceClient>(); blobServiceClient.Setup(mock => mock.GetBlobContainerClient(It.IsAny <string>())).Returns(Mock.Of <BlobContainerClient>()); var fileUploadProcessor = new FileUploadProcessor( SqlQueryDispatcherFactory, blobServiceClient.Object, Clock, new RegionCache(SqlQueryDispatcherFactory), new ExecuteImmediatelyBackgroundWorkScheduler(Fixture.ServiceScopeFactory)); var provider = await TestData.CreateProvider(); var user = await TestData.CreateUser(providerId : provider.ProviderId); var learnAimRef = (await TestData.CreateLearningDelivery()).LearnAimRef; var(courseUpload, _) = await TestData.CreateCourseUpload(provider.ProviderId, user, UploadStatus.Created); var stream = DataManagementFileHelper.CreateCourseUploadCsvStream( // Empty record will always yield errors (but we will always have a valid LARS code at this point) new CsvCourseRow() { LearnAimRef = learnAimRef }); // Act await fileUploadProcessor.ProcessCourseFile(courseUpload.CourseUploadId, stream); // Assert courseUpload = await WithSqlQueryDispatcher( dispatcher => dispatcher.ExecuteQuery(new GetCourseUpload() { CourseUploadId = courseUpload.CourseUploadId })); using (new AssertionScope()) { courseUpload.UploadStatus.Should().Be(UploadStatus.ProcessedWithErrors); courseUpload.ProcessingCompletedOn.Should().Be(Clock.UtcNow); courseUpload.ProcessingStartedOn.Should().NotBeNull(); } }
public async Task ProcessCourseFile_AllRecordsValid_SetStatusToProcessedSuccessfully() { // Arrange var blobServiceClient = new Mock <BlobServiceClient>(); blobServiceClient.Setup(mock => mock.GetBlobContainerClient(It.IsAny <string>())).Returns(Mock.Of <BlobContainerClient>()); var fileUploadProcessor = new FileUploadProcessor( SqlQueryDispatcherFactory, blobServiceClient.Object, Clock, new RegionCache(SqlQueryDispatcherFactory), new ExecuteImmediatelyBackgroundWorkScheduler(Fixture.ServiceScopeFactory)); var provider = await TestData.CreateProvider(); var user = await TestData.CreateUser(providerId : provider.ProviderId); var learnAimRef = (await TestData.CreateLearningDelivery()).LearnAimRef; var(courseUpload, _) = await TestData.CreateCourseUpload(provider.ProviderId, user, UploadStatus.Created); var uploadRows = DataManagementFileHelper.CreateCourseUploadRows(learnAimRef, rowCount: 3).ToArray(); var stream = DataManagementFileHelper.CreateCourseUploadCsvStream(uploadRows); // Act await fileUploadProcessor.ProcessCourseFile(courseUpload.CourseUploadId, stream); // Assert courseUpload = await WithSqlQueryDispatcher( dispatcher => dispatcher.ExecuteQuery(new GetCourseUpload() { CourseUploadId = courseUpload.CourseUploadId })); using (new AssertionScope()) { courseUpload.UploadStatus.Should().Be(UploadStatus.ProcessedSuccessfully); courseUpload.ProcessingCompletedOn.Should().Be(Clock.UtcNow); courseUpload.ProcessingStartedOn.Should().NotBeNull(); } }
public async Task ProcessCourseFile_LearnAimRefWithMissingLeadingZero_HasLeadingZeroAdded() { // Arrange var blobServiceClient = new Mock <BlobServiceClient>(); blobServiceClient.Setup(mock => mock.GetBlobContainerClient(It.IsAny <string>())).Returns(Mock.Of <BlobContainerClient>()); var fileUploadProcessor = new FileUploadProcessor( SqlQueryDispatcherFactory, blobServiceClient.Object, Clock, new RegionCache(SqlQueryDispatcherFactory), new ExecuteImmediatelyBackgroundWorkScheduler(Fixture.ServiceScopeFactory)); var provider = await TestData.CreateProvider(); var user = await TestData.CreateUser(providerId : provider.ProviderId); var(courseUpload, _) = await TestData.CreateCourseUpload(provider.ProviderId, user, UploadStatus.Created); var learningDelivery = await TestData.CreateLearningDelivery(learnAimRef : "01234567"); var uploadRows = DataManagementFileHelper.CreateCourseUploadRows(learningDelivery.LearnAimRef.TrimStart('0'), rowCount: 1).ToArray(); uploadRows[0].CourseName = string.Empty; var stream = DataManagementFileHelper.CreateCourseUploadCsvStream(uploadRows); // Act await fileUploadProcessor.ProcessCourseFile(courseUpload.CourseUploadId, stream); // Assert var rows = await WithSqlQueryDispatcher(async dispatcher => (await dispatcher.ExecuteQuery(new GetCourseUploadRows() { CourseUploadId = courseUpload.CourseUploadId, WithErrorsOnly = false })).Rows); rows.Single().LearnAimRef.Should().Be(learningDelivery.LearnAimRef); }