public void Should_Sucess_Get_Excel() { var mockFacade = new Mock <ITransferOutDoc>(); mockFacade.Setup(x => x.GenerateExcel(It.IsAny <int>())) .Returns(new MemoryStream()); var mockMapper = new Mock <IMapper>(); var mockFacadePkbj = new Mock <IPkpbjFacade>(); //var INVFacade = new Mock<IGarmentInvoice>(); var user = new Mock <ClaimsPrincipal>(); var claims = new Claim[] { new Claim("username", "unittestusername") }; user.Setup(u => u.Claims).Returns(claims); TransferOutDocController controller = new TransferOutDocController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object, mockFacadePkbj.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 <int>()); Assert.Equal("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", response.GetType().GetProperty("ContentType").GetValue(response, null)); }
public void Should_Success_Get_All_Data_Retur_By_User() { var validateMock = new Mock <IValidateService>(); validateMock.Setup(s => s.Validate(It.IsAny <TransferOutDocViewModel>())).Verifiable(); var mockFacade = new Mock <ITransferOutDoc>(); var mockFacadePkbj = new Mock <IPkpbjFacade>(); mockFacade.Setup(x => x.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), null, It.IsAny <string>())) .Returns(Tuple.Create(new List <TransferOutDoc>(), 0, new Dictionary <string, string>())); var mockMapper = new Mock <IMapper>(); mockMapper.Setup(x => x.Map <List <TransferOutDocViewModel> >(It.IsAny <List <TransferOutDoc> >())) .Returns(new List <TransferOutDocViewModel> { viewModel }); TransferOutDocController controller = GetController(mockFacade, mockFacadePkbj, validateMock, mockMapper); var response = controller.GetRetur(); Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response)); }
public void Should_Error_Get_All_Data_By_User() { var validateMock = new Mock <IValidateService>(); validateMock.Setup(s => s.Validate(It.IsAny <TransferOutDocViewModel>())).Verifiable(); var mockFacade = new Mock <ITransferOutDoc>(); var mockFacadePkbj = new Mock <IPkpbjFacade>(); mockFacade.Setup(x => x.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), null, It.IsAny <string>())) .Returns(Tuple.Create(new List <TransferOutDoc>(), 0, new Dictionary <string, string>())); var mockMapper = new Mock <IMapper>(); mockMapper.Setup(x => x.Map <List <TransferOutDocViewModel> >(It.IsAny <List <TransferOutDoc> >())) .Returns(new List <TransferOutDocViewModel> { viewModel }); TransferOutDocController controller = new TransferOutDocController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object, mockFacadePkbj.Object); var response = controller.Get(); Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response)); }
public void Should_Error_Get_Excel() { var mockFacade = new Mock <ITransferOutDoc>(); var mockMapper = new Mock <IMapper>(); var mockFacadePkbj = new Mock <IPkpbjFacade>(); TransferOutDocController controller = new TransferOutDocController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object, mockFacadePkbj.Object); var response = controller.GetXls(It.IsAny <int>()); Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response)); }
public void Should_Error_Get_Data_By_Id() { var mockFacade = new Mock <ITransferOutDoc>(); var mockFacadePkbj = new Mock <IPkpbjFacade>(); mockFacade.Setup(x => x.ReadById(It.IsAny <int>())) .Returns(new TransferOutDoc()); var mockMapper = new Mock <IMapper>(); TransferOutDocController controller = new TransferOutDocController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object, mockFacadePkbj.Object); var response = controller.Get(It.IsAny <int>()); Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response)); }
private TransferOutDocController GetController(Mock <ITransferOutDoc> facadeM, Mock <IPkpbjFacade> facadePkbj, Mock <IValidateService> validateM, Mock <IMapper> mapper) { var user = new Mock <ClaimsPrincipal>(); var claims = new Claim[] { new Claim("username", "unittestusername") }; user.Setup(u => u.Claims).Returns(claims); var servicePMock = GetServiceProvider(); if (validateM != null) { servicePMock .Setup(x => x.GetService(typeof(IValidateService))) .Returns(validateM.Object); } TransferOutDocController controller = new TransferOutDocController(servicePMock.Object, mapper.Object, facadeM.Object, facadePkbj.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); }
public async Task Should_Error_Create_Data() { var validateMock = new Mock <IValidateService>(); validateMock.Setup(s => s.Validate(It.IsAny <TransferOutDocViewModel>())).Verifiable(); var mockMapper = new Mock <IMapper>(); mockMapper.Setup(x => x.Map <TransferOutDoc>(It.IsAny <TransferOutDocViewModel>())) .Returns(Model); var mockFacade = new Mock <ITransferOutDoc>(); var mockFacadePkbj = new Mock <IPkpbjFacade>(); mockFacade.Setup(x => x.Create(It.IsAny <TransferOutDocViewModel>(), It.IsAny <TransferOutDoc>(), "unittestusername", 7)) .ReturnsAsync(1); var controller = new TransferOutDocController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object, mockFacadePkbj.Object); var response = await controller.Post(this.viewModel); Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response)); }