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 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); }