public void Should_Fail_Get_Report_Xls() { var mockFacade = new Mock <IGarmentReportCMTFacade>(); mockFacade.Setup(x => x.GenerateExcel(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(new MemoryStream()); var mockMapper = new Mock <IMapper>(); mockMapper.Setup(x => x.Map <List <GarmentReportCMTViewModel> >(It.IsAny <List <GarmentReportCMTViewModel> >())) .Returns(new List <GarmentReportCMTViewModel> { viewModel }); var user = new Mock <System.Security.Claims.ClaimsPrincipal>(); var claims = new Claim[] { new Claim("username", "unittestusername") }; user.Setup(u => u.Claims).Returns(claims); GarmentReportCMTController controller = new GarmentReportCMTController(mockFacade.Object, GetServiceProvider().Object); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user.Object } }; //var dateTo = DateTime.UtcNow.AddDays(1); //var dateFrom = dateTo.AddDays(-30); var response = controller.GetXlsOUT(null, null, 0); Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response)); }
public void Should_Success_Get_Report_Xls() { var mockFacade = new Mock <IGarmentReportCMTFacade>(); mockFacade.Setup(x => x.GenerateExcel(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(new MemoryStream()); var mockMapper = new Mock <IMapper>(); mockMapper.Setup(x => x.Map <List <GarmentReportCMTViewModel> >(It.IsAny <List <GarmentReportCMTViewModel> >())) .Returns(new List <GarmentReportCMTViewModel> { viewModel }); var user = new Mock <System.Security.Claims.ClaimsPrincipal>(); var claims = new Claim[] { new Claim("username", "unittestusername") }; user.Setup(u => u.Claims).Returns(claims); GarmentReportCMTController controller = new GarmentReportCMTController(mockFacade.Object, GetServiceProvider().Object); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user.Object } }; //var dateTo = DateTime.UtcNow.AddDays(1); //var dateFrom = dateTo.AddDays(-30); var response = controller.GetXlsOUT(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <int>()); Assert.Equal("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", response.GetType().GetProperty("ContentType").GetValue(response, null)); }