public async Task CanScheduleAndFinishProcessing() { var file = new Abstraction.Service.File("file.csv", csvData); var result = await FileService.ScheduleForProcessing(file); result.Succeeded.Should().BeTrue(); var history = result.Value; history.Key.Should().NotBe(default(Guid)); history.Status.Should().Be(UploadStatus.Pending); history.Filename.Should().Be(file.Filename); history.Errors.Should().BeEmpty(); history.Timestamp.Should().BeCloseTo(DateTimeOffset.UtcNow, 1000); await WaitForProcessingFinish(history.Key); var found = await FileService.FindHistory(history.Key); found.Key.Should().Be(history.Key); found.Status.Should().Be(UploadStatus.Done); found.Filename.Should().Be(history.Filename); found.Errors.Should().BeEmpty(); history.Timestamp.Should().Be(history.Timestamp); }
public async Task <OperationResult <UploadHistory> > ScheduleForProcessing(Abstraction.Service.File file) { var processor = ProcessorResolver.Resolve(file.Filename); if (processor == null) { return(OperationResult <UploadHistory> .Failed("The file format is not supported.")); } var history = new UploadHistory { Key = Guid.NewGuid(), Filename = file.Filename, Status = UploadStatus.Pending, Timestamp = DateTimeOffset.UtcNow, Errors = new string[0] }; await historyStore.Create(history, file.Data); backgroundJobClient.Enqueue <FileJob>(job => job.ProcessFile(history.Key)); return(OperationResult <UploadHistory> .Success(history)); }