public bool ValidateTask(string text, UserView owner, TaskType? type, int? size, int? value, Nullable<DateTime> completion, TaskState? state) { bool result = true; result &= (text != null && text.Length > 0); // Text is required result &= (type.HasValue); // Type is required result &= (size.HasValue && EnumValues.sizeComplexity.Contains(size.Value)); // Size complexity is required to be one of a set of values result &= (value.HasValue && EnumValues.businessValue.Contains(value.Value)); // Business value is required to be one of a set of values // If the owner is null, the state must be Unassigned. Otherwise the state cannot be Unassigned result &= (state.HasValue && ((owner == null && state.Value == TaskState.Unassigned) || (owner != null && state.Value != TaskState.Unassigned))); result &= (state.HasValue && (state.Value != TaskState.Completed || completion.HasValue)); // A completed task must have a completed date if (CurrSprint != null && completion.HasValue) { result &= (completion.Value >= CurrSprint.StartDate); // Tasks must be completed within their sprint if (CurrSprint.EndDate.HasValue) { result &= (completion.Value <= CurrSprint.EndDate.Value); // Tasks must be completed within their sprint } } return result; }
/// <summary> /// Checks if user input for a team is valid /// </summary> /// <param name="name">The name of the team</param> /// <param name="manager">The manager of the team</param> /// <param name="lead">The team lead</param> /// <returns>True if the data is valid, false otherwise</returns> public bool ValidateTeam(string name, UserView manager, UserView lead) { bool result = true; result &= (name != null && name.Length > 0 && name.Length <= 50); // Name between 1 and 50 characters result &= (manager != null); // Manager is required result &= (lead != null); // Team lead is required return result; }
/// <summary> /// Moves a user to a given team /// </summary> /// <param name="user">The user to change</param> /// <param name="team">The team to which to move the user</param> /// <returns>True if moving the user succeeds, false otherwise</returns> public bool MoveUserToTeam(UserView user, TeamView team) { if (!_isLoggedIn) { throw new InvalidOperationException("User must be logged in"); } if (user == null || team == null) { throw new ArgumentNullException("Arguments to ChangeTeam must not be null"); } bool result = _dataModel.MoveUserToTeam(user.UserID, team.TeamID); if (result && user.UserID == CurrUser.UserID) { CurrTeam = team; updateProjectsForUser(); } return result; }
/// <summary> /// Checks if user input for a project is valid /// </summary> /// <param name="name">The name of the project</param> /// <param name="startDate">The start date of the project</param> /// <param name="endDate">The end date of the project</param> /// <param name="owner">The owner of the project</param> /// <param name="team">The team responsible for the project</param> /// <returns>True if the data is valid, false otherwise</returns> public bool ValidateProject(string name, Nullable<DateTime> startDate, Nullable<DateTime> endDate, UserView owner, TeamView team) { bool result = true; result &= (name != null && name.Length > 0 && name.Length <= 50); // Name between 1 and 50 characters result &= startDate.HasValue; // Start date is required if (startDate.HasValue && endDate.HasValue) { result &= (startDate.Value < endDate.Value); // Sprint must start before it ends } result &= (owner != null); // Owner is required result &= (team != null); // Team is required return result; }
public Dictionary<UserView, int[]> GetCurrSprintUserStatus() { if (!_isLoggedIn || CurrSprint == null) { throw new InvalidOperationException("User must be logged in"); } else if (CurrSprint.StartDate > DateTime.Today) { throw new InvalidOperationException("The sprint must have started to view its task status"); } IEnumerable<User> users = _dataModel.GetTeamMembers(_dataModel.GetProjectByID(CurrSprint.ProjectID).Team_id); IEnumerable<Task> allTasks = _dataModel.GetAllTasksForSprint(CurrSprint.SprintID); Dictionary<UserView, int[]> results = new Dictionary<UserView, int[]>(); foreach (User u in users) { IEnumerable<TaskView> tasks = allTasks.Where(task => task.Owner.HasValue && task.Owner.Value == u.User_id).Select(t => new TaskView(t)); UserView user = new UserView(u); int[] vals = { tasks.Count(t => t.State == TaskState.Completed), tasks.Count(t => t.State == TaskState.In_Progress), tasks.Count(t => t.State == TaskState.Blocked), }; results.Add(user, vals); } return results; }
/// <summary> /// Gets the Team for a User /// </summary> /// <param name="user">The User for which to get the team</param> /// <returns>The Team to which the given user belongs</returns> public TeamView GetTeamForUser(UserView user) { if (!_isLoggedIn) { throw new InvalidOperationException("User must be logged in"); } else if (user == null) { throw new ArgumentNullException("Arguments to GetUserTeam must not be null"); } Team team = _dataModel.GetTeamByID(user.TeamId); if (team != null) { return new TeamView(team); } else { return null; } }
/// <summary> /// Creates a new task /// </summary> /// <param name="text">The text of this task</param> /// <param name="size">The size complexity of this task</param> /// <param name="value">The business value of this task</param> /// <param name="owner">The user who owns this task</param> /// <param name="type">The type of this task</param> /// <param name="state">The state of this task</param> /// <returns>True if creating the task succeeds, false otherwise</returns> public bool CreateTask(string text, int size, int value, UserView owner, TaskType type, TaskState state, Nullable<DateTime> completionDate) { if (!_isLoggedIn || CurrStory == null) { throw new InvalidOperationException("User must be logged in"); } else if (owner == null && state != TaskState.Unassigned) // Giving an unassigned task any state but unassigned is not allowed { throw new InvalidOperationException("A task without an owner must be marked Unassigned"); } else if (!EnumValues.businessValue.Contains(value) || !EnumValues.sizeComplexity.Contains(size)) { throw new ArgumentOutOfRangeException("Invalid complexity value"); } else if ((state == TaskState.Completed && !completionDate.HasValue) || (state != TaskState.Completed && completionDate.HasValue)) { throw new InvalidOperationException("A task has a completion date iff it is completed"); } else if (text == null) { throw new ArgumentNullException("Arguments to AddTask must not be null"); } bool result = _dataModel.CreateTask(text, size, value, owner == null ? null : new int?(owner.UserID), type.ConvertToBinary(), state.ConvertToBinary(), CurrStory.StoryID, completionDate); updateTasksForStory(); updateTasksForUser(); return result; }
/// <summary> /// Creates a new team /// </summary> /// <param name="name">The name of the new team</param> /// <param name="manager">The manager of the new team</param> /// <param name="lead">The team lead for the new team</param> /// <returns>True if creating the team succeeds, false otherwise</returns> public bool CreateTeam(string name, UserView manager, UserView lead) { if (!_isLoggedIn) { throw new InvalidOperationException("User must be logged in"); } else if (manager == null || lead == null || name == null) { throw new ArgumentNullException("Arguments to AddTeam must not be null"); } return _dataModel.CreateTeam(name, manager.UserID, lead.UserID); }
/// <summary> /// Creates a new project /// </summary> /// <param name="name">The name of the project</param> /// <param name="startDate">The start date of the project</param> /// <param name="endDate">The end date of the project</param> /// <param name="owner">The User who owns the new project</param> /// <param name="team">The team responsible for the new project</param> /// <returns>True if creating the project succeeds, false otherwise</returns> public bool CreateProject(string name, Nullable<DateTime> startDate, Nullable<DateTime> endDate, UserView owner, TeamView team) { if (!_isLoggedIn) { throw new InvalidOperationException("User must be logged in"); } else if (name == null || owner == null || team == null || !startDate.HasValue) { throw new ArgumentNullException("Arguments to AddProject must not be null"); } bool result = _dataModel.CreateProject(name, startDate.Value, endDate, owner.UserID, team.TeamID); updateProjectsForUser(); return result; }
/// <summary> /// Updates the current task /// </summary> /// <param name="text">The text of this task</param> /// <param name="size">The size complexity of this task</param> /// <param name="value">The business value of this task</param> /// <param name="owner">The user who owns this task</param> /// <param name="type">The type of this task</param> /// <param name="state">The state of this task</param> /// <param name="completion">The date this task was completed</param> /// <returns>True if the changes succeed, false otherwise</returns> public bool ChangeCurrTask(string text, int size, int value, UserView owner, TaskType type, TaskState state, Nullable<DateTime> completion) { if (!_isLoggedIn || CurrTask == null) { throw new InvalidOperationException("User must be logged in"); } else if (owner == null && state != TaskState.Unassigned) // Giving an unassigned task any state but unassigned is not allowed { throw new InvalidOperationException("A task without an owner must be marked Unassigned"); } else if (!EnumValues.businessValue.Contains(value) || !EnumValues.sizeComplexity.Contains(size)) { throw new ArgumentOutOfRangeException("Invalid complexity value"); } else if (text == null) { throw new ArgumentNullException("Arguments to AddTask must not be null"); } bool result = _dataModel.ChangeTask(CurrTask.TaskID, text, size, value, owner == null ? null : new int?(owner.UserID), type.ConvertToBinary(), state.ConvertToBinary(), completion); if (result) { updateTasksForStory(); updateTasksForUser(); CurrTask = new TaskView(_dataModel.GetTaskByID(CurrTask.TaskID)); } return result; }
/// <summary> /// Updates the current project /// </summary> /// <param name="name">The name of the project</param> /// <param name="startDate">The start date of the project</param> /// <param name="endDate">The end date of the project</param> /// <param name="owner">The User who owns the new project</param> /// <param name="team">The team responsible for the new project</param> /// <returns>True if the changes succeed, false otherwise</returns> public bool ChangeCurrProject(string name, Nullable<DateTime> startDate, Nullable<DateTime> endDate, UserView owner, TeamView team) { if (!_isLoggedIn || CurrProject == null) { throw new InvalidOperationException("User must be logged in"); } else if (name == null || !startDate.HasValue || owner == null || team == null) { throw new ArgumentNullException("Arguments to AddProject must not be null"); } bool result = _dataModel.ChangeProject(CurrProject.ProjectID, name, startDate.Value, endDate, owner.UserID, team.TeamID); if (result) { updateProjectsForUser(); CurrProject = new ProjectView(_dataModel.GetProjectByID(CurrProject.ProjectID)); } return result; }
/// <summary> /// Authenticates the user /// </summary> /// <param name="userId">The ID of the user to authenticate</param> /// <param name="password">The user's password</param> /// <returns>True if authentication succeeds, false otherwise</returns> public bool AuthenticateUser(int userId, string password) { string passHash = hashPassword(password); User curr = _dataModel.AuthenticateUser(userId, passHash); if (curr == null) // Authentication failed { return false; } _isLoggedIn = true; CurrTeam = new TeamView(curr.Team_); // Store the team CurrUser = new UserView(curr); // Store the user IsManager = CurrUser.Role == UserRole.Manager; return true; }
public void GetUserByIDTest() { int userId = -1; UserView expected = new UserView(target._dataModel.GetUserByID(1)); UserView actual; target._isLoggedIn = false; try { actual = target.GetUserByID(userId); Assert.Fail("Exception not thrown"); } catch (InvalidOperationException) { ; } target._isLoggedIn = true; try { actual = target.GetUserByID(userId); Assert.Fail("Exception not thrown"); } catch (ArgumentOutOfRangeException) { ; } userId = 1; actual = target.GetUserByID(userId); Assert.AreEqual(expected, actual); (target._dataModel as MockDataModel).failureOn = true; actual = target.GetUserByID(userId); Assert.IsNull(actual); }