public void SetCustomAttributes() { TestCustomAttribute dbCustomAttr = Helpers.GetCustomAttribute(TestContext); string strEx = string.Empty; Models.User existingUser = null; string strUserLogin = dbCustomAttr.Login; try { var usersClient = oktaClient.GetUsersClient(); existingUser = usersClient.GetByUsername(strUserLogin); if (existingUser != null) { List <string> unmappedProperties = existingUser.Profile.GetUnmappedPropertyNames(); foreach (string unmappedProperty in unmappedProperties) { string strPropertyValue = existingUser.Profile.GetProperty(unmappedProperty); } } object oValue = string.Empty; if (dbCustomAttr.MultiValued) //we assume it's an array of strings { if (existingUser.Profile.ContainsProperty(dbCustomAttr.Name)) { string[] arAttrVal = OktaJsonConverter.GetStringArray(existingUser.Profile.GetProperty(dbCustomAttr.Name)); List <string> lstVal = new List <string>(arAttrVal); string[] arValues = dbCustomAttr.Value.Split(','); List <string> lstNewVal = new List <string>(arValues); lstVal.AddRange(lstNewVal); oValue = lstVal.ToArray(); } else { oValue = string.Format("[{0}]", dbCustomAttr.Value); } } else { oValue = dbCustomAttr.Value; } string s = existingUser.Profile.GetProperty(dbCustomAttr.Name); existingUser.Profile.SetProperty(dbCustomAttr.Name, oValue); usersClient.Update(existingUser); //} } catch (OktaException e) { strEx = string.Format("Error Code: {0} - Summary: {1} - Message: {2}", e.ErrorCode, e.ErrorSummary, e.Message); } }
internal static TestCustomAttribute GetCustomAttribute(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext context) { TestCustomAttribute attr = new TestCustomAttribute { Login = Convert.ToString(context.DataRow["Login"]), Name = Convert.ToString(context.DataRow["AttributeName"]), Value = Convert.ToString(context.DataRow["AttributeValue"]), }; if (context.DataRow["MultiValued"] != System.DBNull.Value) { attr.MultiValued = Convert.ToBoolean(context.DataRow["MultiValued"]); } return(attr); }