public Guid Insert(Task task) { var guid = Guid.NewGuid(); task.IdTask = guid; _db.Tasks.Add(task); _db.SaveChanges(); return guid; }
public TaskRepositoryTest() { _taskRepository = new TaskRepository(_db); _statusRepository = new StatusRepository(_db); _simpleTask = new Task() { Name = "SimpleTask", Priority = 12 }; _newStatus = new Status() { IdStatus = new Guid("00000000-0000-0000-0000-000000000001"), Name = "Started" }; _statusRepository.Insert(_newStatus); }
public void Update(Task task) { var currentTask = _db.Tasks.Find(task.IdTask); var currentState = _db.Status.Find(task.Status.IdStatus); currentTask.Status = currentState; currentTask.Minutes = task.Minutes; currentTask.Name = task.Name; currentTask.Priority = task.Priority; _db.Entry<Status>(currentState).State = System.Data.EntityState.Unchanged; _db.Entry<Task>(currentTask).State = System.Data.EntityState.Modified; _db.SaveChanges(); }
public void Should_update_simple_user_with_tasks() { var taskOne = new Task() { Name = "TaskOne", Minutes = 12, Priority = 5 }; _taskRepository.Insert(taskOne); var taskTwo = new Task() { Name = "TaskTwo", Minutes = 1, Priority = 3 }; _taskRepository.Insert(taskTwo); var taskThree = new Task() { Name = "TaskThree", Minutes = 120, Priority = 6 }; _taskRepository.Insert(taskThree); _simpleUser.Tasks.Add(taskOne); _simpleUser.Tasks.Add(taskTwo); _simpleUser.Tasks.Add(taskThree); _userRepository.Update(_simpleUser); var userModified = _userRepository.GetById(_simpleUser.IdUser); Assert.AreEqual<User>(userModified, _simpleUser); Assert.AreEqual<int>(userModified.Tasks.Count, _simpleUser.Tasks.Count); }