public void TestAddCategoryToCategory() { // Arrange EventCtrl eCtrl = new EventCtrl(); ComponentCtrl cCtrl = new ComponentCtrl(); UserCtrl uCtrl = new UserCtrl(); var u = uCtrl.CreateUser("Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password"); var e = eCtrl.CreateEvent("Testing Event", "Test", 2, 20, 100, "Right here", DateTime.Now.AddHours(5), true, u); var c1 = cCtrl.CreateCategory("Testing Category Lvl 1", "Test", null); // Act eCtrl.AddCategory(e, c1); var c2 = cCtrl.CreateCategory("Testing Category Lvl 2", "Test", c1); var e2 = eCtrl.FindById(e.Id); eCtrl.AddCategory(e2, c2); Assert.IsTrue(c2.Parent.Id == c1.Id); Assert.IsTrue(c2.EventId == e.Id); }
public void CreateRegistrationTest() { // Arrange UserCtrl uCtrl = new UserCtrl(); var user = uCtrl.CreateUser("Jesper", "Jørgensen", "*****@*****.**" + Guid.NewGuid(), "123456"); EventCtrl eCtrl = new EventCtrl(); var eve = eCtrl.CreateEvent("Hej", "nej", 5, 5.5, 6.5, "42", DateTime.Now.AddHours(5), false, user); RegistrationCtrl rCtrl = new RegistrationCtrl(); // Act var reg = rCtrl.CreateRegistration(user, eve); //Assert user = uCtrl.UpdateUserInfo(user); eve = eCtrl.FindById(eve.Id); bool userHasReg = user.Registrations.Select(x => x.Id).Contains(reg.Id); bool eventHasReg = eve.Registrations.Select(x => x.Id).Contains(reg.Id); Assert.IsTrue(userHasReg); Assert.IsTrue(eventHasReg); }
public void TestAddComponent() { // Arrange EventCtrl eCtrl = new EventCtrl(); UserCtrl uCtrl = new UserCtrl(); var u = uCtrl.CreateUser("Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password"); var e = eCtrl.CreateEvent("Event", "Evently event", 2, 20, 100, "Right here", DateTime.Now, true, u); Category c = new ComponentCtrl().CreateCategory("Cat", "CateCat", null); //Act eCtrl.AddCategory(e, c); //Assert var foundEvent = eCtrl.FindById(e.Id); Assert.IsTrue(foundEvent.Components.Count == 1); var foundComponent = foundEvent.Components.First(); Assert.IsTrue(c.Id == foundComponent.Id); Assert.IsTrue(foundComponent is Category); // it returns true if an instance is in the inheritance tree }
public void TestRegisterToEvent() { // Arrange var ctrl = new EventCtrl(); var uCtrl = new UserCtrl(); Event e = new Event { Title = "test title" + Guid.NewGuid(), Description = "This is a long description\ncontaining newlines", NumOfParticipants = 5, PriceFrom = 100.0, PriceTo = 200.0, Location = "Sofiendalsvej 60", Datetime = DateTime.Now.AddHours(1), //+1 hour from now to not trigger the past date exception IsPublic = true }; var user = uCtrl.CreateUser("efrgfvd", "fss", "*****@*****.**" + Guid.NewGuid(), "dsasdc"); Event newEvent = ctrl.CreateEvent(e.Title, e.Description, e.NumOfParticipants, e.PriceFrom, e.PriceTo, e.Location, e.Datetime, e.IsPublic, user); // Act ctrl.RegisterToEvent(newEvent, user); // Assert using (var ctx = new DAL.DALContext()) { user = uCtrl.FindByEmail(user.Email); newEvent = ctrl.FindById(newEvent.Id); var reg = user.Registrations[0]; Assert.AreEqual(reg.User, user); Assert.AreEqual(reg.Event.Id, newEvent.Id); Assert.IsTrue(user.Registrations.Contains(reg)); Assert.IsTrue(newEvent.Registrations.Exists(r => r.Id == reg.Id)); } }
public Event FindEventById(int id) { return(eCtrl.FindById(id)); }