private OrdersController GetController() { var userManagerMock = new Mock <IUserManager>(); var dataManagerMock = new Mock <IDataManager>(); userManagerMock.Setup(x => x.FindUserByName(It.IsAny <string>())) .Returns <string>(a => Task.FromResult(DomainTestUtil.GetTestUsers(1)[0])); dataManagerMock.Setup(x => x.OrderRepository.GetAllEntities()) .Returns(DomainTestUtil.GetTestOrders()); dataManagerMock.Setup(x => x.OrderRepository.GetEntity(It.IsAny <Guid>())) .Returns <Guid>(a => DomainTestUtil.GetTestOrders(1)[0]); return(new OrdersController(dataManagerMock.Object, userManagerMock.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new GenericIdentity("test")) } } }); }
private ProfileController GetController( bool changeablePassword = true, bool confirmablePhoneNumber = true, bool findsByPhoneNumber = true ) { var testUser = DomainTestUtil.GetTestUsers(1)[0]; var dataManagerMock = new Mock <IDataManager>(); var userManagerMock = new Mock <IUserManager>(); var userManagerHelperMock = new Mock <IUserManagerHelper>(); var smsServiceMock = new Mock <ISmsService>(); var imageServiceMock = new Mock <IImageService>(); var environmentMock = new Mock <IWebHostEnvironment>(); dataManagerMock.Setup(x => x.OrderRepository.GetAllEntities()) .Returns(DomainTestUtil.GetTestOrders()); userManagerMock.Setup(x => x.FindUserByName(It.IsAny <string>())) .Returns <string>(a => Task.FromResult(testUser)); userManagerMock.Setup(x => x.FindUserById(It.IsAny <Guid>())) .Returns <Guid>(a => Task.FromResult(DomainTestUtil.GetTestUsers(1)[0])); userManagerMock.Setup(x => x.FindUserByPhoneNumber(It.IsAny <string>())) .Returns <string>(a => Task.FromResult(findsByPhoneNumber ? testUser : null)); userManagerMock.Setup(x => x.ChangeUserPassword(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>())) .Returns <Guid, string, string>((a, b, c) => Task.FromResult(changeablePassword)); userManagerMock.Setup(x => x.ConfirmPhoneNumber(It.IsAny <Guid>(), It.IsAny <string>())) .Returns <Guid, string>((a, b) => Task.FromResult(confirmablePhoneNumber)); return(new ProfileController( dataManagerMock.Object, userManagerMock.Object, userManagerHelperMock.Object, smsServiceMock.Object, imageServiceMock.Object, environmentMock.Object ) { ObjectValidator = ControllerTestUtil.GetObjectModelValidatorMock().Object, TempData = new TempDataDictionary(new DefaultHttpContext(), Mock.Of <ITempDataProvider>()), ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new GenericIdentity("test")) } } }); }
private PurchaseDetailsController GetController() { var dataManagerMock = new Mock <IDataManager>(); dataManagerMock.Setup(x => x.PurchaseDetailRepository.GetAllEntities()) .Returns(DomainTestUtil.GetTestPurchaseDetails()); dataManagerMock.Setup(x => x.PurchaseDetailRepository.GetEntity(It.IsAny <Guid>())) .Returns <Guid>(a => DomainTestUtil.GetTestPurchaseDetails(1)[0]); dataManagerMock.Setup(x => x.PurchaseDetailRepository.SaveEntity(It.IsAny <PurchaseDetail>())) .Returns <PurchaseDetail>(a => Guid.NewGuid()); dataManagerMock.Setup(x => x.OrderRepository.GetAllEntities()) .Returns(DomainTestUtil.GetTestOrders()); dataManagerMock.Setup(x => x.ProductRepository.GetAllEntities()) .Returns(DomainTestUtil.GetTestProducts()); dataManagerMock.Setup(x => x.ProductRepository.GetEntity(It.IsAny <Guid>())) .Returns <Guid>(a => DomainTestUtil.GetTestProducts(1)[0]); return(new PurchaseDetailsController(dataManagerMock.Object) { ObjectValidator = ControllerTestUtil.GetObjectModelValidatorMock().Object }); }
private OrdersController GetController() { var dataManagerMock = new Mock <IDataManager>(); dataManagerMock.Setup(x => x.OrderRepository.GetAllEntities()) .Returns(DomainTestUtil.GetTestOrders()); dataManagerMock.Setup(x => x.OrderRepository.GetEntity(It.IsAny <Guid>())) .Returns <Guid>(a => DomainTestUtil.GetTestOrders(1)[0]); dataManagerMock.Setup(x => x.OrderRepository.SaveEntity(It.IsAny <Order>())) .Returns <Order>(a => Guid.NewGuid()); var userManagerMock = new Mock <IUserManager>(); userManagerMock.Setup(x => x.GetAllUsers()) .Returns(DomainTestUtil.GetTestUsers()); userManagerMock.Setup(x => x.FindUserById(It.IsAny <Guid>())) .Returns <Guid>(a => Task.FromResult(DomainTestUtil.GetTestUsers(1)[0])); return(new OrdersController(dataManagerMock.Object, userManagerMock.Object) { ObjectValidator = ControllerTestUtil.GetObjectModelValidatorMock().Object }); }
private ManagingController GetController() { var dataManagerMock = new Mock <IDataManager>(); dataManagerMock.Setup(x => x.OrderRepository.GetAllEntities()) .Returns(DomainTestUtil.GetTestOrders()); dataManagerMock.Setup(x => x.OrderRepository.GetEntity(It.IsAny <Guid>())) .Returns <Guid>(a => DomainTestUtil.GetTestOrders(1)[0]); var notificationHubContextMock = new Mock <IHubContext <NotificationHub> >(); var userConnectionManagerMock = new Mock <IUserConnectionManager>(); var emailServiceMock = new Mock <IEmailService>(); return(new ManagingController( dataManagerMock.Object, notificationHubContextMock.Object, userConnectionManagerMock.Object, emailServiceMock.Object ) { ObjectValidator = ControllerTestUtil.GetObjectModelValidatorMock().Object }); }