public void Core_identity_fields_contain_similar_information() { var exceptions = new List <Exception>(); var identityFields = new[] { CoreFieldRefNames.AssignedTo, CoreFieldRefNames.AuthorizedAs, CoreFieldRefNames.ChangedBy, CoreFieldRefNames.CreatedBy }; foreach (var field in identityFields) { try { var restValue = RestResult.WorkItem[field]?.ToString(); var soapValue = SoapResult.WorkItem[field]?.ToString(); // If there is an identity field, drop the account name that REST returns to us restValue = new IdentityFieldValue(restValue).DisplayName; soapValue = new IdentityFieldValue(soapValue).DisplayName; restValue.ShouldEqual(soapValue, field); } catch (Exception e) { exceptions.Add(e); } } if (exceptions.Any()) { throw new AggregateException(exceptions.EachToUsefulString(), exceptions); } }
public MockTeamFoundationIdentity( IIdentityDescriptor descriptor, string displayName, Guid teamFoundationId, bool isActive = true, IEnumerable <IIdentityDescriptor> members = null, IEnumerable <IIdentityDescriptor> memberOf = null) : base( isActive, teamFoundationId == Guid.Empty ? Guid.NewGuid() : teamFoundationId, isActive ? 0 : 1, memberOf ?? ZeroLengthArrayOfIdentityDescriptor, members ?? ZeroLengthArrayOfIdentityDescriptor) { DisplayName = displayName ?? throw new ArgumentNullException(nameof(displayName)); IsContainer = false; Descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor)); var f = new IdentityFieldValue(DisplayName, Descriptor.Identifier, TeamFoundationId.ToString()); _properties = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { IdentityAttributeTags.SchemaClassName, "User" }, { IdentityAttributeTags.Description, string.Empty }, { IdentityAttributeTags.Domain, f.Domain }, { IdentityAttributeTags.AccountName, f.AccountName }, { IdentityAttributeTags.DistinguishedName, string.Empty }, { IdentityAttributeTags.MailAddress, f.Email }, { IdentityAttributeTags.SpecialType, "Generic" }, { IdentityAttributeTags.IdentityTypeClaim, Descriptor.IdentityType } }; }
public override IReadOnlyDictionary <string, object> Map(IEnumerable <string> values) { if (values == null) { return(Empty); } var identities = _identityManagementService.ReadIdentities(IdentitySearchFactor.DisplayName, values); var retval = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); foreach (var identity in identities) { var c = identity.Value?.Count(); if (c.GetValueOrDefault(0) == 0) { retval.Add(identity.Key, new IdentityFieldValue(identity.Key)); continue; } if (c > 1) { var m = $"Multiple identities found matching '{identity.Key}'. Please specify one of the following identities:{string.Join("\r\n- ", identity.Value)}"; throw new MultipleIdentitiesFoundException(m); } var v = new IdentityFieldValue(identity.Value.FirstOrDefault()); retval.Add(identity.Key, v); } return(retval); }
/// <summary> /// Visits the <see cref="T:System.Linq.Expressions.ConstantExpression" />. /// </summary> /// <param name="node">The expression to visit.</param> /// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns> protected override Expression VisitConstant(ConstantExpression node) { if (!NeedsIdentityMapping) { return(base.VisitConstant(node)); } void Validate(string identity) { var i = new IdentityFieldValue(identity); if (string.IsNullOrEmpty(i.AccountName)) { Trace.TraceWarning( "'{0}' is not a combo-string and may be ambiguous. Use the combo-string to unambiguously refer to an identity.", identity); } } var v = node.Value; if (v is string s) { Validate(s); } else if (v is IEnumerable <string> sv) { foreach (var s1 in sv) { Validate(s1); } } else { Trace.TraceWarning("Unrecognized value in identity field. Type: {0}, Value: {1}", node.Type, node.Value); } return(base.VisitConstant(node)); }
/// <inheritdoc /> public override void When() { Result = new IdentityFieldValue(DisplayName); }