private async Task <LokaalController> SetupLokaalController(LokaalService service) { ctxDb.Roles.Add(new IdentityRole { Name = "Student", NormalizedName = "STUDENT" }); ctxDb.SaveChanges(); AccountService accService = new AccountService(userManager, signInManager); var user = await accService.RegisterUser(new RegisterViewModel { RNum = "r0000001", Email = "*****@*****.**", Name = "Thomas", SurName = "Claes", Password = "******", ConfirmPassword = "******", GeboorteDatum = new DateTime(1998, 9, 21) }); IOptions <IdentityOptions> options = Options.Create <IdentityOptions>(new IdentityOptions { }); UserClaimsPrincipalFactory <ApplicationUser> userClaimFactory = new UserClaimsPrincipalFactory <ApplicationUser>(userManager, options); var claim = userClaimFactory.CreateAsync(user).Result; var httpContext = new Mock <HttpContext>(); httpContext.Setup(x => x.User).Returns(claim); var context = new ControllerContext(new ActionContext(httpContext.Object, new RouteData(), new ControllerActionDescriptor())); return(new LokaalController(service) { ControllerContext = context, TempData = new TempDataDictionary(httpContext.Object, Mock.Of <ITempDataProvider>()) }); }
public void EditLokaalTest() { // ARRANGE LokaalService service = new LokaalService(ctxDb); service.AddLokaal("A", 2, "01", "Vergaderlokaal", 5, "Geen middelen"); int lId = ctxDb.Room.Where(i => i.Verdiep.Equals(2)).FirstOrDefault().Id; string gebouw = "B"; //verdiep blijft hetzelfde string nummer = "02"; string type = "Aula"; int capac = 10; string middelen = "Scherm"; // ACT service.EditLokaal(lId, gebouw, 2, nummer, type, capac, middelen); // ASSERT Room room = ctxDb.Room.Find(lId); Assert.IsTrue(room.Gebouw.Equals("B")); Assert.IsTrue(room.Verdiep == 2); Assert.IsTrue(room.Nummer.Equals("02")); Assert.IsTrue(room.Type.Equals("Aula")); Assert.IsTrue(room.Capaciteit == 10); Assert.IsTrue(room.Middelen.Equals("Scherm")); }
public void AddTest() { // ARRANGE LokaalService service = new LokaalService(ctxDb); LokaalController controller = SetupLokaalController(service).Result; // ACT var res = controller.Add("A", 1, "01", "Lokaal", 20, "wifi"); // ASSERT Assert.IsTrue(res is ActionResult); Assert.IsNotNull(ctxDb.Room.Where(r => r.Gebouw == "A" && r.Verdiep == 1 && r.Gebouw == "01")); }
public void DeleteLokaalTest() { // ARRANGE LokaalService service = new LokaalService(ctxDb); service.AddLokaal("A", 2, "01", "Vergaderlokaal", 5, "Geen middelen"); int lId = ctxDb.Room.Where(i => i.Verdiep.Equals(2)).FirstOrDefault().Id; // ACT service.DeleteLokaal(lId); // ASSERT Assert.IsTrue(!ctxDb.Room.Any()); }
public void AddLokaalTest() { // ARRANGE LokaalService service = new LokaalService(ctxDb); // ACT service.AddLokaal("A", 2, "01", "Vergaderlokaal", 5, "Geen middelen"); Room room = ctxDb.Room.Where(c => c.Gebouw.Equals("A")).FirstOrDefault(); // ASSERT Assert.IsNotNull(room); Assert.IsTrue(room.Gebouw == "A"); Assert.IsTrue(room.Verdiep == 2); Assert.IsTrue(room.Nummer == "01"); }
public void DeleteTest() { // ARRANGE LokaalService service = new LokaalService(ctxDb); LokaalController controller = SetupLokaalController(service).Result; service.AddLokaal("A", 1, "01", "Lokaal", 20, "wifi"); var roomId = ctxDb.Room.Where(r => r.Gebouw == "A" && r.Verdiep == 1 && r.Nummer == "01").FirstOrDefault().Id; // ACT var res = controller.Delete(roomId); // ASSERT Assert.IsTrue(res is ActionResult); Assert.IsNull(ctxDb.Room.Where(r => r.Gebouw == "A" && r.Verdiep == 1 && r.Nummer == "01").FirstOrDefault()); }