public async void AddPersonRouteInvalidEmailFormat_Test() { // Arrange var newPerson = CreatePerson(); newPerson.Email = "Wrongemailformat"; var personController = new PersonController(_personRepository.Object, _mapper, _emailHelper.Object, _tokenClass.Object); // Act var result = await personController.AddPersonAsync(newPerson); var okResult = result as OkObjectResult; // Assert Assert.True(okResult != null); Assert.Equal(200, okResult.StatusCode); Assert.Equal("Email in incorrect format", okResult.Value.ToString()); }
public async void AddPersonRoute_Test() { var linkString = $"Please confirm your account by clicking this link: <a href='https://localhost:5001/api/email/AddPerson'>link</a>"; // Arrange var newPerson = CreatePerson(); // Setup Single base repository function to return nothing _personRepository .Setup(x => x.Single(It.IsAny <Expression <Func <Person, bool> > >())) .ReturnsAsync((Person)null); _personRepository .Setup(a => a.Add(It.IsAny <Person>())) .ReturnsAsync(true); _personRepository .Setup(x => x.Update(It.IsAny <Expression <Func <Person, bool> > >(), It.IsAny <Person>())) .ReturnsAsync(true); _emailHelper .Setup(e => e.SendEmail(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(true); _emailHelper .Setup(e => e.ConfirmationLinkBody(It.IsAny <Person>(), It.IsAny <string>())) .Returns(linkString); _tokenClass .Setup(t => t.CreateToken()) .Returns("abcdefghitj"); var personController = new PersonController(_personRepository.Object, _mapper, _emailHelper.Object, _tokenClass.Object); // Act var result = await personController.AddPersonAsync(newPerson); var okResult = result as OkObjectResult; // Assert Assert.True(okResult != null); Assert.Equal(200, okResult.StatusCode); Assert.Equal(bool.TrueString, okResult.Value.ToString()); }