public void RunSeedMethod_WithoutDescription()
 {
     using (var ctx = new CarsContext())
     {
         ctx.Seed<CarBodyStyle>(descriptionField: null);
     }
 }
 public void TestStoreBrand()
 {
     using (TransactionScope ts = new TransactionScope())
     using (CarsContext context = new CarsContext())
     {
         Brand volvo = new Brand { Name = "Volvo" };
         context.Brands.Add(volvo);
         context.SaveChanges();
     }
 }
        public void RunSeedMethod()
        {
            // Not a proper unit test, nor placed in the right unit test lib,
            // but it's a great runner to use to get the code running.

            using (var ctx = new CarsContext())
            {
                ctx.Seed<CarBodyStyle>();
            }
        }
        public void TestBasicSelect()
        {
            using (CarsContext ctx = new CarsContext())
            {
                var car = ctx.Cars.Select(basicSelect)
                    .Single(c => c.RegistrationNumber == "ABC123");

                Assert.IsNotNull(car);
            }
        }
public void TestSavingChanges()
{
    using (var ctx = new CarsContext())
    {
        var objCtx = ((IObjectContextAdapter)ctx).ObjectContext;

        bool eventCalled = false;

        objCtx.SavingChanges += (sender, args) => eventCalled = true;

        ctx.SaveChanges();

        Assert.IsTrue(eventCalled);
    }
}
        public void TestMergedSelect()
        {
            using (CarsContext ctx = new CarsContext())
            {
var car = ctx.Cars.Select(basicSelect.Merge(c => new CarExtendedInfo
{
    Color = c.Color,
    BrandName = c.Brand.Name
})).Single(c => c.RegistrationNumber == "ABC123");

Assert.IsNotNull(car);
Assert.AreEqual("Red", car.Color);
Assert.AreEqual("Volvo", car.BrandName);
            }
        }
        public void TestStoreCar()
        {
            using (TransactionScope ts = new TransactionScope())
            using (CarsContext context = new CarsContext())
            {
                Brand volvo = new Brand { Name = "Volvo" };
                Car myVolvo = new Car
                {
                    Brand = volvo,
                    RegistrationNumber = "ABC123"
                };

                context.Cars.Add(myVolvo);
                context.SaveChanges();
            }
        }
        public void TestChangeTracking()
        {
            using (TransactionScope ts = new TransactionScope())
            using (CarsContext context = new CarsContext())
            {
                context.Configuration.AutoDetectChangesEnabled = false;

                Debug.WriteLine("Reading people...");
                var people = context.People.ToArray();
                Debug.WriteLine(string.Format("Type of people[0] is {0}",
                    people[0].GetType().ToString()));

                Debug.WriteLine("Updating birth year of first person...");
                people[0].BirthYear = 1965;

                Debug.WriteLine("Saving changes...");
                context.SaveChanges();
            }
        }
        public void TestNavigationAndForeignKeySetKey()
        {
            using (TransactionScope ts = new TransactionScope())
            using (CarsContext context = new CarsContext())
            {
                var brands = context.Brands.Include(b => b.Cars).OrderBy(b => b.BrandId);
                var car = brands.First().Cars.First();

                Debug.WriteLine("The car has BrandId {0} pointing to Brand \"{1}\"",
                    car.BrandId, car.Brand.Name);
                Brand newBrand = brands.Skip(1).First();
                Debug.WriteLine(string.Format("Setting BrandId to {0}", newBrand.BrandId));
                car.BrandId = newBrand.BrandId;
                Debug.WriteLine(string.Format("The car has BrandId {0} pointing to Brand \"{1}\"",
                    car.BrandId, car.Brand.Name));

                Debug.WriteLine("Saving Changes...");
                context.SaveChanges();
                Debug.WriteLine(string.Format("The car has BrandId {0} pointing to Brand \"{1}\"",
                    car.BrandId, car.Brand.Name));
            }
        }
        public void TestChangeTrackingSimpleType()
        {
            using (TransactionScope ts = new TransactionScope())
            using (CarsContext context = new CarsContext())
            {
                var phoneBook = context.PhoneBook.ToList();
                var entry = phoneBook.First();

                entry.PhoneNumber = "4567";

                Debug.WriteLine("Saving changes...");
                context.SaveChanges();
            }
        }
        public void TestNavigationAndForeignKeySetNavigationPropertyWithProxy()
        {
            using (TransactionScope ts = new TransactionScope())
            using (CarsContext context = new CarsContext())
            {
                var genders = context.Genders.Include(g => g.People).OrderBy(g => g.GenderId);
                var person = genders.First().People.First();

                Debug.WriteLine("The person has GenderId {0} pointing to Gender \"{1}\"",
                    person.GenderId, person.Gender.Description);
                Gender newGender = genders.Skip(1).First();
                Debug.WriteLine(string.Format("Setting Gender to {0}", newGender.Description));
                person.Gender = newGender;
                Debug.WriteLine("The person has GenderId {0} pointing to Gender \"{1}\"",
                    person.GenderId, person.Gender.Description);

                Debug.WriteLine("Saving Changes...");
                context.SaveChanges();
                Debug.WriteLine("The person has GenderId {0} pointing to Gender \"{1}\"",
                    person.GenderId, person.Gender.Description);
            }
        }