Ejemplo n.º 1
0
        public void SetPasswordHashAsyncTests()
        {
            var target = Target();

            UtilsLol.AssertThrows(() => target.SetPasswordHashAsync(null, null).Wait());
            UtilsLol.AssertThrows(() => target.SetPasswordHashAsync(null, "").Wait());
            UtilsLol.AssertThrows(() => target.SetPasswordHashAsync(null, "  ").Wait());
            UtilsLol.AssertThrows(() => target.SetPasswordHashAsync(null, "derp").Wait());

            var user = new AzureTableUser
            {
                Id       = "derpHash",
                UserName = "******"
            };

            UtilsLol.AssertThrows(() => target.SetPasswordHashAsync(user, null).Wait());
            UtilsLol.AssertThrows(() => target.SetPasswordHashAsync(user, "").Wait());
            UtilsLol.AssertThrows(() => target.SetPasswordHashAsync(user, "  ").Wait());
            target.CreateAsync(user).Wait();
            UtilsLol.AssertThrows(() => target.SetPasswordHashAsync(user, null).Wait());
            UtilsLol.AssertThrows(() => target.SetPasswordHashAsync(user, "").Wait());
            UtilsLol.AssertThrows(() => target.SetPasswordHashAsync(user, "  ").Wait());

            Assert.IsNull(target.GetPasswordHashAsync(user).Result);
            // eh, oh well.
            var hash = "stupid or liar";

            target.SetPasswordHashAsync(user, hash).Wait();
            Assert.AreEqual(hash, target.GetPasswordHashAsync(user).Result);
        }
Ejemplo n.º 2
0
        public void RemoveClaimAsyncTests()
        {
            var target = Target();

            UtilsLol.AssertThrows(() => target.RemoveClaimAsync(null, null).Wait());

            target.CreateAsync(_user).Wait();

            UtilsLol.AssertThrows(() => target.RemoveClaimAsync(_user, null).Wait());

            target.AddClaimAsync(_user, _claim1).Wait();
            target.AddClaimAsync(_user, _claim2).Wait();
            var backAgain = target.GetClaimsAsync(_user).Result;

            Assert.AreEqual(2, backAgain.Count);
            Assert.AreEqual(2, backAgain.Count);
            AssertClaims(backAgain.ToArray());

            target.RemoveClaimAsync(_user, _claim2).Wait();
            var first = target.GetClaimsAsync(_user).Result.Single();

            Assert.IsTrue(AreEquivalent(_claim1, first));

            target.RemoveClaimAsync(_user, _claim1).Wait();
            Assert.AreEqual(0, target.GetClaimsAsync(_user).Result.Count);
        }
        public void RemoveLoginAsyncTests()
        {
            var target = Target();

            UtilsLol.AssertThrows(() => target.RemoveLoginAsync(null, null).Wait());

            target.CreateAsync(_user).Wait();

            UtilsLol.AssertThrows(() => target.RemoveLoginAsync(_user, null).Wait());

            target.AddLoginAsync(_user, _login1).Wait();
            target.AddLoginAsync(_user, _login2).Wait();
            var backAgain = target.GetLoginsAsync(_user).Result;

            Assert.AreEqual(2, backAgain.Count);
            Assert.IsTrue(backAgain.Any(x => x.LoginProvider == _login1.LoginProvider && x.ProviderKey == _login1.ProviderKey));
            Assert.IsTrue(backAgain.Any(x => x.LoginProvider == _login2.LoginProvider && x.ProviderKey == _login2.ProviderKey));

            target.RemoveLoginAsync(_user, _login1).Wait();

            backAgain = target.GetLoginsAsync(_user).Result;
            Assert.AreEqual(1, backAgain.Count);
            Assert.IsTrue(backAgain.First().LoginProvider == _login2.LoginProvider && backAgain.First().ProviderKey == _login2.ProviderKey);

            target.RemoveLoginAsync(_user, _login2).Wait();
            backAgain = target.GetLoginsAsync(_user).Result;
            Assert.AreEqual(0, backAgain.Count);
        }
Ejemplo n.º 4
0
        public void AddClaimAsyncTests()
        {
            var target = Target();

            UtilsLol.AssertThrows(() => target.AddClaimAsync(null, null).Wait());

            UtilsLol.AssertThrows(() => target.AddClaimAsync(_user, null).Wait());
            target.AddClaimAsync(_user, _claim1).Wait();
            var returned = target.GetClaimsAsync(_user).Result.Single();

            Assert.IsTrue(AreEquivalent(returned, _claim1));
            target.AddClaimAsync(_user, _claim2).Wait();
            var backAgain = target.GetClaimsAsync(_user).Result;

            Assert.AreEqual(2, backAgain.Count);
            AssertClaims(backAgain.ToArray());
        }
Ejemplo n.º 5
0
        public void DeleteAsyncTest()
        {
            var target = Target();
            var user   = new AzureTableUser
            {
                Id       = "foo",
                UserName = "******"
            };

            UtilsLol.AssertThrows(() => target.DeleteAsync(new AzureTableUser
            {
                UserName = "******"
            }).Wait());
            try
            {
                target.DeleteAsync(null).Wait();
                Assert.Fail("DeleteAsync didn't throw on null");
            }
            catch (AggregateException ex)
            {
                Assert.IsTrue(ex.InnerException is ArgumentNullException);
            }

            target.CreateAsync(user).Wait();
            Assert.IsNotNull(target.FindByIdAsync(user.Id).Result); // sanity

            target.DeleteAsync(user).Wait();

            Assert.IsNull(target.FindByIdAsync(user.Id).Result);

            target.DeleteAsync(user).Wait();

            target.Dispose();

            try
            {
                target.DeleteAsync(user).Wait();
                Assert.Fail("deleteAsync doesn't throw when disposed");
            }
            catch (AggregateException ex)
            {
                Assert.IsTrue(ex.InnerException is ObjectDisposedException);
            }
        }
        public void UpdateAsyncTest()
        {
            var target = Target();
            var role   = new AzureTableRole
            {
                Id   = "foo",
                Name = "bar"
            };

            UtilsLol.AssertThrows(() => target.UpdateAsync(
                                      new AzureTableRole
            {
                Name = "bar"
            }).Wait());

            UtilsLol.AssertThrows(() => target.UpdateAsync(null).Wait());

            target.CreateAsync(role).Wait();
            Assert.IsNotNull(target.FindByIdAsync(role.Id).Result); // sanity

            var newRole = new AzureTableRole
            {
                Id   = "foo",
                Name = "derp"
            };

            target.UpdateAsync(newRole).Wait();

            Assert.AreEqual(newRole.Name, target.FindByIdAsync(role.Id).Result.Name);

            target.Dispose();

            try
            {
                target.UpdateAsync(newRole).Wait();
                Assert.Fail("FindByNameAsync doesn't throw when disposed");
            }
            catch (AggregateException ex)
            {
                Assert.IsTrue(ex.InnerException is ObjectDisposedException);
            }
        }
        public void FindAsyncTests()
        {
            var target = Target();

            UtilsLol.AssertThrows(() => target.FindAsync(null).Result);
            Assert.IsNull(target.FindAsync(_login1).Result);

            target.CreateAsync(_user).Wait();

            Assert.IsNull(target.FindAsync(_login1).Result);
            Assert.IsNull(target.FindAsync(_login2).Result);
            target.AddLoginAsync(_user, _login1).Wait();
            Assert.IsNull(target.FindAsync(_login2).Result);
            target.AddLoginAsync(_user, _login2).Wait();
            var backAgain = target.FindAsync(_login2).Result;

            Assert.IsTrue(backAgain.UserName == _user.UserName);
            backAgain = target.FindAsync(_login1).Result;
            Assert.IsTrue(backAgain.UserName == _user.UserName);
        }
Ejemplo n.º 8
0
        public void HasPasswordAsyncTests()
        {
            var target = Target();

            UtilsLol.AssertThrows(() => target.HasPasswordAsync(null).Result, typeof(ArgumentNullException));

            var user = new AzureTableUser
            {
                Id       = "derp",
                UserName = "******"
            };

            Assert.IsFalse(target.HasPasswordAsync(user).Result);
            target.CreateAsync(user);
            Assert.IsFalse(target.HasPasswordAsync(user).Result);

            var hash = "stupid or liar";

            target.SetPasswordHashAsync(user, hash).Wait();
            Assert.IsTrue(target.HasPasswordAsync(user).Result);
        }
        public void DeleteAsyncTest()
        {
            var target = Target();
            var role   = new AzureTableRole
            {
                Id   = "foo",
                Name = "bar"
            };

            UtilsLol.AssertThrows(() => target.DeleteAsync(
                                      new AzureTableRole
            {
                Name = "bar"
            }).Wait());
            UtilsLol.AssertThrows(() => target.DeleteAsync(null).Wait());

            target.CreateAsync(role).Wait();
            Assert.IsNotNull(target.FindByIdAsync(role.Id).Result); // sanity

            target.DeleteAsync(role).Wait();

            Assert.IsNull(target.FindByIdAsync(role.Id).Result);

            // am currently swallowing exceptions if attempting to delete something not there
            target.DeleteAsync(role).Wait();

            target.Dispose();

            try
            {
                target.DeleteAsync(role).Wait();
                Assert.Fail("deleteAsync doesn't throw when disposed");
            }
            catch (AggregateException ex)
            {
                Assert.IsTrue(ex.InnerException is ObjectDisposedException);
            }
        }