Пример #1
0
        public void AddApplicationsToBook_Invalid_BookId()
        {
            // Arrange
            int    bookId         = 0;
            string applicationIds = "1,2,3";

            // Act
            var controller = new ApplicationController(logger.Object, applicationServiceMoq.Object);
            var response   = controller.AddApplicationToBook(bookId, applicationIds) as BadRequestObjectResult;

            // Assert
            Assert.IsType <BadRequestObjectResult>(response);
            Assert.Equal($"Invalid BookId : {bookId} or ApplicationIds : {applicationIds}", response.Value);
        }
Пример #2
0
        public void AddApplicationsToBook_Unsuccessfull()
        {
            // Arrange
            int    bookId         = 1;
            string applicationIds = "1,2,3";
            int    rowsInserted   = 0;

            int[] appIds = Array.ConvertAll(applicationIds.Split(','), int.Parse);
            applicationServiceMoq.Setup(c => c.AddApplications(bookId, appIds)).Returns(rowsInserted);

            // Act
            var controller = new ApplicationController(logger.Object, applicationServiceMoq.Object);
            var response   = controller.AddApplicationToBook(bookId, applicationIds) as NotFoundObjectResult;

            // Assert
            Assert.IsType <NotFoundObjectResult>(response);
            Assert.Equal("Failed to insert", response.Value);
            applicationServiceMoq.Verify(c => c.AddApplications(bookId, appIds), Times.Once);
        }