public async Task ManyAccountsWithEmail() { string email = "*****@*****.**"; var args = new UserServiceBuilder(); args.DB.AddRange(new[] { new AccountRow { Email = email, FirstName = "First", LastName = "Last", Id = Guid.NewGuid() }, new AccountRow { Email = email, FirstName = "Other First", LastName = "Other Last", Id = Guid.NewGuid() } }); args.Members.Setup(f => f.FindMembersByEmail(email)).Returns(Task.FromResult <IList <Member> >(new List <Member> { new Member { Email = email, FirstName = "First", LastName = "Last", Id = Guid.NewGuid() } })); args.Logger.Setup(f => f.Warning(LogStrings.MultipleAccountsForEmail, It.IsAny <object[]>())); var svc = args.Build(); var claimsId = new ClaimsIdentity(new[] { new Claim(Constants.ClaimTypes.ExternalProviderUserId, "abcdefg", null, "facebook") }); var result = await svc.SendExternalVerificationCode(claimsId, email); result.Should().Be(ProcessVerificationResult.EmailNotAvailable); }
public async Task UpdateFromMember() { var member = new Member { Id = Guid.NewGuid(), Email = "*****@*****.**", FirstName = "UpdatedFirst", LastName = "UpdatedLast" }; var acct = GetSampleAccount(); acct.MemberId = member.Id; var args = new UserServiceBuilder(); args.DB.Add(acct); args.Members.Setup(f => f.GetMember(member.Id)).Returns(Task.FromResult(member)); var svc = args.Build(); var ctx = new LocalAuthenticationContext { UserName = Username, Password = Password }; args.DB.SaveChangesCount = 0; await svc.AuthenticateLocalAsync(ctx); ctx.AuthenticateResult.IsError.Should().BeFalse(); args.DB.SaveChangesCount.Should().Be(1); acct.Email.Should().Be(member.Email); acct.FirstName.Should().Be(member.FirstName); acct.LastName.Should().Be(member.LastName); }
public async Task MissingMember() { var member = new Member { Id = Guid.NewGuid(), Email = "*****@*****.**", FirstName = "UpdatedFirst", LastName = "UpdatedLast" }; var acct = GetSampleAccount(); acct.MemberId = member.Id; var args = new UserServiceBuilder(); args.DB.Add(acct); args.Logger.Setup(f => f.Error(LogStrings.LinkedMemberNotFound, acct)); args.Members.Setup(f => f.GetMember(member.Id)).Returns(Task.FromResult((Member)null)); var svc = args.Build(); var ctx = new LocalAuthenticationContext { UserName = Username, Password = Password }; args.DB.SaveChangesCount = 0; await svc.AuthenticateLocalAsync(ctx); ctx.AuthenticateResult.IsError.Should().BeTrue(); ctx.AuthenticateResult.ErrorMessage.Should().Be(Strings.AccountLocked); }
public void EmailNull() { var args = new UserServiceBuilder(); var svc = args.Build(); var claimsId = new ClaimsIdentity(new[] { new Claim(Constants.ClaimTypes.ExternalProviderUserId, "abcdefg", null, "facebook") }); Func <Task <ProcessVerificationResult> > act = async() => await svc.SendExternalVerificationCode(claimsId, null); act.ShouldThrow <ArgumentNullException>(); }
public async Task InvalidUser() { var args = new UserServiceBuilder(); var svc = args.Build(); var ctx = new LocalAuthenticationContext { UserName = Username, Password = "******" }; await svc.AuthenticateLocalAsync(ctx); ctx.AuthenticateResult.IsError.Should().BeTrue(); ctx.AuthenticateResult.ErrorMessage.Should().Be(Strings.UserPasswordNotCorrect); }
public async Task InvalidPassword() { var args = new UserServiceBuilder(); var acct = GetSampleAccount(); args.DB.Add(acct); var svc = args.Build(); var ctx = new LocalAuthenticationContext { UserName = Username, Password = "******" }; await svc.AuthenticateLocalAsync(ctx); ctx.AuthenticateResult.IsError.Should().BeTrue(); ctx.AuthenticateResult.ErrorMessage.Should().Be(Strings.UserPasswordNotCorrect); }
public async Task NoMemberNoAccountWithEmail() { string email = "*****@*****.**"; var args = new UserServiceBuilder(); args.Members.Setup(f => f.FindMembersByEmail(email)).Returns(Task.FromResult <IList <Member> >(new List <Member>())); args.Logger.Setup(f => f.Warning(LogStrings.EmailNotFound, It.IsAny <object[]>())); var svc = args.Build(); var claimsId = new ClaimsIdentity(new[] { new Claim(Constants.ClaimTypes.ExternalProviderUserId, "abcdefg", null, "facebook") }); var result = await svc.SendExternalVerificationCode(claimsId, email); result.Should().Be(ProcessVerificationResult.EmailNotAvailable); }
public async Task Locked() { var args = new UserServiceBuilder(); var acct = GetSampleAccount(); acct.Locked = DateTime.Now; acct.LockReason = "Some reason"; args.DB.Add(acct); args.Logger.Setup(f => f.Warning(LogStrings.LockedAccountAttempt, acct)); var svc = args.Build(); var ctx = new LocalAuthenticationContext { UserName = Username, Password = Password }; await svc.AuthenticateLocalAsync(ctx); ctx.AuthenticateResult.IsError.Should().BeTrue(); ctx.AuthenticateResult.ErrorMessage.Should().Be(Strings.AccountLocked); }
public async Task OneMemberNoAccountSendCode() { string email = "*****@*****.**"; var args = new UserServiceBuilder(); args.Members.Setup(f => f.FindMembersByEmail(email)).Returns(Task.FromResult <IList <Member> >(new List <Member> { new Member { Email = email, FirstName = "First", LastName = "Last", Id = Guid.NewGuid() } })); args.Logger.Setup(f => f.Information(LogStrings.SendingVerifyCode, It.IsAny <object[]>())); args.EMails.Setup(f => f.SendEmail(email, Strings.VerifyMessageSubject, It.IsAny <string>(), true)).Returns(Task.FromResult(0)); var svc = args.Build(); var claimsId = new ClaimsIdentity(new[] { new Claim(Constants.ClaimTypes.ExternalProviderUserId, "abcdefg", null, "facebook") }); var result = await svc.SendExternalVerificationCode(claimsId, email); result.Should().Be(ProcessVerificationResult.Success); }
public async Task Login() { var acct = GetSampleAccount(); var args = new UserServiceBuilder(); args.DB.Add(acct); var svc = args.Build(); var ctx = new LocalAuthenticationContext { UserName = Username, Password = Password }; await svc.AuthenticateLocalAsync(ctx); ctx.AuthenticateResult.IsError.Should().BeFalse(); ctx.AuthenticateResult.IsPartialSignIn.Should().BeFalse(); var identity = ctx.AuthenticateResult.User as ClaimsPrincipal; identity.Identity.Name.Should().Be("First Last"); identity.FindFirst(Constants.ClaimTypes.Subject).Value.Should().Be(acct.Id.ToString()); }