Beispiel #1
0
 private void InsertNewCustomer(EFCustomer customer)
 {
     using (var custRepo = new CustomerRepository())
     {
         custRepo.Insert(customer);
         custRepo.RepoContext.Commit();
     }
 }
Beispiel #2
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;

            var newNote = new EFNote
            {
                CustomerId  = 1,
                NoteText    = "CCCC",
                ObjectState = ObjectStateType.Added
            };

            cInfo.EFNote.Add(newNote);

            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("CCCC");
            cInfo.EFNote.First().NoteText.Should().Be("DDDD");
        }
Beispiel #3
0
        private EFCustomer GetCustomerInfo()
        {
            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"
                    }
                }
            };

            return(customer);
        }
Beispiel #4
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");
        }