Example #1
0
        public void Should_Error_Get_Report_Data()
        {
            var mockFacade = new Mock <IMonitoringCorrectionNoteExpenditureFacade>();

            mockFacade.Setup(x => x.GetMonitoringKeluarNKReport(null, null, 1, 25, "{}", 7))
            .Returns(Tuple.Create(new List <MonitoringCorrectionNoteExpenditureViewModel> {
                ViewModel
            }, 25));

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <List <MonitoringCorrectionNoteExpenditureViewModel> >(It.IsAny <List <MonitoringCorrectionNoteExpenditureViewModel> >()))
            .Returns(new List <MonitoringCorrectionNoteExpenditureViewModel> {
                ViewModel
            });

            var user   = new Mock <ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

            user.Setup(u => u.Claims).Returns(claims);
            MonitoringCorrectionNoteExpenditureController controller = new MonitoringCorrectionNoteExpenditureController(GetServiceProvider().Object, mockFacade.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user.Object
                }
            };
            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "0";
            var response = controller.GetReport(null, null, 1, 25, "{}");

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
Example #2
0
        private MonitoringCorrectionNoteExpenditureController GetController(Mock <IMonitoringCorrectionNoteExpenditureFacade> facadeM, Mock <IValidateService> validateM, Mock <IMapper> mapper, Mock <IGarmentDeliveryOrderFacade> facadeDO)
        {
            var user   = new Mock <ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

            user.Setup(u => u.Claims).Returns(claims);

            var servicePMock = GetServiceProvider();

            if (validateM != null)
            {
                servicePMock
                .Setup(x => x.GetService(typeof(IValidateService)))
                .Returns(validateM.Object);
            }

            var controller = new MonitoringCorrectionNoteExpenditureController(servicePMock.Object, facadeM.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = user.Object
                    }
                }
            };

            controller.ControllerContext.HttpContext.Request.Headers["Authorization"] = "Bearer unittesttoken";
            controller.ControllerContext.HttpContext.Request.Path = new PathString("/v1/unit-test");
            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "7";

            return(controller);
        }