public void Should_Success_Get_Xls_DO() { var mockFacade = new Mock <IGarmentDeliveryOrderFacade>(); mockFacade.Setup(x => x.GenerateExcelDO(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <long>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <int>())) .Returns(new MemoryStream()); var mockMapper = new Mock <IMapper>(); //mockMapper.Setup(x => x.Map<List<GarmentDeliveryOrderReportViewModel>>(It.IsAny<List<GarmentDeliveryOrder>>())) // .Returns(new List<GarmentDeliveryOrderReportViewModel> { ViewModel }); var user = new Mock <ClaimsPrincipal>(); var claims = new Claim[] { new Claim("username", "unittestusername") }; user.Setup(u => u.Claims).Returns(claims); GarmentDeliveryOrderController controller = new GarmentDeliveryOrderController(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.GetXlsDO(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <long>(), It.IsAny <DateTime>(), It.IsAny <DateTime>()); Assert.Equal("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", response.GetType().GetProperty("ContentType").GetValue(response, null)); }
public void Should_Error_Get_Xls_DO() { var mockFacade = new Mock <IGarmentDeliveryOrderFacade>(); var mockMapper = new Mock <IMapper>(); GarmentDeliveryOrderController controller = new GarmentDeliveryOrderController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object); var response = controller.GetXlsDO(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <long>(), It.IsAny <DateTime>(), It.IsAny <DateTime>()); Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response)); }