Esempio n. 1
0
        public ActionResult Create(LunchCreateEditViewModel lunchCreateEditViewModel)
        {
            var selectedRestaurants = lunchCreateEditViewModel.Restaurants.Where(r => r.IsChecked).Select(r => r.ID).ToList();

            if (ModelState.IsValid)
            {
                var lunch = new Lunch()
                {
                    Host        = lunchCreateEditViewModel.Host,
                    MeetingTime = lunchCreateEditViewModel.MeetingTime
                };

                foreach (var restaurantId in selectedRestaurants)
                {
                    var restaurant = _context.Restaurants.Find(restaurantId);
                    lunch.Restaurants.Add(restaurant);
                }

                _context.Lunches.Add(lunch);
                _context.SaveChanges();

                return(RedirectToAction("Index"));
            }


            return(View("Create", lunchCreateEditViewModel));
        }
Esempio n. 2
0
        public void Upvote_PostWithDifferntUser_CreatedOneVoteWhenCalledMultipleTimes()
        {
            var existingVote = new Vote
            {
                Restaurant = _context.Restaurants.Find(_restaurantId1),
                Lunch      = _context.Lunches.Find(_lunchId),
                Value      = 1,
                UserName   = "******"
            };

            _context.Votes.Add(existingVote);
            _context.SaveChanges();

            // Act
            var result1 = _controller.Upvote(_lunchId, _restaurantId1);
            var result2 = _controller.Upvote(_lunchId, _restaurantId1);

            // Assert
            var numberOfVotes = _context.Votes.Count();

            numberOfVotes.ShouldBe(2);

            var voteValue = _context.Votes
                            .Where(v => v.Restaurant.Id == _restaurantId1)
                            .Where(v => v.Lunch.Id == _lunchId)
                            .Where(v => v.UserName == "Brent")
                            .Sum(v => v.Value);

            voteValue.ShouldBe(1);

            AssertLunchRestaurantVoteTotal(_lunchId, _restaurantId1, 2);
        }
Esempio n. 3
0
        public void StuffStartsHere()
        {
            _context = new DevLunchDbContext(Effort.DbConnectionFactory.CreateTransient());

            _controller = new LunchesController(_context);
            _controller.WithAuthenticatedUser("Brent", "ImBrent");

            _lunch = new Lunch()
            {
                Host        = "Brent",
                MeetingTime = new DateTime(1985, 6, 6),
                Restaurants = new List <Restaurant>()
                {
                    new Restaurant {
                        Name = "Linda's", Latitude = 55, Longitude = 60
                    },
                    new Restaurant {
                        Name = "The Pine Box", Latitude = 55, Longitude = 60
                    },
                    new Restaurant {
                        Name = "Sizzler", Latitude = 55, Longitude = 60
                    }
                }
            };

            _context.Lunches.Add(_lunch);
            _context.SaveChanges();

            _lunchId       = _lunch.Id;
            _restaurantId1 = _lunch.Restaurants.First().Id;
            _restaurantId2 = _lunch.Restaurants.FirstOrDefault(r => r.Name == "The Pine Box").Id;
            _restaurantId3 = _lunch.Restaurants.Last().Id;
        }
Esempio n. 4
0
 public ActionResult Create([Bind(Include = "Name, Longitude, Latitude")] Restaurant restaurant)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _context.Restaurants.Add(restaurant);
             _context.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception)
     {
     }
     return(View(restaurant));
 }
        public void Details_ReturnsOneLunchWithRestaurantsWithVotes()
        {
            // Arrange
            _context.Lunches.Add(new Lunch
            {
                Host        = "Brent",
                Restaurants = new List <Restaurant>
                {
                    new Restaurant
                    {
                        Name      = "Lunchbox Labs",
                        Longitude = 55,
                        Latitude  = 42
                    }
                },
                MeetingTime = new DateTime(1999, 12, 31)
            });

            _context.SaveChanges();

            _context.Votes.AddRange(
                new List <Vote>
            {
                new Vote {
                    Lunch = _context.Lunches.First(), Restaurant = _context.Restaurants.First(), Value = 2
                },
                new Vote {
                    Lunch = _context.Lunches.First(), Restaurant = _context.Restaurants.First(), Value = 3
                },
                new Vote {
                    Lunch = _context.Lunches.First(), Restaurant = _context.Restaurants.First(), Value = -8
                }
            }
                );

            _context.SaveChanges();

            var controller = new LunchesController(_context);

            // Act
            var id     = _context.Lunches.First().Id;
            var result = controller.Details(id) as ViewResult;

            // Assert
            var data = result.Model as LunchDetailsViewModel;

            data.ShouldNotBeNull();
            data.Id.ShouldBe(1);
            data.Restaurants.Count.ShouldBe(1);
            data.Votes.Count.ShouldBe(3);
            data.Votes.Sum(v => v.Value).ShouldBe(-3);
            data.Host.ShouldBe("Brent");
        }
Esempio n. 6
0
        protected override void Seed(DevLunchDbContext context)
        {
            context.Votes.RemoveRange(context.Votes);
            context.Restaurants.RemoveRange(context.Restaurants);
            context.Lunches.RemoveRange(context.Lunches);

            var restaurants = new List <Restaurant>
            {
                new Restaurant {
                    Name = "Rocco’s"
                },
                new Restaurant {
                    Name = "Li’l Woody’s"
                },
                new Restaurant {
                    Name = "Biscuit Bitch Belltown"
                },
                new Restaurant {
                    Name = "Lunchbox Laboratory"
                },
                new Restaurant {
                    Name = "Citrus Thai Cuisine"
                },
                new Restaurant {
                    Name = "Icon Grill"
                },
                new Restaurant {
                    Name = "FareStart"
                },
                new Restaurant {
                    Name = "Gordon Biersch"
                },
                new Restaurant {
                    Name = "Dahlia Lounge"
                },
                new Restaurant {
                    Name = "Cactus"
                },
                new Restaurant {
                    Name = "Blue Moon Burgers"
                },
                new Restaurant {
                    Name = "Serious Pie"
                },
                new Restaurant {
                    Name = "Brave Horse Tavern"
                }
            };

            context.Restaurants.AddRange(restaurants);
            context.SaveChanges();
        }
Esempio n. 7
0
        public void Details_ReturnsOneRestaurant()
        {
            // Arrange
            _context.Restaurants.Add(new Restaurant {
                Name = "Brave Horse"
            });
            _context.SaveChanges();
            var controller = new RestaurantController(_context);

            // Act
            var Id     = _context.Restaurants.First().Id;
            var result = controller.Details(Id) as ViewResult;

            // Assert
            var data = result.Model as Restaurant;

            data.ShouldNotBeNull();
            data.Id.ShouldBe(1);
            data.Name.ShouldBe("Brave Horse");
        }