public async Task MarkFilesAsUsedAsync(MarkFilesAsUsedCommand command) { // VALIDATION AssertionHelper.AssertNotNull(command, "command"); //TODO: Validate that file id's specified are valid guid's. if (command.FileIds == null || command.FileIds.Count() < 1) { //TODO: Throw exception } // Load session based on the identifier of the first file. UploadSession session = await this.UploadSessionRepository.GetByFileIdAsync(new Guid(command.FileIds.ElementAt(0))); if (session == null) { //TODO: Localize message throw new UploadSessionNotStartedException(string.Format("No upload session containing some of the specified files has been previously started. Please, make sure that the file identifiers have been properly uploaded correctly.")); } // Mark file description in upload session as used session.MarkFilesAsUsed(Mapper.Map <IEnumerable <Guid> >(command.FileIds)); // Index file information foreach (var id in command.FileIds) { FileUploadDescription fileDescription = session.GetFileUploadDescription(new Guid(id)); FileInformationIndex index = FileInformationIndex.Create(fileDescription.Id, session.OwnerId, fileDescription.FileName, fileDescription.ContentType, fileDescription.ContentLength, fileDescription.AssignedUri, session.UploadAsPublic); // Save index this.FileInformationIndexRepository.Add(index); } // Commit changes await this.UnitOfWork.CommitChangesAsync(); }
public async Task MarkFilesAsUsed_GivenValidArgsAndSessionEnded_DoesNotThrowException() { // Arrange string sessionId = "273fbe3c-5e1d-47ea-bef3-d37783e10dd1"; string file01Id = "939be7f6-33ef-412b-850f-c27f240a7787"; string file02Id = "2c10700b-6779-4621-9117-eb4c9c41fa72"; List <string> fileIds = new List <string>() { file01Id, file02Id }; MarkFilesAsUsedCommand command = new MarkFilesAsUsedCommand(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new CommandIssuer(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()), fileIds); var applicationService = this.Fixture.Kernel.Get <IFileStorageCommandApplicationService>(); var uploadSessionRepository = this.Fixture.Kernel.Get <IUploadSessionRepository>(); var fileInformationIndexRepository = this.Fixture.Kernel.Get <IFileInformationIndexRepository>(); // Act await applicationService.MarkFilesAsUsedAsync(command); // Assert UploadSession session = await uploadSessionRepository.GetByIdAsync(new Guid(sessionId)); FileInformationIndex index01 = await fileInformationIndexRepository.GetByIdAsync(new Guid(file01Id)); FileInformationIndex index02 = await fileInformationIndexRepository.GetByIdAsync(new Guid(file02Id)); Assert.NotNull(session); Assert.Equal(sessionId, session.Id.ToString()); Assert.True(session.AreAllFilesInUse); Assert.NotNull(index01); Assert.NotNull(index02); }
public void Add(FileInformationIndex fileInformationIndex) { this.DbContext.FileInformationIndexes.Add(fileInformationIndex); }