public void Should_Success_Get_Report_Xls_Data() { var mockFacade = new Mock<IUnitPaymentPriceCorrectionNoteFacade>(); mockFacade.Setup(x => x.GenerateExcel(null, null, It.IsAny<int>())) .Returns(new MemoryStream()); var mockMapper = new Mock<IMapper>(); mockMapper.Setup(x => x.Map<List<UnitPaymentPriceCorrectionNoteReportViewModel>>(It.IsAny<List<UnitPaymentCorrectionNote>>())) .Returns(new List<UnitPaymentPriceCorrectionNoteReportViewModel> { ViewModel }); var user = new Mock<ClaimsPrincipal>(); var claims = new Claim[] { new Claim("username", "unittestusername") }; user.Setup(u => u.Claims).Returns(claims); UnitPaymentPriceCorrectionNoteReportController controller = new UnitPaymentPriceCorrectionNoteReportController(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.GetXls(null, null); Assert.Equal(null, response.GetType().GetProperty("FileStream")); }
public void Should_Error_Get_Report_Xls_Data() { var mockFacade = new Mock<IUnitPaymentPriceCorrectionNoteFacade>(); mockFacade.Setup(x => x.GetReport(null, null, It.IsAny<int>(), It.IsAny<int>(), "{}", It.IsAny<int>())) .Returns(Tuple.Create(new List<UnitPaymentPriceCorrectionNoteReportViewModel> { ViewModel }, 25)); var mockMapper = new Mock<IMapper>(); mockMapper.Setup(x => x.Map<List<UnitPaymentPriceCorrectionNoteReportViewModel>>(It.IsAny<List<UnitPaymentCorrectionNote>>())) .Returns(new List<UnitPaymentPriceCorrectionNoteReportViewModel> { ViewModel }); var user = new Mock<ClaimsPrincipal>(); var claims = new Claim[] { new Claim("username", "unittestusername") }; user.Setup(u => u.Claims).Returns(claims); UnitPaymentPriceCorrectionNoteReportController controller = new UnitPaymentPriceCorrectionNoteReportController(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.GetXls(null, null); Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response)); }