Ejemplo n.º 1
0
        public void GivenNullMediaDto_ThenThrowsArgumentNullException()
        {
            var givenFormFile = FormFileFactory.Create("filename1234", "file content");

            Action act = () => FileUploadCommand.Create(givenFormFile, null, SampleAuthorId);

            act.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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>();
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
0
        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();
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
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);
        }