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 Attach(User user) { context.Entry(user).State = System.Data.EntityState.Modified; context.Users.Attach(user); }
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 virtual void Attach(T entity) { context.Entry(entity).State = System.Data.EntityState.Modified; dbSet.Attach(entity); }
public void Attach(Payment payment) { context.Entry(payment).State = System.Data.EntityState.Modified; context.Payments.Attach(payment); }
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 Attach(Message message) { context.Entry(message).State = System.Data.EntityState.Modified; context.Messages.Attach(message); }
public void Attach(AgentMessage agentMessage) { context.Entry(agentMessage).State = System.Data.EntityState.Modified; context.AgentMessages.Attach(agentMessage); }
public void Attach(UserMessage userMessage) { context.Entry(userMessage).State = System.Data.EntityState.Modified; context.UserMessages.Attach(userMessage); }
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"); }