public async Task RemoveLoginAsync(TUser user, UserLoginInfo login) { if (user == null) { throw new ArgumentNullException("user"); } if (login == null) { throw new ArgumentNullException("login"); } string keyToLookFor = RavenUserLogin.GenerateKey(login.LoginProvider, login.ProviderKey); RavenUserLogin ravenUserLogin = await _documentSession.LoadAsync <RavenUserLogin>(keyToLookFor).ConfigureAwait(false); if (ravenUserLogin != null) { _documentSession.Delete(ravenUserLogin); } RavenUserLogin userLogin = user.Logins.FirstOrDefault(lgn => lgn.Id.Equals(keyToLookFor, StringComparison.InvariantCultureIgnoreCase)); if (userLogin != null) { user.RemoveLogin(userLogin); } }
public async Task AddLoginAsync(TUser user, UserLoginInfo login) { if (user == null) { throw new ArgumentNullException("user"); } if (login == null) { throw new ArgumentNullException("login"); } RavenUserLogin ravenUserLogin = new RavenUserLogin(user.Id, login); await _documentSession.StoreAsync(ravenUserLogin).ConfigureAwait(false); user.AddLogin(ravenUserLogin); }
public async Task <TUser> FindAsync(UserLoginInfo login) { if (login == null) { throw new ArgumentNullException("login"); } string keyToLookFor = RavenUserLogin.GenerateKey(login.LoginProvider, login.ProviderKey); RavenUserLogin ravenUserLogin = await _documentSession .Include <RavenUserLogin, TUser>(usrLogin => usrLogin.UserId) .LoadAsync(keyToLookFor) .ConfigureAwait(false); return((ravenUserLogin != null) ? await _documentSession.LoadAsync <TUser>(ravenUserLogin.UserId).ConfigureAwait(false) : default(TUser)); }
public async Task FindAsync_Should_Find_The_User_If_Login_Exists() { const string userName = "******"; const string loginProvider = "Twitter"; const string providerKey = "12345678"; using (IDocumentStore store = CreateEmbeddableStore()) { // Arrange using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; IUserLoginStore <RavenUser, string> userLoginStore = new RavenUserStore <RavenUser>(ses); RavenUser user = new RavenUser(userName); RavenUserLogin userLogin = new RavenUserLogin(user.Id, new UserLoginInfo(loginProvider, providerKey)); user.AddLogin(userLogin); await ses.StoreAsync(user); await ses.StoreAsync(userLogin); await ses.SaveChangesAsync(); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; IUserLoginStore <RavenUser, string> userLoginStore = new RavenUserStore <RavenUser>(ses); // Act UserLoginInfo loginInfo = new UserLoginInfo(loginProvider, providerKey); RavenUser foundUser = await userLoginStore.FindAsync(loginInfo); // Assert Assert.NotNull(foundUser); Assert.Equal(userName, foundUser.UserName); } } }
public async Task Add_Should_Add_New_Login_If_User_Exists() { const string userName = "******"; const string loginProvider = "Twitter"; const string providerKey = "12345678"; using (IDocumentStore store = CreateEmbeddableStore()) { using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; IUserLoginStore <RavenUser, string> userLoginStore = new RavenUserStore <RavenUser>(ses); RavenUser user = new RavenUser(userName); await ses.StoreAsync(user); await ses.SaveChangesAsync(); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; IUserLoginStore <RavenUser, string> userLoginStore = new RavenUserStore <RavenUser>(ses); RavenUser user = await ses.LoadAsync <RavenUser>(RavenUser.GenerateKey(userName)); // Act UserLoginInfo loginToAdd = new UserLoginInfo(loginProvider, providerKey); await userLoginStore.AddLoginAsync(user, loginToAdd); await ses.SaveChangesAsync(); // Assert RavenUserLogin foundLogin = await ses.LoadAsync <RavenUserLogin>(RavenUserLogin.GenerateKey(loginProvider, providerKey)); Assert.Equal(1, user.Logins.Count()); Assert.NotNull(foundLogin); } } }