public void ContainsKey_SendInDictionaryWithStringKeyAndObjectArrayValueAndCheckForKey_ReturnsTrue() { var attributeValueCollection = A.CollectionOfFake<object>(1); var dictionary = new Hashtable(); dictionary.Add("key", attributeValueCollection); var collection = new AttributeCollection(dictionary); Assert.IsTrue(collection.ContainsKey("key")); }
public void ContainsKey_SendInDictionaryWithStringKeyAndObjectArrayValueAndCheckForKey_ReturnsTrue() { var attributeValueCollection = A.CollectionOfFake <object>(1); var dictionary = new Hashtable(); dictionary.Add("key", attributeValueCollection); var collection = new AttributeCollection(dictionary); Assert.IsTrue(collection.ContainsKey("key")); }
public void WithValueFalseRemovesAttributeIfAlreadyExists() { string attributeName = "AttributeName"; var attributeCollection = new AttributeCollection(); attributeCollection.AddOrRemoveMinimizedAttribute( attributeName, true ); attributeCollection.AddOrRemoveMinimizedAttribute( attributeName, false ); Assert.IsFalse( attributeCollection.ContainsKey( attributeName ) ); }
public void WithValueFalseDoesNotAddAttribute() { string attributeName = "AttributeName"; bool value = false; var attributeCollection = new AttributeCollection(); attributeCollection.AddOrRemoveMinimizedAttribute( attributeName, value ); Assert.IsFalse( attributeCollection.ContainsKey( attributeName ) ); }
public void WithWhiteSpaceNameDoesNotAddAttribute() { string name = " "; string script = "Script"; var attributes = new AttributeCollection(); var builder = new EventAttributeBuilder( attributes ); var result = builder.Event( name, script ); Assert.AreSame( builder, result ); Assert.IsFalse( attributes.ContainsKey( name ) ); }
/// /// Pack the translations into the name field when a Bilingual Item is Created or Updated /// Each translated name is packed into a pipe separated string /// This field is unpacked when the Bilingual Item entity is retrieved or related records are retrieved /// protected void PackTranslations(LocalPluginContext localContext) { if (!(localContext.PluginExecutionContext.InputParameters[InputParameter.Target] is Entity target)) { return; } Entity preImage = null; if (localContext.PluginExecutionContext.PreEntityImages.ContainsKey(PreImageAlias)) { preImage = localContext.PluginExecutionContext.PreEntityImages[PreImageAlias]; } var attributes = new AttributeCollection(); attributes.AddRange(target.Attributes); if (preImage != null) { attributes.AddRange(preImage.Attributes.Where(a => !attributes.ContainsKey(a.Key))); } // Check if the entity supports translations if (!attributes.TryGetValue(IsLocalizableAttribute, out _)) { return; } // Get the attributes for the current entity var response = localContext.OrganizationService.Execute( new RetrieveEntityRequest() { EntityFilters = EntityFilters.Attributes, LogicalName = localContext.PluginExecutionContext.PrimaryEntityName } ) as RetrieveEntityResponse; if (response == null) { return; } // Filter valid attributes var entityAttributes = response.EntityMetadata.Attributes .Where(a => a.AttributeType == AttributeTypeCode.String || a.AttributeType == AttributeTypeCode.Memo) .Select(a => a.LogicalName) .ToArray(); var translatedAttributes = entityAttributes.Where(a => LanguageSuffixes.Values.All(s => entityAttributes.Contains($"{a}{s}"))).ToArray(); foreach (var attribute in translatedAttributes) { var translations = new List <object>(); foreach (var suffix in LanguageSuffixes.Values) { var translatedAttribute = $"{attribute}{suffix}"; attributes.TryGetValue(translatedAttribute, out var translation); translations.Add(translation ?? string.Empty); } target[attribute] = $"{Prefix}{string.Join(Separator, translations)}"; } }