public User GetUserByName(string userName) { List <User> users = repo.GetUsers(user => user.UserName.Equals(userName)); if (users.Count == 0) { return(null); } if (users.Count > 1) { throw new Exception($"Multiple users with the same name: {userName}"); } return(users[0]); }
public void GetUsersShouldGetAllUsers() { using (var ctx = new StoreContext(options)) { StoreRepoDB repo = new StoreRepoDB(ctx); for (int i = 0; i < 5; i++) { User testUser = new User(); testUser.UserName = $"Test{i}"; testUser.isManager = true; ctx.Users.Add(testUser); } ctx.SaveChanges(); } using (var assertCtx = new StoreContext(options)) { StoreRepoDB repo = new StoreRepoDB(assertCtx); var users = repo.GetUsers(user => true); Assert.NotNull(users); Assert.Equal(5, users.Count); } }