public void FaillingTestInsertUser() { var userAdmin = new User { UserName = "******", Role = "Admin", Enabled = false }; //Action var chkInsert = userService.Insert(userAdmin); // Assert moqIDALContext.Verify(m => m.Users.Create(userAdmin), Times.Never()); moqIDALContext.Verify(m => m.SaveChanges(), Times.Never()); Assert.Equal(false, chkInsert); }
public void TestInsertUserSuccessfull() { var userAdmin = new User { UserName = "******", Role = "Admin", Enabled = true }; //Action var chkInsert = userService.Insert(userAdmin); // Assert moqIDALContext.Verify(m => m.Users.Create(userAdmin), Times.Exactly(1)); moqIDALContext.Verify(m => m.SaveChanges(), Times.Exactly(1)); // Statebased testing Assert.Equal(true, chkInsert); }
/// <summary> /// Return 1: New User has succeeded to register. /// Return 0: Has exception /// Return 2: UserName or Email is already in system. /// </summary> /// z /// <param name="user"></param> /// <returns></returns> public int Register(User user) { if (CheckUser(user)) { try { context.Users.Create(user); context.SaveChanges(); return 0; } catch (Exception exception) { _logService.LogError("Function Register: {0}", exception); return 2; } } return 1; }
public TestBussiness() { user = new User { UserName = "******", Role = "Tester", Enabled = true }; var users = new List<User> { new User{UserId = 1, UserName = "******", Role = "Description",Enabled = true}, new User{UserId = 2, UserName = "******", Role = "PM",Enabled = true}, new User{UserId = 3, UserName = "******", Role = "QA",Enabled = true}, }; // Setup moqIDALContext = new Mock<IDALContext>(); //moqIDALContext.Setup(db => db.Users).Verifiable(); // Assert _IDALContext = moqIDALContext.Object; userService = new UserService(_IDALContext); }
public void SetUp() { user = new User { UserName = "******", Role = "Tester", Enabled = true }; List<User> users = new List<User> { new User{UserId = 1, UserName = "******", Role = "Description",Enabled = true}, new User{UserId = 2, UserName = "******", Role = "PM",Enabled = true}, new User{UserId = 3, UserName = "******", Role = "QA",Enabled = true}, }; moqService = new Mock<IUserService>(); moqService.Setup(mUserS => mUserS.GetAll()).Returns(users); moqService.Setup(mUserS => mUserS.Insert(user)).Returns(true); logService = new FileLogManager(typeof(HomeController)); userService = moqService.Object; }
public ActionResult Insert(User objUser) { return null; }
public User Update(User user) { context.Users.Update(user); context.SaveChanges(); return user; }
public bool Delete(User user) { context.Users.Delete(user); context.SaveChanges(); return true; }
public bool CheckUser(User user) { if (user == null) return false; var check = context.Users.All().FirstOrDefault(x => x.UserName == user.UserName || x.Email == user.Email); return check != null; }