예제 #1
0
        public void Should_Error_Xls_Get_All_Data()
        {
            var mockFacade = new Mock <IGarmentPurchaseDayBookReport>();

            var mockMapper = new Mock <IMapper>();

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

            user.Setup(u => u.Claims).Returns(claims);
            GarmentPurchaseDayBookReportController controller = GetController(mockFacade, null, mockMapper);

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

            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "0";
            var year     = DateTime.UtcNow.Year;
            var response = controller.GetXls(null, false, null, null, year, 0, 0, "");

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
예제 #2
0
        public void Should_Success_Xls_Get_All_Data()
        {
            var mockFacade = new Mock <IGarmentPurchaseDayBookReport>();

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

            var mockMapper = new Mock <IMapper>();

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

            user.Setup(u => u.Claims).Returns(claims);
            GarmentPurchaseDayBookReportController controller = GetController(mockFacade, null, mockMapper);

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

            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "0";
            var year     = DateTime.UtcNow.Year;
            var response = controller.GetXls(null, false, null, null, year, 0, 0, "");

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