Exemple #1
0
        public void ShouldFilterPayloadDataAndReturnErrorMessage()
        {
            var dataProvider = new DataProvider();
            var o            = dataProvider.PayloadData();
            var r            = dataProvider.PayloadResponseData();

            var m = new Mock <IDataService>();

            m.Setup(mock => mock.FilterPayload(o)).Returns(r.Response);
            m.Setup(mock => mock.ValidatePayload(o)).Returns(true);

            var controller = new PayloadController(m.Object);
            var response   = controller.FilterPayload(o);

            var result = response as OkNegotiatedContentResult <PayloadResponseDto>;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            var a = r.Response.ToList();
            var b = result.Content.Response.ToList();

            for (var i = 0; i < 7; i++)
            {
                Assert.IsTrue(a[i].Image == b[i].Image, string.Format("fail at {0}", i));
                Assert.IsTrue(a[i].Slug == b[i].Slug, string.Format("fail at {0}", i));
                Assert.IsTrue(a[i].Title == b[i].Title, string.Format("fail at {0}", i));
            }
        }
Exemple #2
0
        public void ShouldThrowError()
        {
            IDataService service    = new DataService();
            var          controller = new PayloadController(service);

            var response = controller.FilterPayload(null);

            var result = response as NegotiatedContentResult <ErrorMessageDto>;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.IsTrue(result.StatusCode == HttpStatusCode.BadRequest);
            Assert.IsTrue(result.Content.Error == "Could not decode request: JSON parsing failed");
        }
        public async Task DownloadsTheUploadedFileFromController()
        {
            // Arrange
            using (var contentStream = new MemoryStream())
            {
                PayloadController controller = AnonymousPayloadController;
                await SerializeExpectedContentStream(contentStream, controller);

                AssignRequestUri(controller.ControllerContext.HttpContext.Request);

                // Act
                var actualResult = await controller.Upload() as ObjectResult;

                // Assert
                var actualUploadResult = actualResult?.Value as UploadResult;
                Assert.True(IsDownloadUrlAMatch(actualUploadResult), $"Actual Request Uri doesn't match the expected Uri '{ExpectedRequestUri}'");

                StreamedFileResult downloadResult = await DownloadPayload(controller, actualUploadResult);

                StreamedFileResultAssert.OnContent(
                    downloadResult, actualContent => Assert.Equal(ExpectedContent, actualContent));
            }
        }
        private static async Task <StreamedFileResult> DownloadPayload(PayloadController controller, UploadResult actualResult)
        {
            string payloadId = actualResult.PayloadId.Split('/').Last();

            return(await controller.Download(payloadId) as StreamedFileResult);
        }