public async void Patch_ShouldChangeTaskEstimateTo_5() { ClearTasksFromDatabase(); var taskId = 1; var expectedEstimate = 5; var projectTask = new ProjectTask() { id = taskId, title = "test task 1", author = new User(), RoomId = 1, estimate = 1 }; context.ProjectTask.Add(projectTask); context.SaveChanges(); context.Entry(projectTask).State = EntityState.Detached; var controller = new ProjectTasksController(context); var result = await controller.PatchProjectTaskEstimate(taskId, expectedEstimate); var projectTaskEstimate = context.ProjectTask.Find(taskId).estimate; Assert.Equal(expectedEstimate, projectTaskEstimate); }
public void Get_ShouldReturnTwoTasks() { ClearTasksFromDatabase(); var controller = new ProjectTasksController(context); context.ProjectTask.Add(new ProjectTask { id = 1, title = "Zadanie 1", author = new User(), RoomId = 1, estimate = 5 }); context.ProjectTask.Add(new ProjectTask { id = 2, title = "Zadanie 2", author = new User(), RoomId = 1, estimate = 5 }); context.SaveChanges(); var projectTasks = controller.GetProjectTasks(); Assert.Equal(2, projectTasks.Count()); }
public ProjectTasksControllerTest() { testContext = new ZPIContext(options); testContext.Database.EnsureDeleted(); taskController = new ProjectTasksController(testContext); taskController.ControllerContext.HttpContext = new DefaultHttpContext(); InitUsers(); }
public async void Put_ShouldAddNewTask() { ClearTasksFromDatabase(); var controller = new ProjectTasksController(context); var task = new ProjectTask { title = "Zadanie testowe", RoomId = 1, status = TaskStatus.UNESTIMATED.name }; var result = await controller.CreateProjectTask(task); var typeResult = Assert.IsType <CreatedAtActionResult>(result); Assert.NotNull(typeResult.StatusCode); Assert.Equal(201, typeResult.StatusCode.Value); Assert.Contains(context.ProjectTask, p => p.title.Equals("Zadanie testowe") && p.id.Equals(task.id)); }
public void EstimatingATask(ProjectTask task) { var controller = new ProjectTasksController(_context); "Given a new task" .x(() => task = new ProjectTask() { id = 2, status = TaskStatus.UNESTIMATED.name, title = "New task in BDD", RoomId = 1999, estimate = 0 }); "And adding the task in database" .x(async() => { await controller.CreateProjectTask(task); _context.Entry(task).State = EntityState.Detached; }); "When I select task to estimate" .x(async() => { await controller.UpdateTaskStatus(task.id, TaskStatus.VOTING.name); }); "And assign estimate" .x(async() => { await controller.PatchProjectTaskEstimate(task.id, 5); }); "Then task status is 'Estimated'" .x(() => { task = _context.ProjectTask.First(pt => pt.id == task.id); Assert.Equal(5, task.estimate); }); "And esitmate is equal to assigned one" .x(() => { Assert.Equal(TaskStatus.ESTIMATED.name, task.status); }); }
public async void Post_ShouldChangeTaskStatusToVoting() { ClearTasksFromDatabase(); var task = new ProjectTask() { title = "Zadanie testowe", RoomId = 1, status = TaskStatus.UNESTIMATED.name }; context.ProjectTask.Add(task); context.SaveChanges(); context.Entry(task).State = EntityState.Detached; var controller = new ProjectTasksController(context); var result = await controller.UpdateTaskStatus(task.id, TaskStatus.VOTING.name); var updatedTask = context.ProjectTask.First(t => t.id == task.id); var typeResult = Assert.IsType <NoContentResult>(result); Assert.Equal(204, typeResult.StatusCode); Assert.Equal(TaskStatus.VOTING.name, updatedTask.status); }
public void GettingSummaryOfEstimatingRoom(Room room, List <ProjectTask> tasks, List <RoomParticipant> participants, List <User> users, ProjectTasksController projectTasksController, GameSummary summary, RoomsController roomsController) { "Given a list of users" .x(() => { users = new List <User>() { new User() { id = 1, username = "******", mailAddress = "*****@*****.**" }, new User() { id = 2, username = "******", mailAddress = "*****@*****.**" }, new User() { id = 3, username = "******", mailAddress = "*****@*****.**" }, new User() { id = 4, username = "******", mailAddress = "*****@*****.**" }, }; _context.User.AddRange(users); _context.SaveChanges(); }); "And a room" .x(() => { room = new Room() { hostMailAddress = users[3].mailAddress, id = 2999, name = "BDD Testing Room" }; _context.Room.Add(room); _context.SaveChanges(); }); "And list of tasks" .x(() => { tasks = new List <ProjectTask>() { new ProjectTask() { id = 1, title = "Add a new task", RoomId = 2999, estimate = 0, status = TaskStatus.UNESTIMATED.name, author = users[3] }, new ProjectTask() { id = 2, title = "Assign estimates", RoomId = 2999, estimate = 0, status = TaskStatus.UNESTIMATED.name, author = users[3] }, new ProjectTask() { id = 3, title = "Sign in to an application", RoomId = 2999, estimate = 0, status = TaskStatus.UNESTIMATED.name, author = users[3] }, new ProjectTask() { id = 4, title = "Sign up to an application", RoomId = 2999, estimate = 0, status = TaskStatus.UNESTIMATED.name, author = users[3] } }; _context.ProjectTask.AddRange(tasks); _context.SaveChanges(); tasks.ForEach(t => _context.Entry(t).State = EntityState.Detached); }); "And having users assigned to the room" .x(() => { participants = new List <RoomParticipant>(); users.ForEach(u => { if (u.id != 4) { participants.Add(new RoomParticipant() { mailAddress = u.mailAddress, roomId = 2999 }); } }); _context.RoomParticipant.AddRange(participants); _context.SaveChanges(); }); "When I estimate all tasks" .x(async() => { projectTasksController = new ProjectTasksController(_context); await projectTasksController.PatchProjectTaskEstimate(1, 1); await projectTasksController.PatchProjectTaskEstimate(2, 10); await projectTasksController.PatchProjectTaskEstimate(3, 5); await projectTasksController.PatchProjectTaskEstimate(4, 20); }); "And request room summary" .x(async() => { roomsController = new RoomsController(_context); summary = await roomsController.GetGameSummary(2999); }); "Then all tasks will be present" .x(() => { tasks = _context.ProjectTask.Where(pt => pt.RoomId == 2999).ToList(); tasks.ForEach(t => { Assert.Contains(summary.tasks, (pt) => t.id == pt.id); }); }); "And all tasks will be having correct estimates" .x(() => { tasks.ForEach(t => { Assert.Contains(summary.tasks, (pt) => t.id == pt.id && t.estimate == pt.estimate); }); }); "And all participants will be present" .x(() => { users.ForEach(u => { if (u.mailAddress != summary.host) { Assert.Contains(summary.participants, rp => rp.id == u.id); } }); }); }