public void ShouldUpdateUser() { var request = new Common.Contracts.User { UserName = "******", IdentityId = "fooBar12345!", FirstName = "foo", LastName = "bar", EmailAddress = "*****@*****.**", BirthDate = DateTime.Now }; var result = new User { UserName = "******", IdentityId = "fooBar12345!", FirstName = "foo", LastName = "bar", EmailAddress = "*****@*****.**", BirthDate = DateTime.Now }; _userRepository = new Mock<IUserRepository>(); _userRepository.Setup(a => a.Edit(It.IsAny<User>())) .Returns(result); _addressRepository = new Mock<IAddressRepository>(); _educationRepository = new Mock<IEducationRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _usersLogic = new UsersLogic(_userRepository.Object, _addressRepository.Object, _educationRepository.Object, _mediaRepository.Object); var user = _usersLogic.Update(request); Assert.NotNull(user); Assert.IsNull(user.Error); }
public void ShouldErrorWhenAddUserWhenUserExists() { var request = new Common.Contracts.User { UserName = "******", IdentityId = "bar", FirstName = "foo", LastName = "bar", EmailAddress = "*****@*****.**", BirthDate = DateTime.Now }; _userRepository = new Mock<IUserRepository>(); _userRepository.Setup(a => a.Find(It.IsAny<Expression<Func<User, bool>>>(), false)) .Returns(_users); _addressRepository = new Mock<IAddressRepository>(); _educationRepository = new Mock<IEducationRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _usersLogic = new UsersLogic(_userRepository.Object, _addressRepository.Object, _educationRepository.Object, _mediaRepository.Object); var user = _usersLogic.Add(request); Assert.NotNull(user.Error); Assert.AreEqual(user.Error.Id, (int)Constants.Error.ValidationError); Assert.AreEqual(user.Error.Message, "Username already exists"); }
public void ShouldThrowExceptionWhenAddUserFails() { var request = new Common.Contracts.User { UserName = "******", IdentityId = "fooBar12345!", FirstName = "foo", LastName = "bar", EmailAddress = "*****@*****.**", BirthDate = DateTime.Now }; _userRepository = new Mock<IUserRepository>(); _userRepository.Setup(a => a.Add(It.IsAny<User>())) .Throws(new Exception()); _userRepository.Setup(a => a.Find(It.IsAny<Expression<Func<User, bool>>>(), false)) .Returns(new List<User>()); _addressRepository = new Mock<IAddressRepository>(); _educationRepository = new Mock<IEducationRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _usersLogic = new UsersLogic(_userRepository.Object, _addressRepository.Object, _educationRepository.Object, _mediaRepository.Object); Assert.Throws<BlogException>(() => _usersLogic.Add(request)); }
public void ShouldErrorWhenAddUserHasInvalidEmail() { var request = new Common.Contracts.User { UserName = "******", IdentityId = "bar", FirstName = "foo", LastName = "bar", EmailAddress = "test", BirthDate = DateTime.Now }; _userRepository = new Mock<IUserRepository>(); _addressRepository = new Mock<IAddressRepository>(); _educationRepository = new Mock<IEducationRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _usersLogic = new UsersLogic(_userRepository.Object, _addressRepository.Object, _educationRepository.Object, _mediaRepository.Object); var user = _usersLogic.Add(request); Assert.NotNull(user.Error); Assert.AreEqual(user.Error.Id, (int)Constants.Error.ValidationError); Assert.AreEqual(user.Error.Message, "Invalid email address"); }