Ejemplo n.º 1
0
        private AccountingStockReportController GetController(Mock <IAccountingStockReportFacade> facadeM)
        {
            var user   = new Mock <System.Security.Claims.ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

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

            var servicePMock = GetServiceProvider();

            var controller = new AccountingStockReportController(facadeM.Object, servicePMock.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);
        }
Ejemplo n.º 2
0
        public async Task Should_Success_Get_ReportAsync()
        {
            var mockFacade = new Mock <IAccountingStockReportFacade>();

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

            var mockMapper = new Mock <IMapper>();

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

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

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

            controller.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";

            var response = controller.GetReportAccountStock(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>());

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
Ejemplo n.º 3
0
        public void Should_Error_Get_Report_Xls_Data()
        {
            var mockFacade = new Mock <IAccountingStockReportFacade>();

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

            var mockMapper = new Mock <IMapper>();

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

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

            user.Setup(u => u.Claims).Returns(claims);
            AccountingStockReportController controller = new AccountingStockReportController(mockFacade.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 <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <string>());

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

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

            var mockMapper = new Mock <IMapper>();

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

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

            user.Setup(u => u.Claims).Returns(claims);
            AccountingStockReportController controller = new AccountingStockReportController(mockFacade.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 <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <string>());

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