public Task <int> AddUserAsync(DomainUsers.User domainUser) { var dataUser = _mapper.Map <User>(domainUser); var userRepository = _unitOfWork.GetRepository <User>(); userRepository.Insert(dataUser); return(_unitOfWork.SaveChangesAsync()); }
//private int _songCount; public Playlist(string name, User owner, IEnumerable<Song> songs) { _owner = owner; _owner.AddPlaylist(this); _name = name; foreach (var song in songs) { _playlistSongs.Add(new PlaylistSong(song, this)); } }
public void CanChangeEmail() { var userRepository = GetFakeRepositoryInstance(emailIsUnique: true); var culture = new CultureInfo("nl-NL"); var user = new User("*****@*****.**", "Robin van der Knaap", culture, userRepository, DefaultTestApplicationSettings); user.SetEmail("*****@*****.**", userRepository); Assert.AreEqual("*****@*****.**", user.Email); }
public void CanDetermineIfUserIsInRole() { var userRepository = GetFakeRepositoryInstance(emailIsUnique: true); var culture = new CultureInfo("nl-NL"); var user = new User("*****@*****.**", "Robin van der Knaap", culture, userRepository, DefaultTestApplicationSettings); user.Roles.Add(Role.Administrator); Assert.IsTrue(user.IsInRole(Role.Administrator)); Assert.IsFalse(user.IsInRole("user")); }
public void CanCreateUser() { var userRepository = GetFakeRepositoryInstance(emailIsUnique:true); var culture = new CultureInfo("nl-NL"); var user = new User("*****@*****.**", "Robin van der Knaap", culture, userRepository, DefaultTestApplicationSettings); Assert.AreEqual("*****@*****.**", user.Email); Assert.AreEqual("Robin van der Knaap", user.DisplayName); Assert.AreEqual(culture, user.Culture); Assert.AreEqual(0, user.Roles.Count); }
public async Task <DomainUsers.User> AuthenticateUserAsync(DomainUsers.User user) { var authenticatedUser = await GetUserAsync(user.Username, user.Password).ConfigureAwait(false); if (authenticatedUser == null) { throw new UnauthenticatedUserException("User is not authenticated", user.Username, user.Password); } var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_settings.JwtGeneratorKey); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, authenticatedUser.Id.ToString()), new Claim(ClaimTypes.Role, authenticatedUser.Role) }), Expires = DateTime.UtcNow.AddDays(1), Issuer = "blogs.api", Audience = "blogs.api", SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); authenticatedUser.Token = tokenHandler.WriteToken(token); authenticatedUser.Password = null; return(authenticatedUser); }
public void CanGetIdentity() { var userRepository = GetFakeRepositoryInstance(emailIsUnique: true); var culture = new CultureInfo("nl-NL"); var user = new User("*****@*****.**", "Robin van der Knaap", culture, userRepository, DefaultTestApplicationSettings); Assert.AreEqual("*****@*****.**", user.Identity.Name); Assert.IsTrue(user.Identity.IsAuthenticated); }
public void CannotInvalidateUser() { var userRepository = GetFakeRepositoryInstance(emailIsUnique: true); var culture = new CultureInfo("nl-NL"); var user = new User("*****@*****.**", "Robin van der Knaap", culture, userRepository, DefaultTestApplicationSettings); CustomAssert.ThrowsWithExceptionMessage<BusinessRuleViolationException>( () => user.SetEmail(" ", userRepository), "Email address is required" ); CustomAssert.ThrowsWithExceptionMessage<BusinessRuleViolationException>( () => user.SetEmail("robinskaelenl", userRepository), "'robinskaelenl' is not a valid email address" ); CustomAssert.ThrowsWithExceptionMessage<BusinessRuleViolationException>( () => user.SetCulture(null, DefaultTestApplicationSettings), "Culture is required" ); CustomAssert.ThrowsWithExceptionMessage<BusinessRuleViolationException>( () => user.SetCulture(new CultureInfo("en-GB"), DefaultTestApplicationSettings), "Culture is not accepted" ); CustomAssert.ThrowsWithExceptionMessage<BusinessRuleViolationException>( () => user.DisplayName = " ", "Display name is required" ); }
public void CannotChangeEmailToDuplicateEmail() { var userRepository = GetFakeRepositoryInstance(emailIsUnique: true); var culture = new CultureInfo("nl-NL"); var user = new User("*****@*****.**", "Robin van der Knaap", culture, userRepository, DefaultTestApplicationSettings); var userRepositoryEmailNotUnique = GetFakeRepositoryInstance(emailIsUnique: false); CustomAssert.ThrowsWithExceptionMessage<BusinessRuleViolationException>( () => user.SetEmail("*****@*****.**", userRepositoryEmailNotUnique), "Email must be unique" ); }
public void CannotAddDuplicateRolesToUser() { var userRepository = GetFakeRepositoryInstance(emailIsUnique: true); var culture = new CultureInfo("nl-NL"); var user = new User("*****@*****.**", "Robin van der Knaap", culture, userRepository, DefaultTestApplicationSettings); user.Roles.Add(Role.Administrator); user.Roles.Add(Role.Administrator); Assert.AreEqual(1, user.Roles.Count); }
public void ResetPassword(User user) { OnResetPassword?.Invoke(this, new UserEventArgs(user.Email, user.Login, user.Name, user.Gender)); }