Exemplo n.º 1
0
        public async Task ImageUploadInvalidFileName()
        {
            var userName      = "******";
            var formCollecton = new MockFormCollection(new MockFormFile("** Whale ?? Shark ::.jpg"));
            var tags          = new string[] { "tag1", "tag2", "wdavidsen Upload" };

            SetControllerContext(_uploadController, "POST", userName, formCollecton);

            _fileUploadService.Setup(m => m.CopyFile(It.IsAny <IFormFile>(), It.IsAny <string>(), FileMode.Create));
            _imageService.Setup(m => m.QueueMobileResize(It.IsAny <string>(), It.IsAny <string>(), tags));

            _uploadTracker.Setup(m => m.AddUpload(userName, It.IsAny <string>()));

            var response = await _uploadController.ImageUpload(formCollecton).ConfigureAwait(true);

            Assert.IsType <BadRequestResult>(response);

            _fileUploadService.Verify(m => m.CopyFile(It.IsAny <IFormFile>(), It.IsAny <string>(), FileMode.Create),
                                      Times.Never);

            _imageService.Verify(m => m.QueueMobileResize(It.IsAny <string>(), It.IsAny <string>(), tags),
                                 Times.Never);

            _uploadTracker.Verify(m => m.AddUpload(userName, It.IsAny <string>()),
                                  Times.Never);
        }
Exemplo n.º 2
0
        public async Task ImageUpload()
        {
            var userName      = "******";
            var fileName      = "Whale Shark.jpg";
            var formCollecton = new MockFormCollection(new MockFormFile(fileName), "tag1", "tag2");
            var tags          = new string[] { "tag1", "tag2", "wdavidsen Upload" };

            SetControllerContext(_uploadController, "POST", userName, formCollecton);

            var cachePath = "c1/A2A44CAE-2EC8-4610-BA4D-6995878B1183.jpg";

            _fileUploadService.Setup(m => m.CopyFile(It.IsAny <IFormFile>(), It.IsAny <string>(), FileMode.Create));
            _imageService.Setup(m => m.QueueMobileResize(userName, It.IsAny <string>(), tags))
            .ReturnsAsync(cachePath)
            .Callback <string, string, string[]>((contextUserName, imageFilePath, tags) =>
            {
                Assert.Equal(fileName, Path.GetFileName(imageFilePath));
            });

            _uploadTracker.Setup(m => m.AddUpload(userName, It.IsAny <string>()))
            .Callback <string, string>((userName, filePath) =>
            {
                Assert.Equal(fileName, Path.GetFileName(filePath));
            });

            var response = await _uploadController.ImageUpload(formCollecton).ConfigureAwait(true);

            Assert.IsType <OkResult>(response);

            _fileUploadService.Verify(m => m.CopyFile(It.IsAny <IFormFile>(), It.IsAny <string>(), FileMode.Create),
                                      Times.Once);

            _imageService.Verify(m => m.QueueMobileResize(It.IsAny <string>(), It.IsAny <string>(), tags),
                                 Times.Once);

            _uploadTracker.Verify(m => m.AddUpload(userName, It.IsAny <string>()),
                                  Times.Once);
        }