public void Items_are_added_to_a_dependency_graph() { _dependencyGraph = new DependencyGraph <string>(); _dependencyGraph.Add("A", "B"); _dependencyGraph.Add("B", "C"); _dependencyGraph.Add("D", "E"); }
public void Items_are_added_to_a_dependency_graph() { _dependencyGraph = new DependencyGraph<string>(); _dependencyGraph.Add("A", "B"); _dependencyGraph.Add("B", "C"); _dependencyGraph.Add("D", "E"); }
public void Items_are_added_to_a_dependency_graph() { var dependencyGraph = new DependencyGraph<string>(); dependencyGraph.Add("A", "B"); dependencyGraph.Add("B", "C"); dependencyGraph.Add("C", "D"); _dependencyOrder = dependencyGraph.GetItemsInDependencyOrder(); }
public void Adding_a_disconnected_loop_to_the_graph() { _dependencyGraph = new DependencyGraph <string>(); _dependencyGraph.Add("A", "B"); _dependencyGraph.Add("B", "C"); _dependencyGraph.Add("D", "E"); _dependencyGraph.Add("E", "F"); _dependencyGraph.Add("F", "D"); }
public void Items_are_added_to_a_dependency_graph() { var dependencyGraph = new DependencyGraph <string>(); dependencyGraph.Add("A", "B"); dependencyGraph.Add("B", "C"); dependencyGraph.Add("C", "D"); _dependencyOrder = dependencyGraph.GetItemsInDependencyOrder(); }
public void TestTwo() { var graph = new DependencyGraph <int>(); graph.Add(1, new[] { 2 }); graph.Add(2, Array.Empty <int>()); var result = graph.Solve(); CollectionAssert.AreEqual(new[] { 2, 1 }, result); }
public void TestThreeNonLinear() { var graph = new DependencyGraph <int>(); graph.Add(1, new[] { 2, 3 }); graph.Add(2, new[] { 3 }); graph.Add(3, Array.Empty <int>()); var result = graph.Solve(); CollectionAssert.AreEqual(new[] { 3, 2, 1 }, result); }
public void TestTwoCircular() { var graph = new DependencyGraph <int>(); graph.Add(1, new[] { 2 }); graph.Add(2, new[] { 1 }); try { var result = graph.Solve().ToArray(); Assert.Fail(); } catch { } }
public ISchema <TSchema> Build() { var builder = new SchemaBuilder <TSchema>(_entityTypeSelectorFactory); var graph = new DependencyGraph <Type>(); foreach (var specification in _specifications) { foreach (var entityType in specification.Value.GetReferencedEntityTypes()) { graph.Add(specification.Key, entityType); } } var orderedSpecifications = graph.GetItemsInDependencyOrder() .Concat(_specifications.Keys) .Distinct() .Select(type => _specifications[type]); foreach (var specification in orderedSpecifications) { specification.Apply(builder); } return(builder.Build()); }
public void There_is_a_huge_dependency_chain() { _dependencyGraph = new DependencyGraph <int>(); for (int i = 0; i < 1000; i++) { _dependencyGraph.Add(i, i + 1); } }
public void TestOne() { var graph = new DependencyGraph <Type>(); graph.Add(typeof(DependencyGraphTests), Array.Empty <Type>()); var result = graph.Solve(); Assert.AreEqual(result.Count(), 1); }
void ValidateBinding(IMessageSink <InMemoryTransportMessage> destination, IInMemoryExchange sourceExchange) { try { var graph = new DependencyGraph <IMessageSink <InMemoryTransportMessage> >(_exchanges.Count + 1); foreach (var exchange in _exchanges.Values) { foreach (IMessageSink <InMemoryTransportMessage> sink in exchange.Sinks) { graph.Add(sink, exchange); } } graph.Add(destination, sourceExchange); graph.EnsureGraphIsAcyclic(); } catch (Exception exception) { throw new InvalidOperationException($"The exchange binding would create a cycle in the messaging fabric.", exception); } }
public static ObjectInfo[] GetMessageObjectInfo(params MessageInfo[] messageInfos) { var graph = new DependencyGraph <ObjectInfo>(messageInfos.Length); var seen = new HashSet <ObjectInfo>(); void ApplyProperties(ObjectInfo sourceInfo) { if (seen.Contains(sourceInfo)) { return; } seen.Add(sourceInfo); graph.Add(sourceInfo); foreach (var propertyInfo in sourceInfo.Properties) { if ((propertyInfo.Kind & PropertyKind.Object) == PropertyKind.Object) { if (ObjectInfoCache.TryGetObjectInfo(propertyInfo.PropertyType, out var objectInfo)) { graph.Add(sourceInfo, objectInfo); ApplyProperties(objectInfo); } } } } foreach (var messageInfo in messageInfos) { if (ObjectInfoCache.TryGetObjectInfo(messageInfo.ObjectType, out var objectInfo)) { ApplyProperties(objectInfo); } } return(graph.GetItemsInOrder().ToArray()); }
private IEnumerable <DatabaseEntry> GetTablesInCreationOrder() { var graph = new DependencyGraph <Type>(); foreach (var entry in TableMap) { var dependencies = entry.Value.GetForeignKeys() .Select(entry => entry.Key.Table); graph.Add(entry.Key, dependencies); } foreach (var entry in graph.Solve()) { yield return(TableMap[entry]); } }
private IEnumerable <string> GetTablesInDependencyOrder() { DependencyGraph <string> graph = new DependencyGraph <string>(); foreach (string tableName in _schema.Value.GetTables()) { var items = _schema.Value.GetTableSchema(tableName).Where(x => !String.IsNullOrEmpty(x.References)); foreach (SchemaFieldItem item in items) { string[] parts = item.References.Split(';'); if (parts.Length > 0 && tableName != parts[0]) { graph.Add(parts[0], tableName); } } } return(graph.GetItemsInDependencyOrder()); }
public void TestDependents() { var graph = new DependencyGraph <Guid>(); var item1 = Guid.NewGuid(); var dep1 = Guid.NewGuid(); graph.Add(item1, dep1); // we should contain all the dependencies now Assert.True(graph.Contains(item1)); Assert.Contains(dep1, graph.GetDependencies(item1)); Assert.True(graph.GetDependencies(dep1).IsEmpty); Assert.True(graph.GetDependents(item1).IsEmpty); Assert.Contains(item1, graph.GetDependents(dep1)); // removing should fail with dependencies still in place Assert.False(graph.Remove(dep1)); // but succeed after we remove all dependents Assert.True(graph.Remove(item1)); Assert.True(graph.Remove(dep1)); }
static void AddDependentAssembly(DependencyGraph<string> graph, string assemblyPath, string referencedAssemblyName) { string name = Path.GetFileName(assemblyPath); string path = Path.GetDirectoryName(assemblyPath); string referencedPath = Path.Combine(path, referencedAssemblyName + ".dll"); if (File.Exists(referencedPath)) { string assemblyName = Path.GetFileName(referencedPath); graph.Add(name, assemblyName); Assembly assembly = Assembly.ReflectionOnlyLoadFrom(referencedPath); foreach (AssemblyName referencedAssembly in assembly.GetReferencedAssemblies()) { string referencedName = Path.GetFileName(referencedAssembly.Name); AddDependentAssembly(graph, assemblyName, referencedName); } } }
void BuildSchema(ISchemaBuilder <TSchema> builder) { var graph = new DependencyGraph <Type>(); foreach (var specification in _schemaSpecifications) { foreach (var entityType in specification.Value.GetReferencedEntityTypes()) { graph.Add(specification.Key, entityType); } } var orderedSpecifications = graph.GetItemsInDependencyOrder() .Concat(_schemaSpecifications.Keys) .Distinct() .Select(type => _schemaSpecifications[type]); foreach (var specification in orderedSpecifications) { specification.Apply(builder); } }
void BuildLayouts(ISchemaLayoutBuilder <TSchema> schemaBuilder) { var builder = new SchemaLayoutBuilder <TSchema>(schemaBuilder); var graph = new DependencyGraph <Type>(); foreach (var specification in _structureSpecifications) { foreach (var layoutType in specification.Value.GetReferencedLayoutTypes()) { graph.Add(specification.Key, layoutType); } } var orderedSpecifications = graph.GetItemsInDependencyOrder() .Concat(_structureSpecifications.Keys) .Distinct() .Select(type => _structureSpecifications[type]); foreach (var specification in orderedSpecifications) { specification.Apply(builder); } }
public void There_is_a_huge_dependency_chain() { _dependencyGraph = new DependencyGraph<int>(); for (int i = 0; i < 1000; i++) { _dependencyGraph.Add(i, i + 1); } }
public void Adding_a_disconnected_loop_to_the_graph() { _dependencyGraph = new DependencyGraph<string>(); _dependencyGraph.Add("A", "B"); _dependencyGraph.Add("B", "C"); _dependencyGraph.Add("D", "E"); _dependencyGraph.Add("E", "F"); _dependencyGraph.Add("F", "D"); }