public void TestWorkshopWithDetails() { WorkshopWithDetails w = new WorkshopWithDetails { Id = 1, Title = "bla", Place = "blabla" }; Assert.AreEqual(1, w.Id); Assert.AreEqual("bla", w.Title); Assert.AreEqual("blabla", w.Place); }
public void SaveWorkshop(WorkshopWithDetails workshop) { if (workshop.Id == null) { workshop.Id = nextAvailableId; nextAvailableId++; } workshops[workshop.Id.Value] = new WorkshopWithDetails { Id = workshop.Id, Title = workshop.Title, Place = workshop.Place , Time = workshop.Time }; }
public ActionResult Create(FormCollection collection) { IWorkshopRepository inwr = (IWorkshopRepository)ControllerContext.HttpContext.Application["data"]; WorkshopWithDetails workshop = new WorkshopWithDetails(); if (TryUpdateModel(workshop)) { workshop.Id = null; inwr.SaveWorkshop(workshop); return View("Detail", workshop); } else { return View(); } }
public void TestAddWorkshop() { IWorkshopRepository repo = new InMemoryWorkshopRepository(); int n = repo.GetAllWorkshops().Count(); WorkshopWithDetails wd = new WorkshopWithDetails { Title = "bla", Place = "blabla" }; Assert.IsNull(wd.Id); repo.SaveWorkshop(wd); Assert.IsNotNull(wd.Id); Assert.AreEqual("bla", wd.Title); Assert.AreEqual("blabla", wd.Place); Assert.AreEqual(n + 1, repo.GetAllWorkshops().Count()); WorkshopWithDetails wd2 = repo.GetWorkshop(wd.Id.Value); Assert.AreEqual(wd.Title, wd2.Title); Assert.AreEqual(wd.Place, wd2.Place); }