Example #1
0
        public async Task DownloadSuccess()
        {
            bool   shouldSucceed = true;
            string filename      = "SuccessDownload.txt";
            string content       = "Successful downloaded content";

            // Setup cloud provider with a file
            ICloudProvider cloudProvider = new MockCloudProvider(shouldSucceed);

            this.UploadFile(filename, content, cloudProvider);

            var controller = new DownloadController(cloudProvider);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            var result = await controller.DownloadFile(filename);

            Assert.That(result, Is.Not.EqualTo(null));

            // verify the contents of the file stream
            Assert.That(result, Is.InstanceOf(typeof(FileStreamResult)));
            FileStreamResult fileStreamResult = result as FileStreamResult;

            Assert.That(fileStreamResult.FileStream, Is.Not.EqualTo(null));
            string fileString = new StreamReader(fileStreamResult.FileStream).ReadToEnd();

            Assert.That(fileString, Is.EqualTo(content));
        }
        public async Task When_downloading_a_file_then_the_file_is_returned_in_the_response()
        {
            var applicationId = Guid.NewGuid();
            var sequenceNo    = 1;
            var sectionNo     = 2;
            var pageId        = "page";
            var questionId    = "question";
            var fileName      = "file";

            var httpResponse = new HttpResponseMessage(HttpStatusCode.OK);
            var stream       = new MemoryStream();

            httpResponse.Content = new StreamContent(stream);

            var mediaType = "application/pdf";

            httpResponse.Content.Headers.ContentType = new MediaTypeHeaderValue(mediaType);

            _apiClient.Setup(x => x.DownloadFile(applicationId, sequenceNo, sectionNo, pageId, questionId, fileName)).ReturnsAsync(httpResponse);

            var response = await _controller.DownloadFile(applicationId, sequenceNo, sectionNo, pageId, questionId, fileName);

            var fileStreamResponse = response as FileStreamResult;

            Assert.IsNotNull(fileStreamResponse.FileStream);
            Assert.AreEqual(mediaType, fileStreamResponse.ContentType);
            Assert.AreEqual(fileName, fileStreamResponse.FileDownloadName);
        }
Example #3
0
        public async Task DownloadFailure()
        {
            bool shouldSucceed = false;
            var  controller    = new DownloadController(new MockCloudProvider(shouldSucceed));

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            var result = await controller.DownloadFile("testfile.txt");

            Assert.That(result, Is.Not.EqualTo(null));
            Assert.That(result, Is.InstanceOf(typeof(NotFoundResult)));
        }