Example #1
0
        private UnitPaymentQuantityCorrectionNoteReportController GetController(Mock <IUnitPaymentQuantityCorrectionNoteFacade> facadeM, Mock <IValidateService> validateM, Mock <IMapper> mapper)
        {
            var user   = new Mock <ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

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

            var servicePMock = GetServiceProvider();

            servicePMock
            .Setup(x => x.GetService(typeof(IValidateService)))
            .Returns(validateM.Object);

            UnitPaymentQuantityCorrectionNoteReportController controller = new UnitPaymentQuantityCorrectionNoteReportController(servicePMock.Object, mapper.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);
        }
Example #2
0
        public void Should_Success_Get_Report_Xls_Data()
        {
            var mockFacade = new Mock <IUnitPaymentQuantityCorrectionNoteFacade>();

            mockFacade.Setup(x => x.GenerateExcel(null, null, It.IsAny <int>()))
            .Returns(new MemoryStream());

            var mockMapper = new Mock <IMapper>();

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

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

            user.Setup(u => u.Claims).Returns(claims);
            UnitPaymentQuantityCorrectionNoteReportController controller = new UnitPaymentQuantityCorrectionNoteReportController(GetServiceProvider().Object, mockMapper.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.GetXls(null, null);

            Assert.Null(response.GetType().GetProperty("FileStream"));
        }
Example #3
0
        public void Should_Error_Get_Report_Data()
        {
            var mockFacade = new Mock <IUnitPaymentQuantityCorrectionNoteFacade>();

            var mockMapper = new Mock <IMapper>();


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

            user.Setup(u => u.Claims).Returns(claims);
            UnitPaymentQuantityCorrectionNoteReportController controller = new UnitPaymentQuantityCorrectionNoteReportController(GetServiceProvider().Object, mockMapper.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 #4
0
        public void Should_Error_Get_Report_Xls_Data()
        {
            var mockFacade = new Mock <IUnitPaymentQuantityCorrectionNoteFacade>();

            mockFacade.Setup(x => x.GetReport(null, null, It.IsAny <int>(), It.IsAny <int>(), "{}", It.IsAny <int>()))
            .Returns(Tuple.Create(new List <UnitPaymentQuantityCorrectionNoteReportViewModel> {
                ViewModel
            }, 25));

            var mockMapper = new Mock <IMapper>();

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

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

            user.Setup(u => u.Claims).Returns(claims);
            UnitPaymentQuantityCorrectionNoteReportController controller = new UnitPaymentQuantityCorrectionNoteReportController(GetServiceProvider().Object, mockMapper.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.GetXls(null, null);

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }