Skip to content

Commit b513450

Browse files
committed
both single and collection filters referencing two entities each in one test. tree reordering is done. closes #6 readme update pending.
1 parent 021ad51 commit b513450

17 files changed

Lines changed: 106 additions & 131 deletions

File tree

TestingContext/Implementation/Dependencies/CollectionDependency.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@ public CollectionDependency(Definition definition)
1313
Definition = definition;
1414
}
1515

16-
public IEnumerable<TItem> GetValue(IResolutionContext context, NodeResolver resolver)
16+
public IEnumerable<TItem> GetValue(IResolutionContext context)
1717
{
18-
return resolver.ResolveCollection(Definition, context)
19-
.Where(x => x.MeetsConditions)
18+
return context.Get(Definition)
2019
.Distinct()
2120
.Cast<IResolutionContext<TItem>>()
2221
.Select(x => x.Value);
2322
}
2423

25-
public bool TryGetValue(IResolutionContext context, NodeResolver resolver, out IEnumerable<TItem> value)
24+
public bool TryGetValue(IResolutionContext context, out IEnumerable<TItem> value)
2625
{
27-
value = GetValue(context, resolver);
26+
value = GetValue(context);
2827
return true;
2928
}
3029

TestingContext/Implementation/Dependencies/IDependency.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ internal interface IDependency
1212

1313
internal interface IDependency<TSource> : IDependency
1414
{
15-
bool TryGetValue(IResolutionContext context, NodeResolver resolver, out TSource value);
15+
bool TryGetValue(IResolutionContext context, out TSource value);
1616
}
1717
}

TestingContext/Implementation/Dependencies/SingleDependency.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public SingleDependency(Definition definition)
1111
Definition = definition;
1212
}
1313

14-
public bool TryGetValue(IResolutionContext context, NodeResolver resolver, out TSource value)
14+
public bool TryGetValue(IResolutionContext context, out TSource value)
1515
{
1616
var definedcontext = context.ResolveSingle(Definition) as IResolutionContext<TSource>;
1717
value = definedcontext.Value;

TestingContext/Implementation/Filters/Filter1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public bool MeetsCondition(IResolutionContext context, NodeResolver resolver, ou
3232
T1 argument;
3333
failureWeight = EmptyArray;
3434
failure = this;
35-
if (!dependency.TryGetValue(context, resolver, out argument))
35+
if (!dependency.TryGetValue(context, out argument))
3636
{
3737
return false;
3838
}

TestingContext/Implementation/Filters/Filter2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public bool MeetsCondition(IResolutionContext context, NodeResolver resolver, ou
3636
failureWeight = EmptyArray;
3737
failure = this;
3838

39-
if (!dependency1.TryGetValue(context, resolver, out argument1) || !dependency2.TryGetValue(context, resolver, out argument2))
39+
if (!dependency1.TryGetValue(context, out argument1) || !dependency2.TryGetValue(context, out argument2))
4040
{
4141
return false;
4242
}

TestingContext/Implementation/ProhibitedRelation.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.

TestingContext/Implementation/Providers/Provider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Provider(IDependency<TSource> dependency,
2525
public IEnumerable<IResolutionContext> Resolve(IResolutionContext parentContext, INode node)
2626
{
2727
TSource sourceValue;
28-
if (!dependency.TryGetValue(parentContext, node.Resolver, out sourceValue))
28+
if (!dependency.TryGetValue(parentContext, out sourceValue))
2929
{
3030
return Enumerable.Empty<IResolutionContext>();
3131
}

TestingContext/Implementation/TreeOperation/Nodes/Node.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Node(Tree tree, Definition definition, IProvider provider, NodeFilters fi
2020

2121
public INode SourceParent { get; set; }
2222

23-
public bool IsChildOf(INode node) => Parent == node || Parent.IsChildOf(node);
23+
public bool IsChildOf(INode node) => Parent == node || Parent.IsChildOf(node);
2424

2525
public List<INode> GetParentalChain()
2626
{

TestingContext/Implementation/TreeOperation/Subsystems/NodeReorderingService.cs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,29 @@ public static void ReorderNodesForFilter(Tree tree, IFilter filter)
1515
{
1616
for (int j = i + 1; j < filter.Dependencies.Length; j++)
1717
{
18-
if (!ReorderNodesForDependencies(tree, filter.Dependencies[i], filter.Dependencies[j]))
19-
{
20-
throw new ResolutionException($"Filter implies chaining of entities, that is not allowed by other filters. " +
21-
$"This filter makes graph that was not successfully resolved." +
22-
$"{filter.Key} {filter.FilterString} ");
23-
}
18+
ReorderNodesForDependencies(tree, filter.Dependencies[i], filter.Dependencies[j]);
2419
}
2520
}
2621
}
2722

28-
private static bool ReorderNodesForDependencies(Tree tree, IDependency dep1, IDependency dep2)
23+
private static void ReorderNodesForDependencies(Tree tree, IDependency dep1, IDependency dep2)
2924
{
3025
if (dep1.Definition == dep2.Definition || dep1.IsCollectionDependency || dep2.IsCollectionDependency)
3126
{
32-
return true;
27+
return;
3328
}
3429

3530
var node1 = tree.Nodes[dep1.Definition];
3631
var node2 = tree.Nodes[dep2.Definition];
3732
if (node1.IsChildOf(node2) || node2.IsChildOf(node1))
3833
{
39-
return true;
34+
return;
4035
}
4136

4237
var chain1 = node1.GetParentalChain();
4338
var chain2 = node2.GetParentalChain();
4439
var closestParentIndex = FindClosestParent(chain1, chain2);
45-
var chained = ChainUpNodes(tree, chain1[closestParentIndex + 1], node2);
46-
chained = chained || ChainUpNodes(tree, chain1[closestParentIndex + 1], node2);
47-
return chained;
48-
}
49-
50-
private static bool ChainUpNodes(Tree tree, INode node, INode newParent)
51-
{
52-
if (!ChainUpIsValid(tree, node, newParent))
53-
{
54-
return false;
55-
}
56-
57-
node.Parent = newParent;
58-
return true;
59-
}
60-
61-
private static bool ChainUpIsValid(Tree tree, INode node, INode newParent)
62-
{
63-
return !tree.ProhibitedRelations
64-
.Where(prohibitedRelation => prohibitedRelation.Child.IsChildOf(node))
65-
.Any(prohibitedRelation => newParent.IsChildOf(prohibitedRelation.Parent));
40+
chain1[closestParentIndex + 1].Parent = node2;
6641
}
6742
}
6843
}

TestingContext/Implementation/TreeOperation/Subsystems/ProhibitedRelationsService.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)