public void TestContainUser() { var user = new User() { Name = "Hung" }; // ReSharper disable once UseObjectOrCollectionInitializer var tasks = new Task(); tasks.Users = new List<User> { new User() { Name = "" } }; var result = tasks.ContainUser(user); Assert.AreEqual(true, result); Assert.IsNotNull(user); }
/// <summary> /// Method to list of task of the selected user /// and seleted state in TaskRepostory class /// </summary> /// <param name="user"></param> /// <param name="state"></param> /// <returns></returns> public IList<Task> GetUserTasks(User user, TaskState state) { var listTasks = new List<Task>(); // ReSharper disable once InvertIf if (user != null) { // ReSharper disable once LoopCanBeConvertedToQuery foreach (var task in Tasks) { var result = task.ContainUser(user); if (result && task.State == state) { listTasks.Add(task); } } } return listTasks; }
/// <summary> /// Create method check parameters user have same with user in the task /// </summary> /// <param name="name"></param> /// <returns></returns> public bool ContainUser(User name) { // ReSharper disable once InvertIf if (Users != null && name != null) { // ReSharper disable once LoopCanBeConvertedToQuery foreach (var user in Users) { if (user.Name == name.Name) { return true; } } } return false; }