public void TestUpdateWorkshop() { var workshop = new Workshop(); workshop.Date = DateTime.Now; workshop.Title = "Sample workshop"; workshop.Description = "Sample"; var reservation = new Reservation(); reservation.UserName = "******"; workshop.Reservations.Add(reservation); var repository = new WorkshopRepository(); repository.InsertOrUpdate(workshop); repository.Save(); var foundWorkshop = repository.Find(workshop.Id); foundWorkshop.Reservations.Add(new Reservation() { UserName = "******"}); repository.InsertOrUpdate(foundWorkshop); repository.Save(); var results = repository.Find(foundWorkshop.Id); Assert.AreEqual(2,results.Reservations.Count); }
public ActionResult Create(Workshop workshop) { try { // Automatically create reservations for the members in the application // that are not marked as optional and are confirmed foreach (var membership in _membershipRepository.GetMemberships()) { Reservation reservation = new Reservation(); reservation.UserName = membership.UserName; workshop.Reservations.Add(reservation); } // Save the workshop to the database _workshopRepository.InsertOrUpdate(workshop); _workshopRepository.Save(); return RedirectToAction("Details", new { id = workshop.Id }); } catch (Exception) { return View(workshop); } }
public void TestInsertWorkshopWithReservations() { var workshop = new Workshop(); workshop.Date = DateTime.Now; workshop.Title = "Sample workshop"; workshop.Description = "Sample"; var reservation = new Reservation(); reservation.UserName = "******"; workshop.Reservations.Add(reservation); var repository = new WorkshopRepository(); repository.InsertOrUpdate(workshop); repository.Save(); var results = repository.Find(workshop.Id); Assert.IsNotNull(results); Assert.AreEqual(1,results.Reservations.Count); }