示例#1
0
        public void BuiltClaimsContainUserCustomProperties()
        {
            const string userAccountName   = "user";
            const string organizationName  = "organization";
            const string organizationValue = "Affecto";
            const string emailName         = "email";
            const string emailValue        = "*****@*****.**";

            ICustomProperty organizationProperty = CreateCustomPropertyMock(organizationName, organizationValue);
            ICustomProperty emailProperty        = CreateCustomPropertyMock(emailName, emailValue);
            IUser           user = Substitute.For <IUser>();

            user.CustomProperties.Returns(new List <ICustomProperty> {
                organizationProperty, organizationProperty, emailProperty
            });
            userService.GetUser(userAccountName, accountType).Returns(user);

            ClaimsIdentity identity = sut.Build("type", userAccountName, accountType);

            List <Claim> organizationClaims = identity.Claims.Where(c => c.Type == ClaimTypePrefix.CustomProperty + organizationName).ToList();

            Assert.AreEqual(2, organizationClaims.Count);
            Assert.IsTrue(organizationClaims.All(c => c.Value.Equals(organizationValue)));

            List <Claim> emailClaims = identity.Claims.Where(c => c.Type == ClaimTypePrefix.CustomProperty + emailName).ToList();

            Assert.AreEqual(1, emailClaims.Count);
            Assert.IsTrue(emailClaims.All(c => c.Value.Equals(emailValue)));
        }
示例#2
0
        private static ICustomProperty CreateCustomPropertyMock(string name, string value)
        {
            ICustomProperty customProperty = Substitute.For <ICustomProperty>();

            customProperty.Name.Returns(name);
            customProperty.Value.Returns(value);
            return(customProperty);
        }
示例#3
0
        protected void DrawPropertyWithTitleLabel(ICustomProperty property)
        {
            if (isRefreshing)
            {
                return;
            }

            //"property" might be null. Thus, we can't convert to method group.
            //ReSharper disable once ConvertClosureToMethodGroup
            RefreshIfNeededOrDraw(property, () => property.DrawWithTitleLabel());
        }
示例#4
0
 private void RefreshIfNeededOrDraw(ICustomProperty property, UnityAction drawAction)
 {
     if (property == null || property.NeedRefresh())
     {
         Initialize();
         isRefreshing = true;
         Repaint();
     }
     else
     {
         drawAction();
     }
 }
示例#5
0
        public void GetUser()
        {
            Guid  userId = Guid.NewGuid();
            IUser user   = Substitute.For <IUser>();

            user.IsDisabled.Returns(true);
            user.Name.Returns("DisplayName");
            identityManagementService.GetUser(userId).Returns(user);

            ICustomProperty customProperty1 = Substitute.For <ICustomProperty>();

            customProperty1.Name.Returns("prop1");
            customProperty1.Value.Returns("value1");
            ICustomProperty customProperty2 = Substitute.For <ICustomProperty>();

            customProperty2.Name.Returns("prop2");
            customProperty2.Value.Returns((string)null);

            user.CustomProperties.Returns(new List <ICustomProperty> {
                customProperty1, customProperty2
            });

            OkNegotiatedContentResult <User> response = sut.GetUser(userId) as OkNegotiatedContentResult <User>;

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Content);
            Assert.IsTrue(response.Content.IsDisabled);
            Assert.AreEqual("DisplayName", response.Content.Name);

            Assert.AreEqual(2, response.Content.CustomProperties.Count);

            CustomProperty customProperty = response.Content.CustomProperties.SingleOrDefault(c => c.Name == "prop1");

            Assert.IsNotNull(customProperty);
            Assert.AreEqual("value1", customProperty.Value);

            customProperty = response.Content.CustomProperties.SingleOrDefault(c => c.Name == "prop2");
            Assert.IsNotNull(customProperty);
            Assert.IsNull(customProperty.Value);
        }