public void returns_given_strings_as_array() { var attributes = new AttributesToFetch("attr1", "attr2", "attr3"); var names = attributes.GetNames(); Assert.Equal(new[] { "attr1", "attr2", "attr3" }, names); }
public void returns_null_if_no_names_passed___required_for_underlying_fim2010client_mechanisms__must_be_null_not_empty_collection() { var attributes = new AttributesToFetch(); var names = attributes.GetNames(); Assert.Null(names); }
public void does_not_append_duplicate_names() { var attributes = new AttributesToFetch("attr1", "attr2"); var newAttributes = attributes.AppendAttribute("attr2"); var names = newAttributes.GetNames(); Assert.Equal(new[] { "attr1", "attr2" }, names); }
public void does_not_modify_original_instance() { var attributes = new AttributesToFetch("attr1"); attributes.AppendAttribute("attr2"); var names = attributes.GetNames(); Assert.Equal(new[] { "attr1" }, names); }
public void can_append_names_to_empty_names_list() { var attributes = new AttributesToFetch(); var newAttributes = attributes.AppendAttribute("attr1"); var names = newAttributes.GetNames(); Assert.Equal(new[] { "attr1" }, names); }
public void appends_new_name_to_the_list_and_creates_new_instance() { var attributes = new AttributesToFetch("attr1"); var newAttributes = attributes.AppendAttribute("attr2"); var names = newAttributes.GetNames(); Assert.Equal(new[] { "attr1", "attr2" }, names); }
public void ExecuteQuery() { var requiredAttributes = new List<SelectableAttribute>(); // attributes selection is possible only when directly querying for type selected in the list // otherwise there is no smart/easy way to tell if queried object contains any of currently displayed attributes if (querying_selected_type()) { if (CurrentAttributes.Any(x => x.IsSelected)) { requiredAttributes = CurrentAttributes.Where(x => x.IsSelected).ToList(); } else { requiredAttributes = CurrentAttributes.ToList(); } if (requiredAttributes.None(x => x.Attribute.Name == RmResource.AttributeNames.ObjectID.Name)) { requiredAttributes.Add(CurrentAttributes.Single(x => x.Attribute.Name == RmResource.AttributeNames.ObjectID.Name)); } } // empty array if querying for other type than selected => all attributes will be fetched var attributesToFetch = new AttributesToFetch(requiredAttributes.Select(x => x.Attribute.Name).ToArray()); string query = XPath.Replace(Environment.NewLine, string.Empty); RmResource[] results = _parent.LongRunningOperation(_parent.loadingIndicator, () => _fimClient.EnumerateAll<RmResource>(query, attributesToFetch) .ToArray() ); DataTable table = new DataTable(); if (results.IsNotEmpty()) { // assuming that all results are of the same type var firstResult = results.First(); var resultType = firstResult.GetResourceType(); var resultTypeAttributes = firstResult.Attributes; SelectableAttribute[] fetchedAttributes; if (requiredAttributes.IsNotEmpty()) { fetchedAttributes = requiredAttributes.ToArray(); } else { FetchAttributesForObjectType(resultType); fetchedAttributes = _attributesCache[resultType].ToArray(); } var resultTableColumnNames = new List<string>(); foreach (var a in resultTypeAttributes.OrderBy(x => x.Key.Name)) { var selectedAttribute = fetchedAttributes.SingleOrDefault(x => x.Attribute.Name == a.Key.Name); if (selectedAttribute == null) { continue; } var column = table.Columns.Add(selectedAttribute.Attribute.DisplayName); resultTableColumnNames.Add(selectedAttribute.Attribute.Name); // window can detect references by their 'object' type as opposed to 'string' defined for all other fields if (selectedAttribute.Attribute.DataType == RmFactory.RmAttributeType.Reference.ToString()) { column.DataType = typeof(object); } else { column.DataType = typeof(string); } } foreach (var resource in results) { var newRowValues = resultTableColumnNames .Select(x => { if (resource.Attributes.Keys.Any(y => y.Name == x)) { return resource.Attributes.First(y => y.Key.Name == x) .Value.Value; } else { return null; } }) .ToArray(); table.Rows.Add(newRowValues); } } QueriedValues = table; }
private void FetchAttributesForObjectType(string typeName) { if (_attributesCache.ContainsKey(typeName)) { return; } _parent.LongRunningOperation(_parent.loadingIndicator, () => { var attributesToFetch = new AttributesToFetch( RmResource.AttributeNames.DisplayName.Name , RmAttributeTypeDescription.AttributeNames.Name.Name , RmAttributeTypeDescription.AttributeNames.DataType.Name ); string query = "/BindingDescription[BoundObjectType = " + "/ObjectTypeDescription[Name = '{0}']]".FormatWith(typeName) + "/BoundAttributeType"; var attributes = _fimClient.EnumerateAll<RmAttributeTypeDescription>(query, attributesToFetch) .ToList(); _attributesCache.Add(typeName, attributes.Select(x => new SelectableAttribute(x)).ToList()); }); }
private void FetchObjectTypes() { _parent.LongRunningOperation(_parent.loadingIndicator, () => { var attributesToFetch = new AttributesToFetch(RmResource.AttributeNames.DisplayName.Name, RmAttributeTypeDescription.AttributeNames.Name.Name); var list = _fimClient.EnumerateAll<RmObjectTypeDescription>("/ObjectTypeDescription", attributesToFetch) .ToList(); ObjectTypes.Clear(); list.ForEach(x => ObjectTypes.Add(x)); }); }