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); }
public void CreateAsyncTest() { // wow, such similar, very copypasta var target = Target(); var user = new AzureTableUser { //ASP.NET identity doesn't set the ID on a new user, adding this into the provider //Id = "foo", UserName = "******" }; try { target.CreateAsync(null).Wait(); Assert.Fail("CreateAsync didn't throw on null"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentNullException); } target.CreateAsync(user).Wait(); Assert.IsTrue(!string.IsNullOrWhiteSpace(user.ETag)); try { target.CreateAsync(user).Wait(); Assert.Fail("CreateAsync created the same user twice"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is AzureTableUserException); } var backAgain = target.FindByIdAsync(user.Id).Result; Assert.AreEqual(user.UserName, backAgain.UserName); target.Dispose(); try { target.CreateAsync(user).Wait(); Assert.Fail("CreateAsync doesn't throw when disposed"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ObjectDisposedException); } }
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 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 user = new AzureTableUser { Id = "foo", UserName = "******" }; UtilsLol.AssertThrows(() => target.UpdateAsync(new AzureTableUser { UserName = "******" }).Wait()); UtilsLol.AssertThrows(() => target.UpdateAsync(null).Wait()); target.CreateAsync(user).Wait(); Assert.IsNotNull(target.FindByIdAsync(user.Id).Result); // sanity var newUser = new AzureTableUser { Id = "foo", UserName = "******" }; target.UpdateAsync(newUser).Wait(); Assert.AreEqual(newUser.UserName, target.FindByIdAsync(user.Id).Result.UserName); target.Dispose(); try { target.UpdateAsync(newUser).Wait(); Assert.Fail("FindByNameAsync doesn't throw when disposed"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ObjectDisposedException); } }
public void FindByNameAsyncTest() { var userName = "******"; var target = Target(); var user = new AzureTableUser { Id = "foo", UserName = userName }; try { target.FindByNameAsync(null).Wait(); Assert.Fail("FindByNameAsync didn't throw on null"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentException); } try { target.FindByNameAsync("").Wait(); Assert.Fail("FindByNameAsync didn't throw on empty"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentException); } try { target.FindByNameAsync(" ").Wait(); Assert.Fail("FindByNameAsync didn't throw on whitespace"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentException); } target.CreateAsync(user).Wait(); var backagain = target.FindByNameAsync(user.UserName).Result; Assert.IsNotNull(backagain); // sanity //FindByName should be CASE INSENSITIVE! // The current storage emulator has a BUG that prevents this part of the test from working :/ //var insensitive = target.FindByNameAsync(userName.ToLowerInvariant()).Result; //Assert.IsNotNull(insensitive); //insensitive = target.FindByNameAsync(userName.ToUpperInvariant()).Result; //Assert.IsNotNull(insensitive); //insensitive = target.FindByNameAsync(userName).Result; //Assert.IsNotNull(insensitive); target.DeleteAsync(user).Wait(); Assert.IsNull(target.FindByNameAsync(user.Id).Result); target.Dispose(); try { target.FindByNameAsync(user.Id).Wait(); Assert.Fail("FindByNameAsync doesn't throw when disposed"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ObjectDisposedException); } }
public void FindByIdAsyncTest() { // holy crap... this entire class is copypasta var target = Target(); try { target.FindByIdAsync(null).Wait(); Assert.Fail("FindByIdAsync didn't throw on null"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentException); } try { target.FindByIdAsync("").Wait(); Assert.Fail("FindByIdAsync didn't throw on empty"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentException); } try { target.FindByIdAsync(" ").Wait(); Assert.Fail("FindByIdAsync didn't throw on whitespace"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentException); } var user = new AzureTableUser { Id = "foo", UserName = "******" }; target.CreateAsync(user).Wait(); Assert.IsNotNull(target.FindByIdAsync(user.Id).Result); // sanity target.DeleteAsync(user).Wait(); Assert.IsNull(target.FindByIdAsync(user.Id).Result); target.Dispose(); try { target.FindByIdAsync(user.Id).Wait(); Assert.Fail("FindByIdAsync doesn't throw when disposed"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ObjectDisposedException); } }
public void GetRolesAsyncTest() { var target = Target(); var user = new AzureTableUser { Id = "foo", UserName = "******" }; var role1 = "derp"; var role2 = "herp"; try { target.GetRolesAsync(null).Wait(); Assert.Fail("GetRolesAsync didn't throw on null"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentNullException); } var result = target.GetRolesAsync(user).Result; Assert.AreEqual(0, result.Count); target.AddToRoleAsync(user, role1).Wait(); target.AddToRoleAsync(user, role2).Wait(); result = target.GetRolesAsync(user).Result; Assert.AreEqual(2, result.Count); Assert.IsTrue(result.All(x => x.Equals(role1) || x.Equals(role2))); target.Dispose(); try { target.GetRolesAsync(user).Wait(); Assert.Fail("GetRolesAsync doesn't throw when disposed"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ObjectDisposedException); } }
public void RemoveFromRoleAsyncTest() { var target = Target(); var user = new AzureTableUser { Id = "foo", UserName = "******" }; var role1 = "derp"; var role2 = "herp"; try { target.RemoveFromRoleAsync(null, null).Wait(); Assert.Fail("RemoveFromRoleAsync didn't throw on null"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentNullException); } try { target.RemoveFromRoleAsync(null, role1).Wait(); Assert.Fail("RemoveFromRoleAsync didn't throw on null"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentNullException); } try { target.RemoveFromRoleAsync(user, null).Wait(); Assert.Fail("RemoveFromRoleAsync didn't throw on null"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentNullException); } try { target.RemoveFromRoleAsync(user, "").Wait(); Assert.Fail("RemoveFromRoleAsync didn't throw on empty"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentException); } try { target.RemoveFromRoleAsync(user, " ").Wait(); Assert.Fail("RemoveFromRoleAsync didn't throw on whitespace"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentException); } target.RemoveFromRoleAsync(user, role1).Wait(); target.AddToRoleAsync(user, role1).Wait(); target.AddToRoleAsync(user, role2).Wait(); Assert.IsTrue(target.IsInRoleAsync(user, role1).Result); Assert.IsTrue(target.IsInRoleAsync(user, role2).Result); target.RemoveFromRoleAsync(user, role1).Wait(); Assert.IsFalse(target.IsInRoleAsync(user, role1).Result); Assert.IsTrue(target.IsInRoleAsync(user, role2).Result); target.RemoveFromRoleAsync(user, role2).Wait(); Assert.IsFalse(target.IsInRoleAsync(user, role1).Result); Assert.IsFalse(target.IsInRoleAsync(user, role2).Result); target.Dispose(); try { target.RemoveFromRoleAsync(user, role1).Wait(); Assert.Fail("GetRolesAsync doesn't throw when disposed"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ObjectDisposedException); } }
public void AddToRoleAsyncTest() { var target = Target(); var user = new AzureTableUser { Id = "fooRole", UserName = "******" }; var role = "derp"; try { target.AddToRoleAsync(null, null).Wait(); Assert.Fail("CreateAsync didn't throw on null"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentNullException); } try { target.AddToRoleAsync(null, role).Wait(); Assert.Fail("CreateAsync didn't throw on null"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentNullException); } try { target.AddToRoleAsync(user, null).Wait(); Assert.Fail("CreateAsync didn't throw on null"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentNullException); } try { target.AddToRoleAsync(user, "").Wait(); Assert.Fail("CreateAsync didn't throw on empty"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentException); } try { target.AddToRoleAsync(user, " ").Wait(); Assert.Fail("CreateAsync didn't throw on whitespace"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ArgumentException); } target.AddToRoleAsync(user, role).Wait(); target.AddToRoleAsync(user, role).Wait(); var roles = target.GetRolesAsync(user).Result; Assert.AreEqual(1, roles.Count); Assert.AreEqual(role, roles[0]); target.Dispose(); try { target.AddToRoleAsync(user, role).Wait(); Assert.Fail("CreateAsync doesn't throw when disposed"); } catch (AggregateException ex) { Assert.IsTrue(ex.InnerException is ObjectDisposedException); } }