Skip to content

Commit

Permalink
Closes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
andreashuber-lawo committed Apr 5, 2017
1 parent 8fcfa7b commit d4c6e62
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions Lawo.EmberPlusSharpTest/Model/ConsumerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,21 @@ public void Bug27Test()
"false"));
}

/// <summary>Tests that Ember+ trees received with different <see cref="ChildrenRetrievalPolicy"/> have an equal
/// structure.</summary>
[TestMethod]
[TestCategory("Manual")]
public void Bug40Test()
{
AsyncPump.Run(
async () =>
{
var automaticRoot = await GetTreeAsync(ChildrenRetrievalPolicy.All);
var manualRoot = await GetTreeAsync(ChildrenRetrievalPolicy.DirectOnly);
Compare(automaticRoot, manualRoot);
});
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private static Task TestConsumerAfterFirstRequest<TRoot>(
Expand Down Expand Up @@ -2118,6 +2133,60 @@ private static async Task WaitAndAssertStableAsync(ObservableCollection<int> col
CollectionAssert.AreEqual(collection, expected);
}

private static async Task<EmptyDynamicRoot> GetTreeAsync(ChildrenRetrievalPolicy policy)
{
using (var tcpClient = new TcpClient())
{
await tcpClient.ConnectAsync("localhost", 8999);

using (var stream = tcpClient.GetStream())
using (var client = new S101Client(tcpClient, stream.ReadAsync, stream.WriteAsync))
using (var consumer = await Consumer<EmptyDynamicRoot>.CreateAsync(client, 10000, policy))
{
if (policy != ChildrenRetrievalPolicy.All)
{
await RetrieveChildrenAsync(consumer, consumer.Root);
}

return consumer.Root;
}
}
}

private static async Task RetrieveChildrenAsync(Consumer<EmptyDynamicRoot> consumer, INode node)
{
foreach (IElement child in node.Children)
{
var childNode = child as INode;

if (childNode != null)
{
childNode.ChildrenRetrievalPolicy = ChildrenRetrievalPolicy.DirectOnly;
await consumer.SendAsync();
await RetrieveChildrenAsync(consumer, childNode);
}
}
}

private static void Compare(INode expected, INode actual)
{
foreach (IElement expectedChild in expected.Children)
{
var actualChild = actual[expectedChild.Number];
Assert.IsNotNull(actualChild);
Assert.AreEqual(expectedChild.GetType(), actualChild.GetType());

var expectedChildNode = expectedChild as INode;

if (expectedChildNode != null)
{
var actualChildNode = actualChild as INode;
Assert.IsNotNull(actualChildNode);
Compare(expectedChildNode, actualChildNode);
}
}
}

private Task DynamicChildrenRetrievalPolicyTestAsync(bool delay)
{
return TestWithRobot<ModelPayloads>(
Expand Down

0 comments on commit d4c6e62

Please sign in to comment.