public void ShouldThrowExceptionWhenUpdateUserFails() { _userRepository = new Mock<IUserRepository>(); _userRepository.Setup(a => a.Edit(It.IsAny<User>())) .Throws(new Exception()); _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.Update(new Common.Contracts.User())); }
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); }