Esempio n. 1
0
        public void CreateDocumentsAsync_CatchException_BadRequest()
        {
            var fakeDocument        = getFakeDocument();
            var documentsInputModel = new AggregatedDocumentInputModel
            {
                DocumentTypeID = fakeDocument.DocumentTypeID
            };
            IEnumerable <IResult <Document> > fakeCreateResult = new List <IResult <Document> > {
                Result.Ok(fakeDocument)
            };

            _documentServiceMock.Setup(x => x.CreateDocumentsAsync(It.IsAny <IEnumerable <DocumentWithFileInputModel> >()))
            .Throws(new Exception());

            var documentController = new DocumentsController(_documentServiceMock.Object);
            var actionResult       = documentController.CreateDocumentsAsync(documentsInputModel);

            Assert.AreEqual((int)System.Net.HttpStatusCode.BadRequest, (actionResult.Result as BadRequestObjectResult).StatusCode);
        }
Esempio n. 2
0
        public void CreateDocumentsAsync_Success()
        {
            var fakeDocument        = getFakeDocument();
            var documentsInputModel = new AggregatedDocumentInputModel
            {
                Files          = new List <IFormFile>(),
                DocumentTypeID = fakeDocument.DocumentTypeID
            };
            IEnumerable <IResult <Document> > fakeCreateResult = new List <IResult <Document> > {
                Result.Ok(fakeDocument)
            };

            _documentServiceMock.Setup(x => x.CreateDocumentsAsync(It.IsAny <IEnumerable <DocumentWithFileInputModel> >()))
            .Returns(Task.FromResult(fakeCreateResult));

            var documentController = new DocumentsController(_documentServiceMock.Object);
            var actionResult       = documentController.CreateDocumentsAsync(documentsInputModel);

            var documentsResult = ((ObjectResult)actionResult.Result).Value as List <IResult <Document> >;

            Assert.AreEqual(1, documentsResult.Count);
            Assert.AreEqual(fakeDocument.ID, documentsResult.First().Value.ID);
        }