public void AddRestrauntShouldAddCorrectRestauranttoDB(string Id, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddRestaurantTesting3DB")
                          .Options;

            Restaurant r = new Restaurant {
                Id = Id, Name = Id + " Diner", Lat = "loc", Lon = "loc"
            };
            RestaurantRepo rRepo;
            Restaurant     result;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                if (useAsync)
                {
                    rRepo.AddRestaurantAsync(r).Wait();
                }
                else
                {
                    rRepo.AddRestaurant(r);
                }
                result = context.Restaurant.Find(r.Id);
            }

            //Assert
            Assert.Equal(r, result);
        }
        public void AddRestaurantShouldThrowExceptionIfIdAlreadyInDB(string Id, bool useAsync)
        {
            //Arrange
            string dbName;

            if (useAsync)
            {
                dbName = "EmptyAddRestaurantAsyncTesting1DB";
            }
            else
            {
                dbName = "EmptyAddRestaurantTesting1DB";
            }
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: dbName)
                          .Options;

            Restaurant r = new Restaurant {
                Id = Id, Name = Id + " Diner", Lat = "loc", Lon = "loc"
            };
            Restaurant r2 = new Restaurant {
                Id = Id, Name = Id + " Diner", Lat = "loc", Lon = "loc"
            };
            RestaurantRepo rRepo;
            bool           result = false;

            using (var context = new Project2DBContext(options))
            {
                context.Restaurant.Add(r2);
                context.SaveChanges();
            }

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        rRepo.AddRestaurantAsync(r).Wait();
                    }
                    else
                    {
                        rRepo.AddRestaurant(r);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
        public void AddRestaurantShouldThrowExceptionIfLocationIsNull(string Id, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddRestaurantTesting2DB")
                          .Options;

            Restaurant r = new Restaurant {
                Id = Id, Name = Id + " Diner"
            };
            RestaurantRepo rRepo;
            bool           result = false;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        rRepo.AddRestaurantAsync(r).Wait();
                    }
                    else
                    {
                        rRepo.AddRestaurant(r);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
Esempio n. 4
0
 private void btnAddNew_Click(object sender, EventArgs e)
 {
     repo.AddRestaurant(txtNewText.Text);
     Close();
     parent.Show();
 }
Esempio n. 5
0
        //public HttpResponseMessage PostRestaurnt(Restaurant rest)
        //{
        //    _repo.AddRestaurant(rest);


        //    var response = Request.CreateResponse(HttpStatusCode.Created, rest);
        //    response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = rest.Id }));
        //    return response;

        //}
        public IHttpActionResult PostRestaurnt(Restaurant rest)
        {
            _repo.AddRestaurant(rest);

            return(CreatedAtRoute <Restaurant>("DefaultApi", new { id = rest.Id }, rest));
        }