示例#1
0
        public async Task Upload_WhenContentNotMultiPartMIME_ReturnUnsuppportedMediaType()
        {
            // Arrange
            var testResultsController = new TestResultsController(mockedService.Object);

            testResultsController.ControllerContext = FakeControllerContextFactory.CreateTextContext();

            // Act
            var result = await testResultsController.Upload();

            // Assert
            Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, ((StatusCodeResult)result).StatusCode);
        }
示例#2
0
        public async Task Upload_WhenServiceReturnsException_ReturnInternalServerError()
        {
            // Arrange
            var testResultsController = new TestResultsController(mockedService.Object);

            testResultsController.ControllerContext = FakeControllerContextFactory.CreateMIMEContext();
            mockedService.Setup(m => m.Upload(It.IsAny <HttpContent>()))
            .ThrowsAsync(new Exception());

            // Act
            var result = await testResultsController.Upload();

            // Assert
            Assert.AreEqual(typeof(ExceptionResult), result.GetType());
        }
示例#3
0
        public async Task Upload_WhenServiceReturnsNull_ReturnBadRequest()
        {
            // Arrange
            var testResultsController = new TestResultsController(mockedService.Object);

            testResultsController.ControllerContext = FakeControllerContextFactory.CreateMIMEContext();
            mockedService.Setup(m => m.Upload(It.IsAny <HttpContent>()))
            .Returns(Task.FromResult((List <UploadedTestResult>)null));

            // Act
            var result = await testResultsController.Upload();

            // Assert
            Assert.AreEqual(typeof(BadRequestResult), result.GetType());
        }
示例#4
0
        public async Task Upload_WhenServiceReturnsResult_ReturnOk()
        {
            // Arrange
            var testResultsController = new TestResultsController(mockedService.Object);

            testResultsController.ControllerContext = FakeControllerContextFactory.CreateMIMEContext();
            mockedService.Setup(m => m.Upload(It.IsAny <HttpContent>()))
            .Returns(Task.FromResult(new List <UploadedTestResult> {
                new UploadedTestResult
                {
                    BlobUrl  = "MockBlobUrl",
                    FileName = "MockTestFile",
                    FileUrl  = "MockFileUrl"
                }
            }));

            // Act
            var result = await testResultsController.Upload();

            // Assert
            Assert.AreEqual(typeof(OkNegotiatedContentResult <List <UploadedTestResult> >), result.GetType());
        }
示例#5
0
        public async Task Download_WhenResultFound_ReturnsOkWithResult()
        {
            // Arrange
            var testResultsController = new TestResultsController(mockedService.Object);

            testResultsController.ControllerContext = FakeControllerContextFactory.CreateGetRequestContext();
            var resultFile = new TestResultFile
            {
                FileName    = "MockFileName",
                FileSize    = 12121,
                ContentType = "application/zip",
                Stream      = new MemoryStream()
            };

            mockedService.Setup(m => m.Download(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(resultFile));

            // Act
            var result = await testResultsController.Download("TestArchive.zip", "TestResult.txt");

            // Assert
            Assert.AreEqual(typeof(ResponseMessageResult), result.GetType());
            Assert.AreEqual(HttpStatusCode.OK, ((ResponseMessageResult)result).Response.StatusCode);
        }