private void SetupDbComand(bool isAdmin = false) { //setup for UserDbServiceHelper.GetAppUserByIdAsync() because it uses execute scaler MyDbConnection con = new MyDbConnection(); //setup command MyDbCommand command = new MyDbCommand(isAdmin ? 1 : 0 /*not admin*/); command.Connection = con; //setup repository repo.Setup(x => x.CreateDbCommand(It.IsAny <CommandType>(), It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(command); //setup service //Mock<IDbService<AspNetUser>> service = new Mock<IDbService<AspNetUser>>(); userService.Setup(x => x.GetRepo()).Returns(repo.Object); }
public void Get_App_User_By_Id_Async_Should_Return_Null() { //setup connection MyDbConnection con = new MyDbConnection(); //setup command MyDbCommand command = new MyDbCommand(0 /*not admin*/); command.Connection = con; //setup repository Mock <IDbRepository <AspNetUser> > repo = new Mock <IDbRepository <AspNetUser> >(); repo.Setup(x => x.CreateDbCommand(It.IsAny <CommandType>(), It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(command); //setup service Mock <IDbService <AspNetUser> > service = new Mock <IDbService <AspNetUser> >(); service.Setup(x => x.FindSingleWhere(It.IsAny <Expression <Func <AspNetUser, bool> > >())); service.Setup(x => x.GetRepo()).Returns(repo.Object); var data = UserDbServiceHelper.GetAppUserByIdAsync(service.Object, UserOne.Id).Result; Assert.Null(data); }
public void Get_User_By_Shop_Domain_Sould_Return_Valid_User_For_Valid_Shop() { //setup connection MyDbConnection con = new MyDbConnection(); //setup command MyDbCommand command = new MyDbCommand(1 /*admin*/); command.Connection = con; //setup repository Mock <IDbRepository <AspNetUser> > repo = new Mock <IDbRepository <AspNetUser> >(); repo.Setup(x => x.CreateDbCommand(It.IsAny <CommandType>(), It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(command); //setup service Mock <IDbService <AspNetUser> > service = new Mock <IDbService <AspNetUser> >(); service.Setup(x => x.FindSingleWhere(It.IsAny <Expression <Func <AspNetUser, bool> > >())).Returns(UserOne); service.Setup(x => x.GetRepo()).Returns(repo.Object); var data = UserDbServiceHelper.GetUserByShopDomain(service.Object, UserOne.MyShopifyDomain).Result; Assert.NotNull(data); Assert.Equal(UserOne.Id, data.Id); }