public void ConfirmEmailShouldReturnBadRequestIfConfirmationFails() { //Arrange var model = new ConfirmEmailModelBuilder().Build(); var existingUser = new User(); var errorCode = Guid.NewGuid().ToString(); var identityResult = IdentityResult.Failed(new IdentityError { Code = errorCode, Description = Guid.NewGuid().ToString() }); _userManagerMock.Setup(manager => manager.FindByIdAsync(It.IsAny <string>())).ReturnsAsync(() => existingUser); _userManagerMock.Setup(manager => manager.ConfirmEmailAsync(It.IsAny <User>(), It.IsAny <string>())) .ReturnsAsync(identityResult); //Act var result = _controller.ConfirmEmail(model).Result as BadRequestObjectResult; //Assert Assert.That(result, Is.Not.Null); var serializableError = result.Value as SerializableError; Assert.That(serializableError, Is.Not.Null); Assert.That(serializableError.Keys, Has.One.EqualTo(errorCode)); _userManagerMock.Verify(manager => manager.FindByIdAsync(model.UserId), Times.Once); _userManagerMock.Verify(manager => manager.ConfirmEmailAsync(existingUser, model.Token), Times.Once); }
public void ConfirmEmailShouldReturnOkIfUserCannotBeFound() { //Arrange var model = new ConfirmEmailModelBuilder().Build(); _userManagerMock.Setup(manager => manager.FindByIdAsync(It.IsAny <string>())).ReturnsAsync(() => null); //Act var result = _controller.ConfirmEmail(model).Result as OkResult; //Assert Assert.That(result, Is.Not.Null); _userManagerMock.Verify(manager => manager.FindByIdAsync(model.UserId), Times.Once); _userManagerMock.Verify(manager => manager.ConfirmEmailAsync(It.IsAny <User>(), It.IsAny <string>()), Times.Never); }
public void ConfirmEmailShouldReturnOkIfConfirmationSucceeds() { //Arrange var model = new ConfirmEmailModelBuilder().Build(); var existingUser = new User(); _userManagerMock.Setup(manager => manager.FindByIdAsync(It.IsAny <string>())).ReturnsAsync(() => existingUser); _userManagerMock.Setup(manager => manager.ConfirmEmailAsync(It.IsAny <User>(), It.IsAny <string>())) .ReturnsAsync(IdentityResult.Success); //Act var result = _controller.ConfirmEmail(model).Result as OkResult; //Assert Assert.That(result, Is.Not.Null); _userManagerMock.Verify(manager => manager.FindByIdAsync(model.UserId), Times.Once); _userManagerMock.Verify(manager => manager.ConfirmEmailAsync(existingUser, model.Token), Times.Once); }
public void ConfirmEmailShouldReturnBadRequestIfModelIsInvalid() { //Arrange var model = new ConfirmEmailModelBuilder().Build(); var errorKey = "someValidationError"; _controller.ModelState.AddModelError(errorKey, Guid.NewGuid().ToString()); //Act var result = _controller.ConfirmEmail(model).Result as BadRequestObjectResult; //Assert Assert.That(result, Is.Not.Null); var serializableError = result.Value as SerializableError; Assert.That(serializableError, Is.Not.Null); Assert.That(serializableError.Keys, Has.One.EqualTo(errorKey)); _userManagerMock.Verify(manager => manager.FindByIdAsync(It.IsAny <string>()), Times.Never); _userManagerMock.Verify(manager => manager.ConfirmEmailAsync(It.IsAny <User>(), It.IsAny <string>()), Times.Never); }