public void Details_ReturnsHttpNotFound_WhenRecordDoesNotExist() { var controller = new LunchesController(_context); // Act var result = controller.Details(999) as HttpStatusCodeResult; // Assert result.ShouldBeOfType <HttpNotFoundResult>(); result.StatusCode.ShouldBe(404); }
public void Edit_Get_ThrowsNotFoundIfRecordNotInDb() { var _context = new DevLunchDbContext(Effort.DbConnectionFactory.CreateTransient()); var controller = new LunchesController(_context); // Act var result = controller.Details(999) as HttpStatusCodeResult; // Assert result.ShouldBeOfType <HttpNotFoundResult>(); result.StatusCode.ShouldBe(404); }
public void Details_WithoutIdThrows() { // Arrange var controller = new LunchesController(_context); // Act var result = controller.Details(null) as HttpStatusCodeResult; // Assert result.ShouldBeOfType <HttpStatusCodeResult>(); result.StatusCode.ShouldBe(400); }
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"); }