public void UserLookup_WhenTargetUserDoesNotExist_ShouldReturnNull()
        {
            AsyncContext.Run(async() =>
            {
                var admin = await User.LoginAsync(SyncTestHelpers.AdminCredentials(), SyncTestHelpers.AuthServerUri);

                var lookupResponse = await admin.RetrieveInfoForUserAsync(Credentials.Provider.UsernamePassword, "something");
                Assert.That(lookupResponse, Is.Null);
            });
        }
        public void UserLookup_WhenTargetUserIsSelf_ShouldReturnResponse()
        {
            AsyncContext.Run(async() =>
            {
                var admin = await User.LoginAsync(SyncTestHelpers.AdminCredentials(), SyncTestHelpers.AuthServerUri);

                var lookupResponse = await admin.RetrieveInfoForUserAsync(Credentials.Provider.UsernamePassword, Constants.AdminUsername);

                Assert.That(lookupResponse.Identity, Is.EqualTo(admin.Identity));
                Assert.That(lookupResponse.IsAdmin, Is.True);
                Assert.That(lookupResponse.Provider, Is.EqualTo(Credentials.Provider.UsernamePassword));
                Assert.That(lookupResponse.ProviderUserIdentity, Is.EqualTo(Constants.AdminUsername));
            });
        }
        public void UserLookup_WhenTargetUserExists_ShouldReturnResponse()
        {
            AsyncContext.Run(async() =>
            {
                var admin = await User.LoginAsync(SyncTestHelpers.AdminCredentials(), SyncTestHelpers.AuthServerUri);

                var aliceUsername = Guid.NewGuid().ToString();
                var alice         = await User.LoginAsync(Credentials.UsernamePassword(aliceUsername, "a", createUser: true), SyncTestHelpers.AuthServerUri);

                var lookupResponse = await admin.RetrieveInfoForUserAsync(Credentials.Provider.UsernamePassword, aliceUsername);

                Assert.That(lookupResponse.Identity, Is.EqualTo(alice.Identity));
                Assert.That(lookupResponse.IsAdmin, Is.False);
                Assert.That(lookupResponse.Provider, Is.EqualTo(Credentials.Provider.UsernamePassword));
                Assert.That(lookupResponse.ProviderUserIdentity, Is.EqualTo(aliceUsername));
            });
        }
        public void UserLookup_WhenTargetUserIsSelf_ShouldReturnResponse()
        {
            SyncTestHelpers.RequiresRos();

            AsyncContext.Run(async() =>
            {
                var admin = await User.LoginAsync(SyncTestHelpers.AdminCredentials(), SyncTestHelpers.AuthServerUri);

                var lookupResponse = await admin.RetrieveInfoForUserAsync(Credentials.Provider.UsernamePassword, Constants.AdminUsername);

                Assert.That(lookupResponse.Identity, Is.EqualTo(admin.Identity));
                Assert.That(lookupResponse.IsAdmin, Is.True);
                Assert.That(lookupResponse.Accounts, Is.Not.Empty);
                var passwordAccount = lookupResponse.Accounts.SingleOrDefault(a => a.Provider == Credentials.Provider.UsernamePassword);

                Assert.That(passwordAccount, Is.Not.Null);
                Assert.That(passwordAccount.ProviderUserIdentity, Is.EqualTo(Constants.AdminUsername));
            });
        }
        public void AdminChangePasswordTest()
        {
            AsyncContext.Run(async() =>
            {
                var userId      = Guid.NewGuid().ToString();
                var credentials = Credentials.UsernamePassword(userId, OriginalPassword, createUser: true);
                var user        = await User.LoginAsync(credentials, SyncTestHelpers.AuthServerUri);
                var identity    = user.Identity;
                user.LogOut();

                var admin = await User.LoginAsync(SyncTestHelpers.AdminCredentials(), SyncTestHelpers.AuthServerUri);
                await admin.ChangePasswordAsync(identity, NewPassword);

                admin.LogOut();

                Assert.That(async() => await admin.ChangePasswordAsync(identity, "c"), Throws.TypeOf <InvalidOperationException>());

                await TestNewPassword(userId);
            });
        }
        public void UserLookup_WhenTargetUserExists_ShouldReturnResponse()
        {
            SyncTestHelpers.RequiresRos();

            AsyncContext.Run(async() =>
            {
                var admin = await User.LoginAsync(SyncTestHelpers.AdminCredentials(), SyncTestHelpers.AuthServerUri);

                var aliceUsername = Guid.NewGuid().ToString();
                var alice         = await User.LoginAsync(Credentials.UsernamePassword(aliceUsername, "a", createUser: true), SyncTestHelpers.AuthServerUri);

                var lookupResponse = await admin.RetrieveInfoForUserAsync(Credentials.Provider.UsernamePassword, aliceUsername);

                Assert.That(lookupResponse.Identity, Is.EqualTo(alice.Identity));
                Assert.That(lookupResponse.IsAdmin, Is.False);

                Assert.That(lookupResponse.Accounts, Is.Not.Empty);
                var passwordAccount = lookupResponse.Accounts.SingleOrDefault(a => a.Provider == Credentials.Provider.UsernamePassword);

                Assert.That(passwordAccount, Is.Not.Null);
                Assert.That(passwordAccount.ProviderUserIdentity, Is.EqualTo(aliceUsername));
            });
        }