Exemple #1
0
 private void Seed()
 {
     //this is an exmaple of a using block
     using (var context = new Entity.RestaurantDBContext(options))
     {
         //This makes sure that the state of the db gets recreated everytime to maintain modularity of tests
         context.Database.EnsureDeleted();
         context.Database.EnsureCreated();
         context.Restaurants.AddRange
         (
             new Entity.Restaurant
         {
             Id      = 1,
             Name    = "Good Taste",
             City    = "Baguio City",
             State   = "Benguet",
             Reviews = new List <Entity.Review>
             {
                 new Entity.Review
                 {
                     Id          = 1,
                     Rating      = 5,
                     Description = "This was good"
                 },
                 new Entity.Review
                 {
                     Id          = 2,
                     Rating      = 5,
                     Description = "Pretty cool"
                 }
             }
         },
             new Entity.Restaurant
         {
             Id      = 2,
             Name    = "Maru Sushi",
             City    = "Kalamazoo",
             State   = "Michigan",
             Reviews = new List <Entity.Review>
             {
                 new Entity.Review
                 {
                     Id          = 3,
                     Rating      = 5,
                     Description = "This was good sushi"
                 },
                 new Entity.Review
                 {
                     Id          = 4,
                     Rating      = 5,
                     Description = "Pretty cool sushi"
                 }
             }
         }
         );
         context.SaveChanges();
     }
 }
Exemple #2
0
        public void GetAllRestaurantsShouldReturnAllRestaurants()
        {
            //putting in a test context/ connection to our test db
            using (var context = new Entity.RestaurantDBContext(options))
            {
                //Arrange
                IRepository _repo = new RepoDB(context);

                //Act
                var restaurants = _repo.GetAllRestaurants();

                //Assert
                Assert.Equal(2, restaurants.Count);
            }
        }
Exemple #3
0
 public void AddRestaurantShouldAddRestaurant()
 {
     using (var context = new Entity.RestaurantDBContext(options))
     {
         IRepository _repo = new RepoDB(context);
         //Act with a test context
         _repo.AddRestaurant
         (
             new Model.Restaurant("Whataburger", "Dallas", "TX")
         );
     }
     //use a diff context to check if changes persist to db
     using (var assertContext = new Entity.RestaurantDBContext(options))
     {
         //Assert with a different context
         var result = assertContext.Restaurants.FirstOrDefault(restaurant => restaurant.Id == 3);
         Assert.NotNull(result);
         Assert.Equal("Dallas", result.City);
     }
 }