예제 #1
0
        public async Task Should_GetPicture()
        {
            //arrange
            var addPictureCommand = new AddPictureCommand
            {
                Description = "Picture from Wadowice",
                Url         = "http://ubiquitous.com/api/product/picture/2137",
                MimeTypeId  = MimeType.Jpg.Id,
                Filename    = "Picture #1"
            };

            //act
            var addPicture = await Mediator.Send(addPictureCommand);

            //act
            var getPicture = await Mediator.Send(new GetPictureQuery(addPicture.Id));

            //assert
            addPicture.Id.Should().NotBeEmpty();
            addPicture.Description.Should().Be(addPictureCommand.Description);
            addPicture.Url.Should().Be(addPictureCommand.Url);
            addPicture.FileName.Should().Be(addPictureCommand.Filename);
            addPicture.MimeTypeId.Should().Be(addPictureCommand.MimeTypeId);

            getPicture.Id.Should().Be(addPicture.Id);
            getPicture.Description.Should().Be(addPicture.Description);
            getPicture.Url.Should().Be(addPicture.Url);
            getPicture.FileName.Should().Be(addPicture.FileName);
            getPicture.MimeTypeId.Should().Be(addPicture.MimeTypeId);
            getPicture.FileStorageUploadId.Should().Be(addPicture.FileStorageUploadId);
        }
예제 #2
0
        public async Task Should_UpdatePicture_ThrownPictureNotFoundException()
        {
            //arrange
            var addPictureCommand = new AddPictureCommand
            {
                Description = "Picture from Wadowice",
                Url         = "http://ubiquitous.com/api/product/picture/2137",
                MimeTypeId  = MimeType.Jpg.Id,
                Filename    = "Picture #1"
            };

            //act
            var addPicture = await Mediator.Send(addPictureCommand);

            //act
            var command = new UpdatePictureCommand
            {
                Description         = addPictureCommand + " Updated",
                Filename            = addPictureCommand + "Updated",
                Url                 = addPictureCommand + "Updated",
                PictureId           = addPicture.Id,
                FileStorageUploadId = Guid.NewGuid(),
                MimeTypeId          = MimeType.Bitmap.Id
            };
            var update = await Mediator.Send(command);

            Func <Task> task = async() => await Mediator.Send(new GetPictureQuery(Guid.NewGuid()));

            //assert

            task.Should().Throw <PictureNotFoundException>();
        }
예제 #3
0
        public async Task Should_DeletePicture()
        {
            //arrange
            var addPictureCommand = new AddPictureCommand
            {
                Description = "Picture from Wadowice",
                Url         = "http://ubiquitous.com/api/product/picture/2137",
                MimeTypeId  = MimeType.Jpg.Id,
                Filename    = "Picture #1"
            };

            //act
            var addPicture = await Mediator.Send(addPictureCommand);

            //act
            await Mediator.Send(new DeletePictureCommand(addPicture.Id));

            Func <Task> task = async() => await Mediator.Send(new GetPictureQuery(addPicture.Id));

            //assert
            addPicture.Id.Should().NotBeEmpty();
            addPicture.Description.Should().Be(addPictureCommand.Description);
            addPicture.Url.Should().Be(addPictureCommand.Url);
            addPicture.FileName.Should().Be(addPictureCommand.Filename);
            addPicture.MimeTypeId.Should().Be(addPictureCommand.MimeTypeId);

            task.Should().Throw <PictureNotFoundException>();
        }
예제 #4
0
        public async Task Should_AttachPictureProduct_ForNonExistingProduct_Returns404()
        {
            //arrange
            var command = GetCreateProductCommand();

            await CreateProductAsync(command);

            var addPictureCommand = new AddPictureCommand
            {
                Description = "Picture from Wadowice",
                Url         = "http://ubiquitous.com/api/product/picture/2137",
                MimeTypeId  = MimeType.Jpg.Id,
                Filename    = "Picture #1"
            };

            //act
            var addPicturePath = PicturesController.AddPicture();
            var addResponse    = await Client.PostAsJsonAsync(addPicturePath, addPictureCommand);

            var postStringResult = await addResponse.Content.ReadAsStringAsync();

            var pictureResult = JsonConvert.DeserializeObject <PictureViewModel>(postStringResult);

            var attachPictureToProduct = ProductController.AttachPicture(Guid.NewGuid(), pictureResult.Id);
            var attachResponse         = await Client.PostAsJsonAsync(attachPictureToProduct, new {});

            //assert
            attachResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
예제 #5
0
        protected async Task <PictureViewModel> AddPicture()
        {
            var addPictureCommand = new AddPictureCommand
            {
                Description = "Picture from Wadowice",
                Url         = "http://ubiquitous.com/api/product/picture/2137",
                MimeTypeId  = MimeType.Jpg.Id,
                Filename    = "Picture #1"
            };
            var addedPicture = await Mediator.Send(addPictureCommand);

            addedPicture.Id.Should().NotBeEmpty();
            return(addedPicture);
        }
예제 #6
0
        public async Task <(Guid, Guid)> Should_AddPictureProduct()
        {
            //arrange
            var command        = GetCreateProductCommand();
            var createdProduct = await CreateProductAsync(command);

            var addPictureCommand = new AddPictureCommand
            {
                Description = "Picture from Wadowice",
                Url         = "http://ubiquitous.com/api/product/picture/2137",
                MimeTypeId  = MimeType.Jpg.Id,
                Filename    = "Picture #1"
            };

            //act
            var addPictureResult = await Mediator.Send(addPictureCommand);

            await Mediator.Send(new AttachPictureToProductCommand(createdProduct.Id, addPictureResult.Id));

            var responseProduct = await GetProductAsync(createdProduct.Id);

            //assert
            command.Should().NotBeNull();
            command.Name.Should().Be(createdProduct.Name);
            command.Description.Should().Be(createdProduct.Description);
            command.BarCode.Should().Be(createdProduct.BarCode);
            command.Price.Should().Be(createdProduct.Price);
            command.Dimensions.Should().Be(createdProduct.Dimensions);
            command.ManufacturerId.Should().Be(createdProduct.ManufacturerId);

            responseProduct.Id.Should().Be(createdProduct.Id);
            responseProduct.Name.Should().Be(createdProduct.Name);
            responseProduct.Description.Should().Be(createdProduct.Description);
            responseProduct.BarCode.Should().Be(createdProduct.BarCode);
            responseProduct.Price.Should().Be(createdProduct.Price);
            responseProduct.Dimensions.Should().Be(createdProduct.Dimensions);
            responseProduct.ManufacturerId.Should().Be(createdProduct.ManufacturerId);
            responseProduct.IsPublished.Should().BeFalse();
            responseProduct.Pictures.Count.Should().Be(1);

            var picture = responseProduct.Pictures.First();

            picture.Id.Should().NotBeEmpty();
            picture.Description.Should().Be(addPictureCommand.Description);
            picture.Url.Should().Be(addPictureCommand.Url);
            picture.FileName.Should().Be(addPictureCommand.Filename);
            picture.MimeTypeId.Should().Be(addPictureCommand.MimeTypeId);

            return(responseProduct.Id, picture.Id);
        }
예제 #7
0
        public async Task Should_UpdatePicture()
        {
            //arrange
            var addPictureCommand = new AddPictureCommand
            {
                Description = "Picture from Wadowice",
                Url         = "http://ubiquitous.com/api/product/picture/2137",
                MimeTypeId  = MimeType.Jpg.Id,
                Filename    = "Picture #1"
            };

            //act
            var addPicture = await Mediator.Send(addPictureCommand);

            //act
            var command = new UpdatePictureCommand
            {
                PictureId           = addPicture.Id,
                Description         = addPictureCommand + " Updated",
                Filename            = addPictureCommand + "Updated",
                Url                 = addPictureCommand + "Updated",
                FileStorageUploadId = Guid.NewGuid(),
                MimeTypeId          = MimeType.Bitmap.Id
            };
            var update = await Mediator.Send(command);

            var getPicture = await Mediator.Send(new GetPictureQuery(addPicture.Id));

            //assert

            getPicture.Id.Should().Be(update.Id);
            getPicture.Description.Should().Be(update.Description);
            getPicture.Url.Should().Be(update.Url);
            getPicture.FileName.Should().Be(update.FileName);
            getPicture.MimeTypeId.Should().Be(update.MimeTypeId);
            getPicture.FileStorageUploadId.Should().Be(update.FileStorageUploadId);

            getPicture.Id.Should().Be(command.PictureId);
            getPicture.Description.Should().Be(command.Description);
            getPicture.Url.Should().Be(command.Url);
            getPicture.FileName.Should().Be(command.Filename);
            getPicture.MimeTypeId.Should().Be(command.MimeTypeId);
            getPicture.FileStorageUploadId.Should().Be(command.FileStorageUploadId);
        }
예제 #8
0
        protected async Task <PictureViewModel> AddPicture()
        {
            var addPictureCommand = new AddPictureCommand
            {
                Description = "Picture from Wadowice",
                Url         = "http://ubiquitous.com/api/product/picture/2137",
                MimeTypeId  = MimeType.Jpg.Id,
                Filename    = "Picture #1"
            };
            var addPicturePath = PicturesController.AddPicture();
            var addResponse    = await Client.PostAsJsonAsync(addPicturePath, addPictureCommand);

            var addStringResult = await addResponse.Content.ReadAsStringAsync();

            var pictureResult = JsonConvert.DeserializeObject <PictureViewModel>(addStringResult);

            addResponse.StatusCode.Should().Be(HttpStatusCode.Created);
            return(pictureResult);
        }
예제 #9
0
        public async Task Should_AttachPictureProduct_ForNonExistingProduct_Returns404()
        {
            //arrange
            var command = GetCreateProductCommand();

            await CreateProductAsync(command);

            var addPictureCommand = new AddPictureCommand
            {
                Description = "Picture from Wadowice",
                Url         = "http://ubiquitous.com/api/product/picture/2137",
                MimeTypeId  = MimeType.Jpg.Id,
                Filename    = "Picture #1"
            };

            //act
            var addPictureResult = await Mediator.Send(addPictureCommand);

            Func <Task> task = async() => await Mediator.Send(new AttachPictureToProductCommand(Guid.NewGuid(), addPictureResult.Id));

            //assert
            task.Should().Throw <ProductNotFoundException>();
        }
예제 #10
0
        public async Task <IActionResult> AddPicture([FromBody] AddPictureCommand command)
        {
            var picture = await _mediator.Send(command);

            return(CreatedAtAction(nameof(GetPicture), new { pictureId = picture }, picture));
        }