public void UpdateAgent() { using (var uow = new CapriconContext()) { var agentRep = new AgentRepository(uow); var existingAgents = agentRep.GetAll().ToList(); var existingAgent = existingAgents.LastOrDefault(); Assert.IsNotNull(existingAgent); existingAgent.FirstName = "Hilda"; existingAgent.LastName = "Kunda"; existingAgent.OtherName = ""; existingAgent.Gender = Gender.Male; existingAgent.DateOfBirth = DateTime.Now.AddYears(-60); existingAgent.MobilePhone = "0777 700 700"; existingAgent.Email = "*****@*****.**"; existingAgent.Town = "Bugembe"; existingAgent.District = "Jinja"; //check for validation rules //existingAgent.FirstName = ""; //existingAgent.LastName = ""; //existingAgent.Gender = Gender.Not_Specified; //existingAgent.Email = ""; //existingAgent.Town = ""; //existingAgent.District = ""; agentRep.Attach(existingAgent); uow.Entry(existingAgent).State = EntityState.Modified; try { uow.SaveChanges(); } catch (DbEntityValidationException ex) { //Retrieve validation errors ex.EntityValidationErrors.ToList().ForEach ( v => { v.ValidationErrors.ToList().ForEach ( e => { System.Diagnostics.Debug.WriteLine(e.ErrorMessage); } ); } ); Assert.Fail("Test failed"); } }; //retrieve saved object var uow1 = new CapriconContext(); var repository = new AgentRepository(uow1); var savedAgents = repository.GetAll().ToList(); Assert.AreEqual(savedAgents[0].LastName, "Byanjeru"); }