public Task <TUser> FindByNameAsync(string userName) { if (userName == null) { throw new ArgumentNullException("userName"); } return(_documentSession.LoadAsync <TUser>(RavenUser.GenerateKey(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); } } }