protected override void Arrange() { _resources = ResourceModelProvider.GetResourceModel().GetAllResources().ToList(); _expectedPropertyNamesByDefinitionName = ExpectedPropertyNamesByDefinitionName(_resources); _namingStrategy = new OpenApiMetadataDefinitionsFactoryDefaultNamingStrategy(); _expectedDefinitionNames = _resources .Select(x => _namingStrategy.GetResourceName(x, new OpenApiMetadataResource(x)).ToCamelCase()).ToList(); }
private static IDictionary<string, List<string>> ExpectedPropertyNamesByDefinitionName(IEnumerable<Resource> resources) { var namingStrategy = new OpenApiMetadataDefinitionsFactoryDefaultNamingStrategy(); var definitions = resources.Select( d => new { DefinitionName = namingStrategy.GetResourceName(d, new OpenApiMetadataResource(d)), Properties = d.UnifiedKeyAllProperties().Select(p => p.JsonPropertyName).Concat( d.Collections.Select( c => c.IsDerivedEntityATypeEntity() && c.IsInherited ? c.Association.OtherEntity.PluralName.ToCamelCase() : c.JsonPropertyName)).Concat(d.EmbeddedObjects.Select(e => e.JsonPropertyName)) .Concat(d.References.Select(r => r.PropertyName.ToCamelCase())) }).Concat( resources.SelectMany(r => r.AllContainedItemTypes).Select( i => new { DefinitionName = namingStrategy.GetContainedItemTypeName( new OpenApiMetadataResource(new Resource("TestResource")), i).ToCamelCase(), Properties = i.Properties .Select(p => UniqueIdSpecification.GetUniqueIdPropertyName(p.JsonPropertyName)) .Concat(i.Collections.Select(c => c.JsonPropertyName)) .Concat(i.EmbeddedObjects.Select(e => e.JsonPropertyName)) .Concat(i.References.Select(r => r.PropertyName.ToCamelCase())) })).Concat( resources.SelectMany(x => x.AllContainedReferences).Distinct(ModelComparers.ReferenceTypeNameOnly).Select( reference => new { DefinitionName = namingStrategy.GetReferenceName(new Resource("TestResource"), reference), Properties = reference.ReferenceTypeProperties.Where(p => p.IsIdentifying).Select( p => UniqueIdSpecification.GetUniqueIdPropertyName(p.JsonPropertyName)) })).ToList(); return definitions.GroupBy(x => x.DefinitionName).Select(x => x.First()).ToDictionary( k => k.DefinitionName.ToCamelCase(), v => v.Properties.ToList()); }