Example #1
0
        public void ShouldUpdateCategoryName()
        {
            var cat = Db.Categories.First();

            cat.CategoryName = "Bar";
            Db.SaveChanges();
            var updatedCat = new IntroToEfContext().Categories.First();

            Assert.Equal("Bar", updatedCat.CategoryName);
        }
Example #2
0
        public void ShouldProductModelName()
        {
            var cat       = Db.Categories.Include(c => c.Products).First();
            var modelName = "Foo";

            cat.Products.ToList()[0].ModelName = modelName;
            Db.SaveChanges();
            var cat2 = new IntroToEfContext().Categories.Include(c => c.Products).First();

            Assert.Equal(modelName, cat.Products.ToList()[0].ModelName);
        }
Example #3
0
 static void Main(string[] args)
 {
     using (var db = new IntroToEfContext())
     {
         foreach (var item in db.Pet_Breed)
         {
             Console.WriteLine(item.BreedName);
         }
     }
     Console.ReadKey();
 }
Example #4
0
        public void ShouldDeleteCategoryById()
        {
            var catCount    = Db.Categories.Count();
            var prodCount   = Db.Products.Count();
            var cat         = Db.Categories.First();
            var newDb       = new IntroToEfContext();
            var catToDelete = new Category {
                Id = cat.Id, TimeStamp = cat.TimeStamp
            };

            newDb.Entry(catToDelete).State = EntityState.Deleted;
            newDb.SaveChanges();
            Assert.Equal(catCount - 1, Db.Categories.Count());
            Assert.Equal(prodCount - 2, Db.Products.Count());
        }
Example #5
0
 public BaseTest()
 {
     Db = new IntroToEfContext();
 }
Example #6
0
 public static void AddProduct(IntroToEfContext db, int categoryId, decimal price, string description, string modelName, string modelNumber, decimal unitCost, int quantity)
 {
     db.Database.ExecuteSqlCommand($"INSERT INTO [Store].[Products] ([CategoryId],[CurrentPrice],[Description],[IsFeatured],[ModelName],[ModelNumber],[UnitCost],[UnitsInStock]) VALUES ({categoryId}, {price}, '{description}',0,'{modelName}', '{modelNumber}', {unitCost}, {quantity})");
 }
Example #7
0
 public static void AddCategory(IntroToEfContext db, string categoryName)
 {
     db.Database.ExecuteSqlCommand($"INSERT INTO [Store].[Categories] ([CategoryName]) VALUES ('{categoryName}')");
 }
Example #8
0
 public ConcurrencyTests()
 {
     _db = new IntroToEfContext();
 }
Example #9
0
 public UpdateDataTests()
 {
     _db = new IntroToEfContext();
 }