public void AddAgent() { using (CapriconContext context = new CapriconContext()) { var newAgent = new Agent() { FirstName = "Blaise", LastName = "Nyamwamba", OtherName = "", Gender = Gender.Female, MobilePhone = "0756 123 456", Email = "*****@*****.**", Town = "Nairobi", District = "Nairobi", DateOfBirth = DateTime.Now.AddYears(-40), }; var agentRep = new AgentRepository(context); agentRep.Add(newAgent); try { context.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 context1 = new CapriconContext(); var repository = new AgentRepository(context1); var savedAgents = repository.GetAll().ToList(); Assert.AreEqual(savedAgents.Count(), 1, "returns 20 records"); var savedAgentsList = savedAgents; savedAgentsList.ForEach ( s => { Debug.WriteLine(s.AgentId + " - " + s.FirstName + " " + s.LastName); } ); }; }
static void CreateBase() { AgentRepository agentRepository = new AgentRepository(); for (int i = 1; i <= 10; i++) { agentRepository.Add(new Agent(i, "Agent" + i.ToString())); } BuilderRepository builderRepository = new BuilderRepository(); for (int i = 1; i <= 3; i++) { builderRepository.Add(new Builder(i, "Builder" + i.ToString())); } }
public void AgentRepositoryTest() { AgentRepository repository = new AgentRepository(); Agent expectedAgent = new Agent(repository.GetAll().Count() + 1, "agensomeagent"); repository.Add(expectedAgent); Agent realAgent = repository.GetItem(expectedAgent.id); Assert.AreEqual(expectedAgent, realAgent); repository.Delete(expectedAgent); realAgent = repository.GetItem(expectedAgent.id); Assert.AreEqual(null, realAgent); }
public void AgentRepositoryTest() { AgentRepository repository = new AgentRepository(); Agent expectedAgent = new Agent { name = "agensomeagent" }; repository.Add(expectedAgent); Agent realAgent = repository.GetAll().Last(); Assert.AreEqual(expectedAgent.name, realAgent.name); repository.Delete(realAgent); realAgent = repository.GetAll().Last(); Assert.AreNotEqual(expectedAgent.name, realAgent.name); }