public async Task ShouldUpdateMainEvent() { MainEventService mainEventService = new MainEventService(_dbContext, _userManager); SecurityService securityService = new SecurityService(_dbContext, _userManager, _roleManager); MainEventController mainEventController = new MainEventController(mainEventService, securityService); CreateUser(); SetUser(mainEventController, _createdUser.Entity.Id); CreateMainEvents(); string newName = "Test name 3"; DateTime newStartTime = DateTime.Now.AddDays(4); DateTime newEndTime = DateTime.Now.AddDays(8); MainEventVm mainEventVm = new MainEventVm { Id = 2, Name = newName, StartDateTime = newStartTime, EndDateTime = newEndTime, VenueId = 2, OrganizerId = 2 }; await mainEventController.UpdateMainEventAsync(mainEventVm); // Check that only one has been changed MainEvent mainEvent1 = _dbContext.MainEvents.Find(2); Assert.AreEqual(newName, mainEvent1.Name); Assert.AreEqual(newStartTime, mainEvent1.StartDateTime); Assert.AreEqual(newEndTime, mainEvent1.EndDateTime); }
public async Task ShouldCreateMainEvent() { string name = "Test Event 3"; DateTime startDateTime = DateTime.Now; DateTime endDateTime = DateTime.Now; MainEventService mainEventService = new MainEventService(_dbContext, _userManager); SecurityService securityService = new SecurityService(_dbContext, _userManager, _roleManager); MainEventController mainEventController = new MainEventController(mainEventService, securityService); CreateUser(); SetUser(mainEventController, _createdUser.Entity.Id); CreateOrganizers(); CreateVenues(); MainEventVm mainEventVm = new MainEventVm { Name = name, StartDateTime = startDateTime, EndDateTime = endDateTime, VenueId = 2, OrganizerId = 2 }; await mainEventController.CreateMainEventAsync(mainEventVm); ActionResult <List <MainEventListVm> > result = await mainEventController.GetMainEventsAsync(); List <MainEventListVm> returnedMainEvents = (List <MainEventListVm>)((OkObjectResult)result.Result).Value; Assert.AreEqual(2, returnedMainEvents.Count); Assert.AreEqual(mainEventVm.Name, returnedMainEvents[1].Name); Assert.AreEqual(mainEventVm.StartDateTime, returnedMainEvents[1].StartDateTime); Assert.AreEqual(mainEventVm.EndDateTime, returnedMainEvents[1].EndDateTime); }
public void ShouldNotGetMainEventWithInvalidId() { MainEventService mainEventService = new MainEventService(_dbContext, _userManager); SecurityService securityService = new SecurityService(_dbContext, _userManager, _roleManager); MainEventController mainEventController = new MainEventController(mainEventService, securityService); var ex = Assert.ThrowsAsync <HttpException>(async() => { await mainEventController.GetMainEventAsync(123); }); Assert.AreEqual("Fant ingen arrangementer med id: 123", ex.Message); }
public async Task ShouldGetMainEventsOfUserParticipation() { MainEventService mainEventService = new MainEventService(_dbContext, _userManager); SecurityService securityService = new SecurityService(_dbContext, _userManager, _roleManager); MainEventController mainEventController = new MainEventController(mainEventService, securityService); SetUser(mainEventController, _createdUser1.Entity.Id); ActionResult <List <UserMainEventsVm> > result = await mainEventController.GetMainEventsOfUserParticipationAsync(); List <UserMainEventsVm> returnedMainEvents = (List <UserMainEventsVm>)((OkObjectResult)result.Result).Value; Assert.AreEqual(1, returnedMainEvents[0].Id); }
public async Task ShouldGetMainEventsForOrgAdmin() { CreateUser(); CreateMainEvents(); MainEventService mainEventService = new MainEventService(_dbContext, _userManager); SecurityService securityService = new SecurityService(_dbContext, _userManager, _roleManager); MainEventController mainEventController = new MainEventController(mainEventService, securityService); SetUser(mainEventController, _createdUser.Entity.Id); ActionResult <List <MainEventListVm> > result = await mainEventController.GetMainEventsForOrgAdminAsync(); List <MainEventListVm> returnedMainEvents = (List <MainEventListVm>)((OkObjectResult)result.Result).Value; Assert.AreEqual(2, returnedMainEvents[0].Id); }
public async Task ShouldGetMainEvent() { UserStore <ApplicationUser> store = new UserStore <ApplicationUser>(_dbContext); UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(store, null, new PasswordHasher <ApplicationUser>(), null, null, null, null, null, null); MainEventService mainEventService = new MainEventService(_dbContext, userManager); SecurityService securityService = new SecurityService(_dbContext, userManager, _roleManager); MainEventController mainEventController = new MainEventController(mainEventService, securityService); CreateUser(); SetUser(mainEventController, _createdUser.Entity.Id); CreateMainEvents(); await mainEventController.SetCurrentEventAsync(2); ActionResult <CurrentMainEventVm> result = await mainEventController.GetCurrentMainEventAsync(); Assert.AreEqual(_eventName2, result.Value.Name); }
public async Task ShouldSetMainEvent() { UserStore <ApplicationUser> store = new UserStore <ApplicationUser>(_dbContext); UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(store, null, new PasswordHasher <ApplicationUser>(), null, null, null, null, null, null); MainEventService mainEventService = new MainEventService(_dbContext, userManager); SecurityService securityService = new SecurityService(_dbContext, userManager, _roleManager); MainEventController mainEventController = new MainEventController(mainEventService, securityService); CreateUser(); SetUser(mainEventController, _createdUser.Entity.Id); CreateMainEvents(); await mainEventController.SetCurrentEventAsync(2); ApplicationUser usr = _dbContext.Users.Find(_createdUser.Entity.Id); Assert.AreEqual(usr.CurrentMainEventId, _createdUser.Entity.CurrentMainEventId); }
public async Task ShouldGetMainEvents() { CreateUser(); CreateMainEvents(); MainEventService mainEventService = new MainEventService(_dbContext, _userManager); SecurityService securityService = new SecurityService(_dbContext, _userManager, _roleManager); MainEventController mainEventController = new MainEventController(mainEventService, securityService); ActionResult <List <MainEventListVm> > result = await mainEventController.GetMainEventsAsync(); List <MainEventListVm> returnedMainEvents = (List <MainEventListVm>)((OkObjectResult)result.Result).Value; Assert.AreEqual(2, returnedMainEvents.Count); Assert.AreEqual(1, returnedMainEvents[0].Id); Assert.AreEqual("Event 1", returnedMainEvents[0].Name); Assert.AreEqual(2, returnedMainEvents[1].Id); Assert.AreEqual(_eventName2, returnedMainEvents[1].Name); }
public async Task ShouldGetMainEventById() { CreateUser(); CreateMainEvents(); // Check that we can get both by id MainEventService mainEventService = new MainEventService(_dbContext, _userManager); SecurityService securityService = new SecurityService(_dbContext, _userManager, _roleManager); MainEventController mainEventController = new MainEventController(mainEventService, securityService); ActionResult <MainEventVm> result1 = await mainEventController.GetMainEventAsync(1); MainEventVm returnedMainEvent = (MainEventVm)((OkObjectResult)result1.Result).Value; Assert.AreEqual(1, returnedMainEvent.Id); Assert.AreEqual("Event 1", returnedMainEvent.Name); ActionResult <MainEventVm> result2 = await mainEventController.GetMainEventAsync(2); MainEventVm returnedMainEvent2 = (MainEventVm)((OkObjectResult)result2.Result).Value; Assert.AreEqual(2, returnedMainEvent2.Id); Assert.AreEqual(_eventName2, returnedMainEvent2.Name); }