コード例 #1
0
        public async Task PostMulitpleImage_Succes()
        {
            // Arrange
            ImagesController controller = GetController();

            Byte[] image = CreateImage();
            MultipartFormDataContent content = new MultipartFormDataContent();

            content.Add(CreateFileContent(image, "image.jpeg", "image/jpeg"));
            content.Add(CreateFileContent(image, "image1.png", "image/jpeg"));
            content.Add(CreateFileContent(image, "image2.jpg", "image/jpeg"));
            content.Add(CreateFileContent(image, "image3.jpeg", "image/jpeg"));
            content.Add(CreateFileContent(image, "image4.jpeg", "image/jpeg"));
            controller.Request = new HttpRequestMessage()
            {
                Method  = HttpMethod.Post,
                Content = content,
            };
            //Act
            HttpResponseMessage response = await controller.Post();

            //Assert
            Assert.AreEqual(response.StatusCode, HttpStatusCode.Created);
            List <Image> images;

            Assert.IsTrue(response.TryGetContentValue <List <Image> >(out images));
            Assert.IsTrue(images.Count == 5);
        }
コード例 #2
0
        public void PostManyWithDifferentTypes()
        {
            var mock       = new Mock <IRepository <ImageEntity> >();
            var controller = new ImagesController(mock.Object);
            var result     = controller.Post(new[] { _imageModels[0], _imageModels[1], _imageModels[2] }) as StatusCodeResult;

            Assert.InRange(result.StatusCode, 200, 299);
            mock.Verify(i => i.Add(It.IsAny <ImageEntity>()), Times.Exactly(3));
        }
コード例 #3
0
        public void PostOne()
        {
            var mock       = new Mock <IRepository <ImageEntity> >();
            var controller = new ImagesController(mock.Object);
            var result     = controller.Post(new[] { _imageModels[0] }) as StatusCodeResult;

            Assert.InRange(result.StatusCode, 200, 299);
            mock.Verify(i => i.Add(It.IsAny <ImageEntity>()), Times.Once());
        }
コード例 #4
0
        public void PostOneForm()
        {
            var mock       = new Mock <IRepository <ImageEntity> >();
            var controller = new ImagesController(mock.Object);

            var files  = new FormFileCollection();
            var stream = new MemoryStream(Convert.FromBase64String(_imageModels[0].Base64Data));

            files.Add(new FormFile(stream, 0, stream.Length, "sample1", "sample1"));

            var result = controller.Post(files) as StatusCodeResult;

            Assert.InRange(result.StatusCode, 200, 299);
            mock.Verify(i => i.Add(It.IsAny <ImageEntity>()), Times.Once());
        }
コード例 #5
0
        public async Task PostImage_TypeNotValid()
        {
            // Arrange
            ImagesController controller = GetController();

            //Arrange
            Byte[] image = CreateImage();

            MultipartFormDataContent content = new MultipartFormDataContent();

            content.Add(CreateFileContent(image, "image.docx", "image/jpeg"));
            //Sets a controller request message content to
            controller.Request = new HttpRequestMessage()
            {
                Method  = HttpMethod.Post,
                Content = content,
            };
            //Act
            HttpResponseMessage response = await controller.Post();

            //Assert
            Assert.AreEqual(response.StatusCode, HttpStatusCode.BadRequest);
        }
コード例 #6
0
        public async Task ReturnsBadRequestWhenFileIsNull()
        {
            var result = await _controller.Post(null);

            result.Should().BeOfType <BadRequestObjectResult>();
        }