Exemplo n.º 1
0
        public void CanWriteAndReadDogFoodIngredients()
        {
            int foodId;
            var ingredientsList = new System.Collections.Generic.List <string> {
                "Chicken", "Bacon", "Peas", "Water", "Preservative"
            };

            using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
            {
                var food = new DogFood()
                {
                    BagSize = 12, Name = "Magi's pet mince"
                };
                food.Ingredients = ingredientsList;
                dbc.Foods.Add(food);
                dbc.SaveChanges();

                foodId = food.Id;
            }
            using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
            {
                var dogfood = dbc.Foods.Find(foodId);
                Assert.NotNull(dogfood);
                Assert.NotEmpty(dogfood.Ingredients);
                Assert.Equal(ingredientsList.Count, dogfood.Ingredients.Count);
            }
        }
Exemplo n.º 2
0
        public void CanInsertAPawtionEntityWithShopDetails()
        {
            int pawtionId;
            var myShop = new Shop("PetMax Kyalami Corner", new Point(new Coordinate(28.074818, -25.985173)));

            using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
            {
                var food = new DogFood()
                {
                    BagSize = 12, Name = "Hills Active Adult"
                };
                var pawtion = new Pawtion(food, 851, 32);
                pawtion.PetShop = new Shop(myShop.Name, myShop.Location);
                dbc.Pawtions.Add(pawtion);

                dbc.SaveChanges();
                pawtionId = pawtion.Id;
            }

            using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
            {
                var pawtion = dbc.Pawtions.Find(pawtionId);
                Assert.Equal(myShop.Name, pawtion.PetShop.Name);
                Assert.Equal(myShop.Location, pawtion.PetShop.Location);
            }
        }
Exemplo n.º 3
0
 public void CanCreateAPawtionContextUsingSqlite()
 {
     using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
     {
         Console.Write(dbc.ContextId);
     }
 }
Exemplo n.º 4
0
        public void CanEditDogFoodIngredients()
        {
            int foodId;
            var ingredientsList = new System.Collections.Generic.List <string> {
                "Chicken", "Bacon", "Peas", "Water", "Preservative"
            };
            var ingredientsList2 = new System.Collections.Generic.List <string> {
                "Bacon", "Chicken", "Desicated coconut", "Peas", "Preservative", "Water", "ZeroMSG"
            };

            using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
            {
                var food = new DogFood()
                {
                    BagSize = 12, Name = "Magi's pet mince 2"
                };
                food.Ingredients = ingredientsList;
                dbc.Foods.Add(food);
                dbc.SaveChanges();

                foodId = food.Id;
            }
            using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
            {
                var dogfood = dbc.Foods.Find(foodId);
                Assert.NotNull(dogfood);
                Assert.NotEmpty(dogfood.Ingredients);
                dogfood.Ingredients.Add("Desicated coconut");
                dogfood.Ingredients.Add("ZeroMSG");
                dogfood.Ingredients.Sort();
                dbc.SaveChanges();
            }
        }
Exemplo n.º 5
0
 public void CanReadShadowProperty()
 {
     using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
     {
         var pawtion = dbc.Pawtions.Find(1);
         Assert.Equal(1, dbc.Entry(pawtion).Property("DogFoodId").CurrentValue);
     }
 }
Exemplo n.º 6
0
 public void CanReadOutAPawtionEntity()
 {
     using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
     {
         var pawtion = dbc.Pawtions.Find(3);
         Assert.NotNull(pawtion);
     }
 }
Exemplo n.º 7
0
 public void CanReadOutADogFoodEntity()
 {
     using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
     {
         var dogfood = dbc.Foods.Find(1);
         Assert.NotNull(dogfood);
     }
 }
Exemplo n.º 8
0
 public void CanReadFromPawtionResultsViewWithNoKey()
 {
     using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
     {
         var allPawtions = dbc.PawtionResults;//.Where(x => x.AddedDate > System.DateTime.Today).ToList();
         Assert.NotEmpty(allPawtions);
         var todaysPawtions = allPawtions.Where(x => x.AddedDate > System.DateTime.Today).ToList();
         Assert.NotEmpty(todaysPawtions);
     }
 }
Exemplo n.º 9
0
 public void CanInsertAPawtionEntity()
 {
     using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
     {
         var food = new DogFood()
         {
             BagSize = 12, Name = "Hills Healthy Adult"
         };
         var pawtion = new Pawtion(food, 765, 32);
         dbc.Pawtions.Add(pawtion);
         dbc.SaveChanges();
         Assert.NotEqual(0, pawtion.Id);
         Assert.Equal(DateTime.Today, pawtion.AddedDate().Date);
     }
 }
Exemplo n.º 10
0
        public void WillNotAddDuplicateDogFoodBasedOnAlternateKey()
        {
            using (var dbc = PawtionContext.GetSQLiteContext(sqlFilename))
            {
                var dogfood1 = new DogFood()
                {
                    Name = "DogFood 1", BagSize = 12
                };
                var dogfood2 = new DogFood()
                {
                    Name = "DogFood 1", BagSize = 12
                };

                dbc.Foods.Add(dogfood1);
                Assert.ThrowsAny <System.InvalidOperationException>(() => dbc.Foods.Add(dogfood2));
                //()=>dbc.SaveChanges());
            }
        }
Exemplo n.º 11
0
        public static PawtionContext GetSQLiteContext(string filename)
        {
            PawtionContext pc = new PawtionContext(new SqliteOptions(filename));

            return(pc);
        }