public void ef_update_by_auto_complex_compare_test() { var customer = GetComplexCustomerInfo(); InsertNewCustomer(customer); var cInfo = new EFCustomer(); using (var repo = new CustomerRepository()) { cInfo = repo.GetCustomFullInfo(1); } var updateInfo = cInfo.DeepCopy(); updateInfo.Email = "*****@*****.**"; updateInfo.Phone = null; updateInfo.Address.City = "SZ"; updateInfo.EFNote.First().NoteText = "DDDD"; var newNotes = updateInfo.EFNote; var note = newNotes.Last(); newNotes.Remove(note); updateInfo.EFNote = newNotes; var childList = updateInfo.EFNote.First().ChildNote; var cNote = childList.First(); childList.Remove(cNote); childList.First().Title = "MMM"; childList.Add(new ChildNote { Title = "ZZZ" }); updateInfo.EFNote.Add(new EFNote { NoteText = "CCCC" }); var result = new CompareLogic().Compare(updateInfo, cInfo); using (var repo = new CustomerRepository()) { repo.Update(updateInfo); repo.RepoContext.Commit(); } using (var repo = new CustomerRepository()) { var newInfo = repo.GetCustomFullInfo(1); newInfo.Email.Should().Be("*****@*****.**"); newInfo.EFNote.Count().Should().Be(2); var newChilds = newInfo.EFNote.First().ChildNote; newChilds.Count.Should().Be(2); newChilds.First().Title.Should().Be("MMM"); newChilds.Last().Title.Should().Be("ZZZ"); } }
public void ef_update_by_auto_compare_by_ilist_test() { var customer = GetCustomerInfo(); InsertNewCustomer(customer); var cInfo = new EFCustomer(); using (var repo = new CustomerRepository()) { cInfo = repo.GetCustomFullInfo(1); cInfo.EFNote = cInfo.EFNote.ToList(); } var updateInfo = cInfo.DeepCopy(); updateInfo.Email = "*****@*****.**"; updateInfo.Phone = null; updateInfo.Address.City = "SZ"; updateInfo.EFNote.First().NoteText = "DDDD"; var newNotes = updateInfo.EFNote.ToList(); newNotes.RemoveAll(p => p.Id == 2); updateInfo.EFNote = newNotes; updateInfo.EFNote.Add(new EFNote { NoteText = "CCCC" }); var result = new CompareLogic().Compare(updateInfo, cInfo); using (var repo = new CustomerRepository()) { repo.Update(updateInfo); repo.RepoContext.Commit(); } using (var repo = new CustomerRepository()) { var newInfo = repo.GetCustomFullInfo(1); newInfo.Email.Should().Be("*****@*****.**"); newInfo.EFNote.Count().Should().Be(2); } }