Skip to content

Commit

Permalink
Closes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
andreashuber-lawo committed Apr 29, 2016
1 parent def7512 commit 2c493fd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
6 changes: 4 additions & 2 deletions Lawo.EmberPlusSharp/Model/INode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public interface INode : IElementWithSchemas
/// <see cref="ChildrenRetrievalPolicy.None"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">Attempted to set a value that is not equal to one of the named
/// constants of <see cref="ChildrenRetrievalPolicy"/>.</exception>
/// <remarks>Setting this property prompts the consumer to automatically retrieve children according to the new
/// value. To wait for the children to be retrieved, <see langword="await"/> the result of a call to
/// <remarks>Setting this property prompts the consumer to retrieve direct and indirect children according to
/// the new value. The retrieval starts automatically when
/// <see cref="Consumer{TRoot}.AutoSendInterval">Consumer&lt;TRoot&gt;.AutoSendInterval</see> elapses. To
/// explicitly wait for the children to be retrieved, <see langword="await"/> the result of a call to
/// <see cref="Consumer{TRoot}.SendAsync"/>.</remarks>
ChildrenRetrievalPolicy ChildrenRetrievalPolicy { get; set; }

Expand Down
64 changes: 38 additions & 26 deletions Lawo.EmberPlusSharpTest/Model/ConsumerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,34 +455,14 @@ public void ChildrenRetrievalPolicyTest()
AsyncPump.Run(
async () =>
{
await ChildrenRetrievalPolicyTestCoreAsync(
await StaticChildrenRetrievalPolicyTestAsync(
ChildrenRetrievalPolicy.None, "ChildrenRetrievalPolicyLog1.xml");
await ChildrenRetrievalPolicyTestCoreAsync(
await StaticChildrenRetrievalPolicyTestAsync(
ChildrenRetrievalPolicy.DirectOnly, "ChildrenRetrievalPolicyLog2.xml");
await ChildrenRetrievalPolicyTestCoreAsync(
await StaticChildrenRetrievalPolicyTestAsync(
ChildrenRetrievalPolicy.All, "ChildrenRetrievalPolicyLog3.xml");
await TestWithRobot<ModelPayloads>(
async client =>
{
using (var consumer = await Consumer<EmptyNodeRoot>.CreateAsync(
client, Timeout.Infinite, ChildrenRetrievalPolicy.None))
{
var root = consumer.Root;
Assert.IsNull(root.Node);
Assert.AreEqual(ChildrenRetrievalPolicy.None, root.ChildrenRetrievalPolicy);
root.ChildrenRetrievalPolicy = ChildrenRetrievalPolicy.DirectOnly;
await consumer.SendAsync();
Assert.IsNotNull(root.Node);
Assert.AreEqual(ChildrenRetrievalPolicy.None, root.Node.ChildrenRetrievalPolicy);
root.Node.ChildrenRetrievalPolicy = ChildrenRetrievalPolicy.All;
await consumer.SendAsync();
}
},
null,
null,
GlowTypes.Instance,
false,
"ChildrenRetrievalPolicyLog3.xml");
await DynamicChildrenRetrievalPolicyTestAsync(false);
await DynamicChildrenRetrievalPolicyTestAsync(true);
});
}

Expand Down Expand Up @@ -1613,7 +1593,7 @@ private static void AssertAccess(RecursiveFieldNode node)
}
}

private static Task ChildrenRetrievalPolicyTestCoreAsync(ChildrenRetrievalPolicy policy, string logName)
private static Task StaticChildrenRetrievalPolicyTestAsync(ChildrenRetrievalPolicy policy, string logName)
{
return TestWithRobot<ModelPayloads>(
async client =>
Expand Down Expand Up @@ -1659,6 +1639,38 @@ private static Task ChildrenRetrievalPolicyTestCoreAsync(ChildrenRetrievalPolicy
logName);
}

private Task DynamicChildrenRetrievalPolicyTestAsync(bool delay)
{
return TestWithRobot<ModelPayloads>(
async client =>
{
using (var consumer = await Consumer<EmptyNodeRoot>.CreateAsync(
client, Timeout.Infinite, ChildrenRetrievalPolicy.None))
{
consumer.AutoSendInterval = this.Random.Next(100, 5000);
var root = consumer.Root;
Assert.IsNull(root.Node);
Assert.AreEqual(ChildrenRetrievalPolicy.None, root.ChildrenRetrievalPolicy);
root.ChildrenRetrievalPolicy = ChildrenRetrievalPolicy.DirectOnly;
await WaitForCompletion(consumer, delay);
Assert.IsNotNull(root.Node);
Assert.AreEqual(ChildrenRetrievalPolicy.None, root.Node.ChildrenRetrievalPolicy);
root.Node.ChildrenRetrievalPolicy = ChildrenRetrievalPolicy.All;
await WaitForCompletion(consumer, delay);
}
},
null,
null,
GlowTypes.Instance,
false,
"ChildrenRetrievalPolicyLog3.xml");
}

private static Task WaitForCompletion(Consumer<EmptyNodeRoot> consumer, bool delay)
{
return delay ? Task.Delay(consumer.AutoSendInterval + 500) : consumer.SendAsync();
}

[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Objects are disposed within the called method.")]
private static Task TestWithRobot<TRoot>(
Func<Consumer<TRoot>, Task> testCallback, bool log, string logXmlName, params object[] args) where TRoot : Root<TRoot>
Expand Down

0 comments on commit 2c493fd

Please sign in to comment.