public void AddAgentMessage() { using (var uow = new CapriconContext()) { //retreive an existing agent var agentRepository = new AgentRepository(uow); var existingAgent = agentRepository.GetAll().FirstOrDefault(); Assert.IsNotNull(existingAgent); //retreive an existing message var messageRepository = new MessageRepository(uow); var existingMessage = messageRepository.GetAll().LastOrDefault(); Assert.IsNotNull(existingMessage); //create new agent messsage var newAgentMessage = new AgentMessage() { Agent = existingAgent, Message = existingMessage }; //add the new agent message to the repository var agentMessageRepository = new AgentMessageRepository(uow); agentMessageRepository.Add(newAgentMessage); 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.FirstName, existingAgent.FirstName = "Blaise"); Assert.AreEqual(savedAgentMessages[0].Message.MessageId, existingMessage.MessageId = 1); }; }
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); } ); }; }
public void AddPayment() { using (CapriconContext context = new CapriconContext()) { var messageRepository = new MessageRepository(context); var existingMessage = messageRepository.GetAll().LastOrDefault(); Assert.IsNotNull(existingMessage); var newPayment = new Payment() { PaymentDate = DateTime.Now, Amount = 750, Message = existingMessage }; var paymentRep = new PaymentRepository(context); paymentRep.Add(newPayment); 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 PaymentRepository(context1); var savedPayments = repository.GetAll().ToList(); Assert.AreEqual(savedPayments.Count(), 3, "returns 20 records"); var savedPaymentsList = savedPayments; savedPaymentsList.ForEach ( p => { Debug.WriteLine(p.PaymentId + " - " + p.Amount + " " + p.Message.MessageId); } ); }; }
public void UpdatePayment() { using (var uow = new CapriconContext()) { var paymentRep = new PaymentRepository(uow); var existingPayments = paymentRep.GetAll().ToList(); var existingPayment = existingPayments.Find(p => p.PaymentId == 3); Assert.IsNotNull(existingPayment); var messageRepository = new MessageRepository(uow); var existingMessage = messageRepository.GetAll().FirstOrDefault(); Assert.IsNotNull(existingMessage); existingPayment.PaymentDate = DateTime.Now; existingPayment.Amount = 350; existingPayment.Message = existingMessage; //check for validation rules //existingPayment.PaymentDate = DateTime.Now; paymentRep.Attach(existingPayment); uow.Entry(existingPayment).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 PaymentRepository(uow1); var savedPayments = repository.GetAll().ToList(); Assert.AreEqual(savedPayments[0].Amount, 350); }
public void UpdateMessage() { using (var uow = new CapriconContext()) { var messageRep = new MessageRepository(uow); var existingMessages = messageRep.GetAll().ToList(); var existingMessage = existingMessages.Find(m => m.MessageId == 3); Assert.IsNotNull(existingMessage); existingMessage.Body = ""; existingMessage.Sent = DateTime.Now; existingMessage.MessageStatus = MessageStatus.Received; //check for validation rules //existingMessage.Body = ""; //existingMessage.Sent = DateTime.Now; //existingMessage.MessageStatus = MessageStatus.Not_Specified; messageRep.Attach(existingMessage); uow.Entry(existingMessage).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 MessageRepository(uow1); var savedMessages = repository.GetAll().ToList(); Assert.AreEqual(savedMessages[0].MessageId, 1); }
public void AddMessage() { using (CapriconContext context = new CapriconContext()) { var newMessage = new Message() { Body = "Testing...............", Sent = DateTime.Now, MessageStatus = MessageStatus.Sent }; var messageRep = new MessageRepository(context); messageRep.Add(newMessage); 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 MessageRepository(context1); var savedMessages = repository.GetAll().ToList(); Assert.AreEqual(savedMessages.Count(), 2, "returns 20 records"); var savedMessagesList = savedMessages; savedMessagesList.ForEach ( m => { Debug.WriteLine(m.MessageId + " - " + m.Body); } ); }; }
public void DeleteAgentMessage() { using (var uow = new CapriconContext()) { var agentMessageRepository = new AgentMessageRepository(uow); var existingAgentMessage = agentMessageRepository.Find(am => am.Id == 2).FirstOrDefault(); Assert.IsNotNull(existingAgentMessage); int id; if (existingAgentMessage != null) { id = existingAgentMessage.Id; //Delete selected agent message agentMessageRepository.Delete(existingAgentMessage); 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(agentMessageRepository.Find(am => am.Id == id).FirstOrDefault()); } else //no agent messages were selected { Assert.Fail("No agent message was selected"); } } }
public void DeletePayment() { using (var uow = new CapriconContext()) { var paymentRep = new PaymentRepository(uow); var existingPayment = paymentRep.Find(p => p.PaymentId == 2).FirstOrDefault(); Assert.IsNotNull(existingPayment); int paymentId; if (existingPayment != null) { paymentId = existingPayment.PaymentId; //Delete payment paymentRep.Delete(existingPayment); 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(paymentRep.Find(p => p.PaymentId == paymentId).FirstOrDefault()); } else //no payments were selected { Assert.Fail("No payment was selected"); } } }
public void DeleteUser() { using (var uow = new CapriconContext()) { var userRep = new UserRepository(uow); var existingUser = userRep.Find(u => u.UserId == 2).FirstOrDefault(); Assert.IsNotNull(existingUser); int userId; if (existingUser != null) { userId = existingUser.UserId; //Delete employee userRep.Delete(existingUser); 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(userRep.Find(u => u.UserId == userId).FirstOrDefault()); } else //no userss were selected { Assert.Fail("No user was selected"); } } }
public void Save() { context.SaveChanges(); }
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"); }
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); }; }
public void UpdateUser() { using (var uow = new CapriconContext()) { var userRep = new UserRepository(uow); var existingUsers = userRep.GetAll().ToList(); var existingUser = existingUsers.Find(a => a.UserId == 3); Assert.IsNotNull(existingUser); existingUser.FirstName = "Aaron"; existingUser.LastName = "Mukasa"; existingUser.OtherName = "Gad"; existingUser.Gender = Gender.Male; existingUser.DateOfBirth = DateTime.Now.AddYears(-60); existingUser.MobilePhone = "0777 700 700"; existingUser.Email = "*****@*****.**"; existingUser.Town = "Bugembe"; existingUser.District = "Jinja"; //check for validation rules //existingUser.FirstName = ""; //existingUser.LastName = ""; //existingUser.Gender = Gender.Not_Specified; //existingUser.Email = ""; //existingUser.Town = ""; //existingUser.District = ""; userRep.Attach(existingUser); uow.Entry(existingUser).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 UserRepository(uow1); var savedUsers = repository.GetAll().ToList(); Assert.AreEqual(savedUsers[0].LastName, "Mawa"); }