private void InitializeMetadata() { var metadataList = new List <EntityMetadata>(); foreach (var type in typeof(AccountDefinition).Assembly.GetExportedTypes()) { if (type.GetCustomAttribute <EntityDefinitionAttribute>() == null) { continue; } var definition = DefinitionCache.GetEntityDefinition(type); var metadata = definition.ToEntityMetadata(); metadataList.Add(metadata); } //FakedContext.InitializeMetadata(metadataList); }
public void Can_merge_two_definition_caches() { var type = DefinitionCacheItemType.Script; var time = DateTime.Now; var cache = new DefinitionCache(); cache .Add(type, "", time, false, true, "cmd1", "") .Append(type, "", time, false, true, "cmd2", "") .Append(type, "", time, false, true, "cmd3", "") .Append(type, "", time, false, false, "-g", ""); var another = new DefinitionCache(); another .Add(type, "", time, false, true, "cmdAnother", "") .Append(type, "", time, false, true, "cmdAnother2", ""); cache.Merge(new string[] { }, another); Assert.That(cache.Definitions.Length, Is.EqualTo(2)); }
public void When_merging_two_definition_caches_it_will_not_add_duplicate_commands() { var type = DefinitionCacheItemType.Script; var time = DateTime.Now; var cache = new DefinitionCache(); cache .Add(type, "", time, false, true, "cmd1", "") .Append(type, "", time, false, true, "cmd2", "") .Append(type, "", time, false, true, "cmd3", "") .Append(type, "", time, false, false, "-g", ""); var another = new DefinitionCache(); another .Add(type, "", time, false, true, "cmd1", "") .Append(type, "", time, false, true, "cmdAnother", ""); cache.Merge(new string[] { }, another); Assert.That(cache.Definitions.Length, Is.EqualTo(1)); }
public void Can_write_definition_cache() { string actualJSON = null; var writer = new DefinitionCacheWriter("/write/path") .WriteUsing((file, content) => actualJSON = content); var type = DefinitionCacheItemType.Script; var script = "/my/script"; var time = new DateTime(2013, 1, 1, 2, 3, 1); var cache = new DefinitionCache(); cache .Add(type, script, time, false, true, "mycmd", "My command does my stuff.") .Append(type, script, time, false, true, "FILE", "another param") .Append(type, script, time, false, false, "optional", "This one is optional"); writer.Write(cache); Assert.That(actualJSON, Is.EqualTo(expectedJSON())); }
private EntityMetadata(Type type) { BindingType = type; EntityDefinition = DefinitionCache.GetEntityDefinitionFromModelType(type); TypeFullName = type.FullName; IsValidForCreate = type.GetCustomAttribute <CrmEntityAttribute>().ValidForCreate; AllowDeactivation = type.GetCustomAttribute <CrmEntityAttribute>().AllowDeactivation; IdProperty = type.GetProperty("Id"); var attributes = new List <AttributeMetadata>(); var extendBindingProperties = new List <PropertyInfo>(); var crmRelationshipProperties = new List <PropertyInfo>(); var allProperties = new List <PropertyInfo>(); foreach (var property in type.GetProperties()) { if (property.GetCustomAttribute <CrmMappingAttribute>() != null) { attributes.Add(new AttributeMetadata(EntityDefinition, property)); } else if (property.GetCustomAttributes <ExtendBindingModelAttribute>().Any()) { extendBindingProperties.Add(property); } else if (property.GetCustomAttributes <CrmRelationshipAttribute>().Any()) { crmRelationshipProperties.Add(property); } allProperties.Add(property); } CrmAttributes = attributes; ExtendBindingProperties = extendBindingProperties; CrmRelationshipProperties = crmRelationshipProperties; AllProperties = allProperties; IsBindingModelBase = typeof(BindingModelBase).IsAssignableFrom(type); }