Ejemplo n.º 1
0
        private EFCustomer GetComplexCustomerInfo()
        {
            var customer = new EFCustomer
            {
                Address  = new EFAddress("China", "SH", "SH", "A street", "12345"),
                UserName = "******",
                Phone    = "111111",
                Password = "******",
                EFNote   = new List <EFNote>
                {
                    new EFNote {
                        NoteText = "AA"
                    },
                    new EFNote
                    {
                        NoteText  = "BB",
                        ChildNote = new List <ChildNote>
                        {
                            new ChildNote {
                                Title = "XXX"
                            },
                            new ChildNote {
                                Title = "YYY"
                            }
                        }
                    }
                }
            };

            return(customer);
        }
Ejemplo n.º 2
0
        private void InsertNewCustomer(EFCustomer customer)
        {
            using (var custRepo = new CustomerRepository())
            {
                var actual = custRepo.GetAll().ToList().Count;
                //actual.Should().Be(0);

                custRepo.Insert(customer);
                custRepo.RepoContext.Commit();
            }
        }
Ejemplo n.º 3
0
        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");
            }
        }
Ejemplo n.º 4
0
        public void ef_update_by_manual_compare_test()
        {
            var customer = GetCustomerInfo();

            InsertNewCustomer(customer);
            var cInfo = new EFCustomer();

            using (var repo = new CustomerRepository())
            {
                cInfo = repo.GetCustomFullInfo(1);
            }

            cInfo.Email        = "*****@*****.**";
            cInfo.Address.City = "SZ";
            cInfo.Address.Zip  = "000000000";
            cInfo.ObjectState  = ObjectStateType.Modified;
            cInfo.EFNote.First().NoteText    = "DDDD";
            cInfo.EFNote.First().ObjectState = ObjectStateType.Modified;
            cInfo.EFNote.Last().ObjectState  = ObjectStateType.Deleted;
            cInfo.EFNote.Add(new EFNote {
                NoteText = "CCCC", ObjectState = ObjectStateType.Added
            });

            using (var repo = new CustomerRepository())
            {
                repo.Update(cInfo);
                repo.RepoContext.Commit();
            }

            using (var repo = new CustomerRepository())
            {
                cInfo = repo.GetCustomFullInfo(1);
                var all = repo.GetAll();
                all.Count().Should().Be(1);
            }
            cInfo.Email.Should().Be("*****@*****.**");
            var address = cInfo.Address;

            address.City.Should().Be("SZ");
            address.Zip.Should().Be("000000000");
            cInfo.EFNote.Count.Should().Be(2);
            cInfo.EFNote.Last().NoteText.Should().Be("CCCC");
            cInfo.EFNote.First().NoteText.Should().Be("DDDD");
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        public void ef_update_by_partial_test()
        {
            var customer = GetCustomerInfo();

            InsertNewCustomer(customer);
            var cInfo = new EFCustomer();

            using (var repo = new CustomerRepository())
            {
                cInfo = repo.GetCustomFullInfo(1);
            }

            cInfo.SetUpdate(() => cInfo.Address.City, "SZ");
            cInfo.SetUpdate(() => cInfo.Address.Zip, "000000000");
            cInfo.SetUpdate(() => cInfo.Email, "*****@*****.**");

            var firstNote = cInfo.EFNote.First();

            firstNote.SetUpdate(() => firstNote.NoteText, "DDDD");

            using (var repo = new CustomerRepository())
            {
                repo.Update(cInfo);
                repo.RepoContext.Commit();
            }

            using (var repo = new CustomerRepository())
            {
                cInfo = repo.GetCustomFullInfo(1);
            }
            cInfo.Email.Should().Be("*****@*****.**");
            var address = cInfo.Address;

            address.City.Should().Be("SZ");
            address.Zip.Should().Be("000000000");
            cInfo.EFNote.Count.Should().Be(2);
            cInfo.EFNote.Last().NoteText.Should().Be("BB");
            cInfo.EFNote.First().NoteText.Should().Be("DDDD");
        }