public async Task GetGebruikerByIdTestMetMockRepositorySuccesvol() { var testResult = new Gebruiker { Id = 1, Gebruikersnaam = "pimm32", Rating = 1500 }; //arrange var mockUnitOfWork = new Mock <IGebruikerRepository>(); mockUnitOfWork.Setup(x => x.GetGebruikerByGebruikerId(1)).ReturnsAsync(testResult).Verifiable(); var service = new GebruikerService(mockUnitOfWork.Object); //Act var result = await service.GetGebruikerById(1) as Gebruiker; //Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.Id); Assert.AreEqual("pimm32", result.Gebruikersnaam); Assert.AreEqual(1500, result.Rating); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { GebruikerService service = new GebruikerService(); var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); Gebruiker gebruiker = new Gebruiker { gebruikerID = user.Id, voornaam = model.Voornaam, familienaam = model.Achternaam, gebruikersnaam = model.Gebruikersnaam, email = model.Email }; service.Create(gebruiker); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task GetAllGebruikersTestMetMockRepositorySuccesvol() { var testResult = new List <Gebruiker> { new Gebruiker { Id = 1, Gebruikersnaam = "pimm32", Rating = 1750 }, new Gebruiker { Id = 2, Gebruikersnaam = "karbonkel", Rating = 1952 } }; //arrange var mockUnitOfWork = new Mock <IGebruikerRepository>(); mockUnitOfWork.Setup(x => x.GetAllGebruikers()).ReturnsAsync(testResult).Verifiable(); var service = new GebruikerService(mockUnitOfWork.Object); //Act var result = await service.GetAllGebruikers() as List <Gebruiker>; //Assert Assert.IsNotNull(result); Assert.AreEqual(2, result.Count); Assert.AreEqual("karbonkel", result[1].Gebruikersnaam); Assert.AreEqual(1, result[0].Id); }