public async Task<IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var user = new ApplicationUser() { UserName = model.Email, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return GetErrorResult(result); } else { await SendConfirmationEmail(user); } return Ok(); }
//[TestMethod] public void TestThatRegistrationSendsConfirmationMail() { Continuum.WebApi.Controllers.AccountController account = new WebApi.Controllers.AccountController(); var mock = new MockMailProvider(); account.MailProvider = mock; Random r = new Random(); RegisterBindingModel model = new RegisterBindingModel() { Email = r.Next() + "@example.com", Password = "******", ConfirmPassword = "******" }; var result = account.Register(model); result.Wait(); Assert.IsTrue(mock.MailWasSent, "Mail was not sent"); Assert.IsTrue(mock.Message.Destination == model.Email); }