Example #1
0
        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);
        }
Example #2
0
 private async Task CreateMediaFileInFileSystem(IFormFile formFile, string filename)
 {
     await using var stream = _fileStorage.CreateNew(filename);
     await formFile.CopyToAsync(stream);
 }