Ejemplo n.º 1
0
            public void RemovesBrandCorrect()
            {
                using (var dataWarehouseContext = new EFDataWarehouseContext())
                {
                    using (var transaction = dataWarehouseContext.Database.BeginTransaction())
                    {
                        var brand = new Brand {
                            Name = "KIA"
                        };

                        dataWarehouseContext.Set <Brand>().Add(brand);
                        dataWarehouseContext.SaveChanges();

                        Assert.IsNotNull(dataWarehouseContext.Entry(brand));

                        dataWarehouseContext.Set <Brand>().Remove(brand);
                        dataWarehouseContext.SaveChanges();

                        Assert.IsNull(dataWarehouseContext.Set <Brand>()
                                      .FirstOrDefault(b => b.Id == brand.Id));

                        transaction.Rollback();
                    }
                }
            }
Ejemplo n.º 2
0
            public void UpdatesModelCorrect()
            {
                using (var dataWarehouseContext = new EFDataWarehouseContext())
                {
                    using (var transaction = dataWarehouseContext.Database.BeginTransaction())
                    {
                        var brand = new Brand {
                            Name = "KIA"
                        };

                        dataWarehouseContext.Set <Brand>().Add(brand);
                        dataWarehouseContext.SaveChanges();

                        var model = new Model {
                            Name = "Rio", Brand = brand
                        };

                        dataWarehouseContext.Set <Model>().Add(model);
                        dataWarehouseContext.SaveChanges();

                        Assert.IsNotNull(dataWarehouseContext.Entry(model));

                        var expectedResult = model.Name = "Sportage";

                        dataWarehouseContext.Entry(model).State = EntityState.Modified;
                        dataWarehouseContext.SaveChanges();

                        Assert.AreEqual(expectedResult, dataWarehouseContext.Entry(model).Entity.Name);

                        transaction.Rollback();
                    }
                }
            }
Ejemplo n.º 3
0
            public void UpdatesBrandCorrect()
            {
                using (var dataWarehouseContext = new EFDataWarehouseContext())
                {
                    using (var transaction = dataWarehouseContext.Database.BeginTransaction())
                    {
                        var brand = new Brand {
                            Name = "KIA"
                        };

                        dataWarehouseContext.Set <Brand>().Add(brand);
                        dataWarehouseContext.SaveChanges();

                        Assert.IsNotNull(dataWarehouseContext.Entry(brand));

                        var expectedResult = brand.Name = "Toyota";

                        dataWarehouseContext.Entry(brand).State = EntityState.Modified;
                        dataWarehouseContext.SaveChanges();

                        Assert.AreEqual(expectedResult, dataWarehouseContext.Entry(brand).Entity.Name);

                        transaction.Rollback();
                    }
                }
            }
Ejemplo n.º 4
0
            public void CreatesNewModelCorrect()
            {
                using (var dataWarehouseContext = new EFDataWarehouseContext())
                {
                    using (var transaction = dataWarehouseContext.Database.BeginTransaction())
                    {
                        var brand = new Brand {
                            Name = "KIA"
                        };

                        dataWarehouseContext.Set <Brand>().Add(brand);
                        dataWarehouseContext.SaveChanges();

                        var model = new Model {
                            Name = "Rio", Brand = brand
                        };

                        dataWarehouseContext.Set <Model>().Add(model);
                        dataWarehouseContext.SaveChanges();

                        Assert.IsNotNull(dataWarehouseContext.Entry(model));

                        transaction.Rollback();
                    }
                }
            }