Esempio n. 1
0
        public void TestDbCtxGetOrAttach()
        {
            //int id = LinqTests.customerIdWithManyAddresses;
            //var addresses = LinqTests.AwDal.List(db => db.QueryCustomerAddressesByCustomerID(id));
            //Assert.IsTrue(2 == addresses.Count);

            //LinqTests.AwDal.Invoke(db => db.ToStringEx(""));

            Customer cust = LinqTests.AwDal.Invoke(db => db.GetOrAttach(OrhpanCust, c => c.CustomerID));
            Assert.IsNull(cust.EmailAddress);

            Customer cust2;
            using(var dbc = new AdventureWorksLT2008R2Entities())
            {
                dbc.Configuration.LazyLoadingEnabled = false;

                cust = dbc.GetProxy(LinqTests.TestAspects).Single(db => db.QueryCustomerByID(LinqTests.CustomerIdWithManyAddresses));
                cust2 = dbc.GetProxy(LinqTests.TestAspects).Invoke(db => db.GetOrAttach(OrhpanCust));
            }
            Assert.IsNotNull(cust2.EmailAddress);
            Assert.IsTrue(cust.Equals(cust2));
        }
Esempio n. 2
0
        public void LinqTestOne()
        {
            IList<Address> addresses;

            // Regular EF call without AOP:
            using(var db = new AdventureWorksLT2008R2Entities())
            {
                db.Configuration.LazyLoadingEnabled = false;
                addresses = db.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses).ToList();
            }
            Assert.AreEqual(2, addresses.Count);

            // Now same with LINQ-friendly AOP shortcuts:

            // Example 1: where AOP creates instance of AdventureWorksLT2008R2Entities, runs the DAL method,
            // and disposes AdventureWorksLT2008R2Entities instance - all in one shot.
            addresses = AwDal.List(db => db.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses));
            Assert.AreEqual(2, addresses.Count);

            // Example 2: with simple AOP proxied call for existing instance of DbContext.
            using(var db = new AdventureWorksLT2008R2Entities())
            {
                db.Configuration.LazyLoadingEnabled = false;
                addresses = db.GetDbProxy(TestAspects).List(dbx => dbx.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses));
            }
            Assert.AreEqual(2, addresses.Count);

            var address = AwDal.Single(db => db.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses));
            Assert.IsNotNull(address);

            long adrressCount = AwDal.Count(db => db.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses));
            Assert.AreEqual(2, adrressCount);

            adrressCount = AwDal.Count(db => db.QueryCustomerAddressesByCustomerID(CustomerIdWithManyAddresses), new QueryModifiers().AddSortCriteria("AddressID").AddPaging(0, 1));
            Assert.AreEqual(1, adrressCount);
        }
Esempio n. 3
0
        public void CallPerfDbContextAugmented()
        {
            long runsPerSec;

            using(var db = new AdventureWorksLT2008R2Entities())
            {
                db.Configuration.LazyLoadingEnabled = false;

                runsPerSec = RunCounter.SpinPerSec(MillisecToRun, () =>
                    db.GetProxy().List(inst => inst.QueryCustomerAddressesByCustomerID(customerIdWithManyAddresses))
                    );
            }
            this.TestContext.WriteLine("db.QueryCustomerAddressesByCustomerID(customerIdWithManyAddresses) augmented sequential base line test result: {0} calls/second.", runsPerSec);
        }
Esempio n. 4
0
        public void CallPerfDbContextDirectParallel()
        {
            long runsPerSec;

            runsPerSec = RunCounter.SpinPerSec(MillisecToRun, () =>
            {
                using(var db = new AdventureWorksLT2008R2Entities())
                {
                    db.Configuration.LazyLoadingEnabled = false;

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                    db.QueryCustomerAddressesByCustomerID(customerIdWithManyAddresses).ToList();
                }
            });

            this.TestContext.WriteLine("db.QueryCustomerAddressesByCustomerID(customerIdWithManyAddresses) direct parallel alloc/call/disp base line test result: {0} calls/second.", runsPerSec);
        }
Esempio n. 5
0
        public void TestExecuteCommand()
        {
            Customer mrAndrewCencini;
            const string originalEmail = "*****@*****.**";
            const string anotherEmail = "*****@*****.**";
            string replacementEmail;

            using(var dbc = new AdventureWorksLT2008R2Entities())
            {
                dbc.Configuration.LazyLoadingEnabled = false;

                mrAndrewCencini = dbc.GetDbProxy(TestAspects).Single(db => db.QueryCustomerByID(163));

                replacementEmail = mrAndrewCencini.EmailAddress == originalEmail ? anotherEmail : originalEmail;
                mrAndrewCencini.EmailAddress = replacementEmail;

                int recordsTouched = dbc.GetDbProxy(TestAspects).ExecuteCommand(db => db.ToStringEx(""));
                Assert.AreEqual(1, recordsTouched);
                mrAndrewCencini = dbc.GetDbProxy(TestAspects).Single(db => db.QueryCustomerByID(163));
            }

            Assert.AreEqual(mrAndrewCencini.EmailAddress, replacementEmail);

            //Customer mrAndrewCencini = new Customer { CustomerID = 163 };
            //int retVal = AwDal.ExecuteCommand(db => db.DeleteEntity(mrAndrewCencini));
            //Assert.AreEqual(1, retVal);
        }