Ejemplo n.º 1
0
        public void Should_Error_Get_Report_Xls_Data()
        {
            var mockFacade = new Mock <IDebtBookReportFacade>();

            mockFacade.Setup(x => x.GetDebtBookReport(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>()))
            .Returns(Tuple.Create(new List <DebtBookReportViewModel> {
                viewModel
            }, 25));

            var mockMapper = new Mock <IMapper>();

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

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

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

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user.Object
                }
            };
            //controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "0";
            var response = controller.GetXls(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>());

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
Ejemplo n.º 2
0
        public void Should_Success_Get_Xls()
        {
            var mockFacade = new Mock <IDebtBookReportFacade>();

            mockFacade.Setup(x => x.GenerateExcelDebtReport(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>()))
            .Returns(new MemoryStream());

            var mockMapper = new Mock <IMapper>();

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

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

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

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

            //controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "0";
            var response = controller.GetXls(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>());

            Assert.Equal("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", response.GetType().GetProperty("ContentType").GetValue(response, null));
        }