public void Return_Empty_UserAttributes_For_InValid_UserId() { // Perform IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork); IEnumerable<UserAttribute> userAttributes = repository.GetUserAttributesByUserId(-1); // Invalid user id passed // Check is the count is zero Assert.AreEqual(userAttributes.Count(), 0); }
public void Get_User_Attributes_For_Valid_User() { // Prepare UserAttribute userAttribute1 = new UserAttribute() { Key = "Key1", Value = "Value1" }; UserAttribute userAttribute2 = new UserAttribute() { Key = "Key2", Value = "Value2" }; User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true, UserAttributes = new List<UserAttribute>() { userAttribute1, userAttribute2 } }; AddUser(newUser); User addedUser = testDBContext.Users.Find(1); // Perform IUserRepository repository = new UserRepository(testDBContext); IEnumerable<UserAttribute> attributes = repository.GetUserAttributesByUserId(addedUser.UserId); // Check if a valid collection of user attributes is returned Assert.IsNotNull(attributes); // Check if the count of attributes is 2, since we added 2 attributes in the preparation code Assert.AreEqual(attributes.Count(), 2); // Check if attribute 1 is returned Assert.AreEqual(attributes.Count<UserAttribute>(ua => ua.Key.Equals(userAttribute1.Key)), 1); // Check is attribute 2 is returned Assert.AreEqual(attributes.Count<UserAttribute>(ua => ua.Key.Equals(userAttribute2.Key)), 1); }