public void DeleteAgent() { using (var uow = new CapriconContext()) { var agentRep = new AgentRepository(uow); var existingAgent = agentRep.Find(a => a.AgentId == 2).FirstOrDefault(); Assert.IsNotNull(existingAgent); int agentId; if (existingAgent != null) { agentId = existingAgent.AgentId; agentRep.Delete(existingAgent); 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"); } Assert.IsNull(agentRep.Find(a => a.AgentId == agentId).FirstOrDefault()); } else //no agents were selected { Assert.Fail("No agent was selected"); } } }
public IEnumerable <Agent> Find(Expression <Func <Agent, bool> > predicate) { return(agentRepo.Find(predicate)); }
public void DeleteAgent() { using (var uow = new CapriconContext()) { var agentRep = new AgentRepository(uow); var existingAgent = agentRep.Find(a => a.AgentId == 2).FirstOrDefault(); Assert.IsNotNull(existingAgent); int agentId; if (existingAgent != null) { agentId = existingAgent.AgentId; agentRep.Delete(existingAgent); 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"); } Assert.IsNull(agentRep.Find(a => a.AgentId == agentId).FirstOrDefault()); } else //no agents were selected Assert.Fail("No agent was selected"); } }
public void UpdateAgentMessage() { using (var uow = new CapriconContext()) { var agentMessageRepository = new AgentMessageRepository(uow); var existingAgentMessage = agentMessageRepository.Find(am => am.Id == 1).FirstOrDefault(); Assert.IsNotNull(existingAgentMessage); //retreive an existing agent var agentRepository = new AgentRepository(uow); var existingAgent = agentRepository.Find(a => a.AgentId == 1).FirstOrDefault(); Assert.IsNotNull(existingAgent); //retreive an existing message var messageRepository = new MessageRepository(uow); var existingMessage = messageRepository.Find(m => m.MessageId == 1).FirstOrDefault(); Assert.IsNotNull(existingMessage); //edit an existing agent message existingAgentMessage.Agent = existingAgent; existingAgentMessage.Message = existingMessage; agentMessageRepository.Attach(existingAgentMessage); uow.Entry(existingAgentMessage).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 AgentMessageRepository(uow1); var savedAgentMessages = repository.GetAll().ToList(); Assert.AreEqual(savedAgentMessages[0].Agent, existingAgent); Assert.AreEqual(savedAgentMessages[0].Message, existingMessage); }; }