Esempio n. 1
0
        public void Should_Error_Get_Data_By_Id()
        {
            var mockFacade = new Mock <IBankExpenditureNoteFacade>();

            mockFacade.Setup(x => x.ReadById(It.IsAny <int>()))
            .Throws(new Exception());

            var mockMapper = new Mock <IMapper>();

            BankExpenditureNoteController controller = new BankExpenditureNoteController(GetServiceProvider().Object, mockFacade.Object, mockMapper.Object);
            var response = controller.GetById(It.IsAny <int>()).Result;

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
Esempio n. 2
0
        public void Should_Not_Found_Get_Data_By_Id()
        {
            var mockFacade = new Mock <IBankExpenditureNoteFacade>();

            mockFacade.Setup(x => x.ReadById(It.IsAny <int>()))
            .ReturnsAsync((BankExpenditureNoteModel)null);

            var mockMapper = new Mock <IMapper>();

            BankExpenditureNoteController controller = new BankExpenditureNoteController(GetServiceProvider().Object, mockFacade.Object, mockMapper.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
            };

            controller.ControllerContext.HttpContext.Request.Headers["Accept"] = "test";

            var response = controller.GetById(It.IsAny <int>()).Result;

            Assert.Equal((int)HttpStatusCode.NotFound, GetStatusCode(response));
        }
Esempio n. 3
0
        public void Should_Success_Get_PDF_By_Id()
        {
            var mockFacade = new Mock <IBankExpenditureNoteFacade>();

            mockFacade.Setup(x => x.ReadById(It.IsAny <int>()))
            .ReturnsAsync(this.Model);

            var mockMapper = new Mock <IMapper>();

            BankExpenditureNoteController controller = new BankExpenditureNoteController(GetServiceProvider().Object, mockFacade.Object, mockMapper.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
            };

            controller.ControllerContext.HttpContext.Request.Headers["Accept"]            = "application/pdf";
            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "0";

            var response = controller.GetById(It.IsAny <int>()).Result;

            Assert.NotEqual(null, response.GetType().GetProperty("FileStream"));
        }