public void GivenNullMediaDto_ThenThrowsArgumentNullException() { var givenFormFile = FormFileFactory.Create("filename1234", "file content"); Action act = () => FileUploadCommand.Create(givenFormFile, null, SampleAuthorId); act.Should().Throw <ArgumentNullException>(); }
public async Task <IActionResult> UploadNewFile([FromForm] FileUploadFormData fileUploadFormData) { var mediaDto = JsonConvert.DeserializeObject <FileUploadDto>(fileUploadFormData.Media); var user = User.GetUserId(); var fileUploadCommand = FileUploadCommand.Create(fileUploadFormData.File, mediaDto, user); await _mediator.Send(fileUploadCommand); return(StatusCode(201)); }
public void GivenNullFormFile_ThenThrowsArgumentNullException() { var givenTags = new[] { "pigeons", "flying rats" }; var givenMediaDto = new FileUploadDto(givenTags, SampleUploadDate, false); Action act = () => FileUploadCommand.Create(null, givenMediaDto, SampleAuthorId); act.Should().Throw <ArgumentNullException>(); }
public void GivenMediaChangeIsSavedInDatabase_MediaChangeIsOfTypeCreate() { var givenFormFile = FormFileFactory.Create("newFile", string.Empty); var givenTags = new[] { "pigeons", "flying rats" }; var givenMediaDto = new FileUploadDto(givenTags, _givenDate, false); var givenUserId = "user"; var command = FileUploadCommand.Create(givenFormFile, givenMediaDto, givenUserId); var handler = new FileUploadCommandHandler(_fileStorageMock, _contextMock, _mediaIdProviderMock.Object, _timeProviderMock.Object); handler.Handle(command, CancellationToken.None).Wait(); _contextMock.MediaChanges.Should().ContainSingle(mc => mc.Type == MediaChangeType.Create); }
public void GivenMediaWithEmptyTagCollection_MediaIsCreatedWithoutTags() { var givenFileName = "newFile"; var givenFileContent = "None"; var givenFormFile = FormFileFactory.Create(givenFileName, givenFileContent); var givenTags = new string[] {}; var givenMediaDto = new FileUploadDto(givenTags, _givenDate, false); var command = FileUploadCommand.Create(givenFormFile, givenMediaDto, string.Empty); var handler = new FileUploadCommandHandler(_fileStorageMock, _contextMock, _mediaIdProviderMock.Object, _timeProviderMock.Object); handler.Handle(command, CancellationToken.None).Wait(); _contextMock.MediaInstances.Find(_givenMediaInstanceId).MediaTags.Should().BeEmpty(); }
public void GivenNewMediaIsUploadedSuccessfully_MediaIsCreatedInDatabase() { var givenFileName = "newFile"; var givenFileContent = "None"; var givenFormFile = FormFileFactory.Create(givenFileName, givenFileContent); var givenTags = new[] { "pigeons", "flying rats" }; var givenMediaDto = new FileUploadDto(givenTags, _givenDate, false); var command = FileUploadCommand.Create(givenFormFile, givenMediaDto, string.Empty); var handler = new FileUploadCommandHandler(_fileStorageMock, _contextMock, _mediaIdProviderMock.Object, _timeProviderMock.Object); handler.Handle(command, CancellationToken.None).Wait(); _contextMock.MediaInstances.Find(_givenMediaInstanceId).Should().NotBeNull(); }
public void GivenMediaWithSingleDotAtFileNameEnd_DataTypeIsEmptyString() { var givenFileName = "newFile."; var givenFileContent = "None"; var givenFormFile = FormFileFactory.Create(givenFileName, givenFileContent); var givenTags = new[] { "pigeons", "flying rats" }; var givenMediaDto = new FileUploadDto(givenTags, _givenDate, false); var command = FileUploadCommand.Create(givenFormFile, givenMediaDto, string.Empty); var handler = new FileUploadCommandHandler(_fileStorageMock, _contextMock, _mediaIdProviderMock.Object, _timeProviderMock.Object); handler.Handle(command, CancellationToken.None).Wait(); _contextMock.MediaInstances.Find(_givenMediaInstanceId).DataType.Should().BeEmpty(); }
public void GivenMediaWithNewTag_NewTagIsCreatedInDatabase() { var givenFileName = "newFile"; var givenFileContent = "None"; var formFile = FormFileFactory.Create(givenFileName, givenFileContent); var givenTag = "pigeons"; var givenTags = new[] { givenTag }; var givenMediaDto = new FileUploadDto(givenTags, _givenDate, false); var command = FileUploadCommand.Create(formFile, givenMediaDto, string.Empty); var handler = new FileUploadCommandHandler(_fileStorageMock, _contextMock, _mediaIdProviderMock.Object, _timeProviderMock.Object); handler.Handle(command, CancellationToken.None).Wait(); _contextMock.Tags.Should().ContainSingle(t => t.Name == givenTag); }
public void GivenMediaWithValidExtension_DataTypeIsEqualToFileExtension() { var givenFileName = "newFile"; var givenExtension = "png"; var givenFileContent = "None"; var givenFormFile = FormFileFactory.Create(givenFileName + "." + givenExtension, givenFileContent); var givenTags = new[] { "pigeons", "flying rats" }; var givenMediaDto = new FileUploadDto(givenTags, _givenDate, false); var command = FileUploadCommand.Create(givenFormFile, givenMediaDto, string.Empty); var handler = new FileUploadCommandHandler(_fileStorageMock, _contextMock, _mediaIdProviderMock.Object, _timeProviderMock.Object); handler.Handle(command, CancellationToken.None).Wait(); _contextMock.MediaInstances.Find(_givenMediaInstanceId).DataType.Should().BeEquivalentTo(givenExtension); }
public void GivenThatFileWithGivenIdAlreadyExists_MediaIsCreatedWithDifferentId() { var givenFileName = "newFile"; var givenFileContent = "None"; var givenFormFile = FormFileFactory.Create(givenFileName, givenFileContent); var givenTags = new [] { "pigeons", "flying rats" }; var givenMediaDto = new FileUploadDto(givenTags, _givenDate, false); _fileStorageMock.CreateNew(_givenMediaInstanceId); var command = FileUploadCommand.Create(givenFormFile, givenMediaDto, string.Empty); var handler = new FileUploadCommandHandler(_fileStorageMock, _contextMock, _mediaIdProviderMock.Object, _timeProviderMock.Object); handler.Handle(command, CancellationToken.None).Wait(); var streamContent = GetFileContent(_fileStorageMock.Read(_givenAlternativeMediaInstanceId)); streamContent.Should().BeEquivalentTo(givenFileContent); }