Esempio n. 1
0
        public async Task Post_WhenDocumentIsMissing_ThenReturnsBadRequest()
        {
            var serviceMock = new Mock <IDocumentService>();

            serviceMock.Setup(x => x.Get(It.IsAny <Guid>())).ReturnsAsync(default(Document));

            var sut      = new DocumentContentController(serviceMock.Object, null);
            var expected = await sut.Post(Guid.Empty, null);

            expected.Should().BeOfType <BadRequestObjectResult>();
        }
Esempio n. 2
0
        public async Task Get_WhenFailure_ThenReturnsInternalServerError()
        {
            var serviceMock        = new Mock <IDocumentService>();
            var contentServiceMock = new Mock <IDocumentContentService>();

            serviceMock.Setup(x => x.Get(It.IsAny <Guid>())).ReturnsAsync(new Document());
            contentServiceMock.Setup(x => x.Store(It.IsAny <Guid>(), It.IsAny <IFormFile>())).ReturnsAsync(true);

            var sut      = new DocumentContentController(serviceMock.Object, contentServiceMock.Object);
            var expected = await sut.Post(Guid.Empty, null);

            expected.Should().BeOfType <OkResult>();
        }
Esempio n. 3
0
        public async Task Get_WhenContentIsMissing_ThenReturnsInternalServerError()
        {
            var serviceMock        = new Mock <IDocumentService>();
            var contentServiceMock = new Mock <IDocumentContentService>();

            serviceMock.Setup(x => x.Get(It.IsAny <Guid>())).ReturnsAsync(new Document());
            contentServiceMock.Setup(x => x.Get(It.IsAny <Guid>())).ReturnsAsync(default(DocumentContent));

            var sut      = new DocumentContentController(serviceMock.Object, contentServiceMock.Object);
            var expected = await sut.Get(Guid.Empty);

            expected.As <StatusCodeResult>().StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
Esempio n. 4
0
        public async Task Get_WhenSuccess_ThenReturnsFile()
        {
            var serviceMock        = new Mock <IDocumentService>();
            var contentServiceMock = new Mock <IDocumentContentService>();

            serviceMock.Setup(x => x.Get(It.IsAny <Guid>())).ReturnsAsync(new Document());
            contentServiceMock.Setup(x => x.Get(It.IsAny <Guid>())).ReturnsAsync(new DocumentContent()
            {
                Content = new byte[1], Name = "aa.text", ContentType = "text/plain"
            });

            var sut      = new DocumentContentController(serviceMock.Object, contentServiceMock.Object);
            var expected = await sut.Get(Guid.Empty);

            expected.Should().BeOfType <FileContentResult>();
        }