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);
        }
        public void Add_User_Attribute()
        {
            // Prepare
            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
            };
            AddUser(newUser);
            User addedUser = testDBContext.Users.Find(1);
            UserAttribute userAttribute = new UserAttribute()
            {
                UserId = addedUser.UserId,
                Key = "Key1",
                Value = "Value1"
            };

            // Perform
            IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork);
            UserAttribute addedUserAttribute = repository.AddUserAttribute(userAttribute); // Invalid user id passed

            // Check is a valid user attribute is returned
            Assert.IsNotNull(addedUserAttribute);

            // Check if the count of tracked objects in the data context is 1
            Assert.IsTrue(testDBContext.UserAttributes.Local.Count == 1);

            // Check if the tracked object is the same one as the added user attribute
            Assert.AreEqual(testDBContext.UserAttributes.Local[0].Key, userAttribute.Key);

            // Check the entity state
            Assert.AreEqual(testDBContext.GetEntityState(addedUserAttribute), EntityState.Added);
        }
Ejemplo n.º 3
0
 public UserAttribute AddUserAttribute(UserAttribute attribute)
 {
     Check.IsNotNull<UserAttribute>(attribute, "attribute");
     return Context.UserAttributes.Add(attribute);
 }