Skip to content

Commit

Permalink
Merge pull request #224 from microsoft/andrueastman/tests
Browse files Browse the repository at this point in the history
Adds test for validation of invocation count
  • Loading branch information
andrueastman authored Apr 23, 2024
2 parents 3a92aa8 + d974416 commit 5166a62
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,32 @@ public void TestsBackingStoreEmbeddedInModelWithByUpdatingNestedIBackedModelColl
var colleagueSubscriptions = GetSubscriptionsPropertyFromBackingStore(testUser.Colleagues[0].BackingStore);
Assert.Single(colleagueSubscriptions);// only one subscription to be invoked for the collection "colleagues"
}

[Fact]
public void TestsBackingStoreNestedInvocationCounts()
{
// Arrange dummy user with initialized backing store
var invocationCount = 0;
var testUser = new TestEntity();
testUser.BackingStore.Subscribe((_, _, _) => invocationCount++, "testId");
testUser.Id = "84c747c1-d2c0-410d-ba50-fc23e0b4abbe"; // invocation site 1
var colleagues = new List<TestEntity>();
for(int i = 0; i < 10; i++)
{
colleagues.Add(new TestEntity
{
Id = "2fe22fe5-1132-42cf-90f9-1dc17e325a74",
BusinessPhones = new List<string>
{
"+1 234 567 891"
}
});
}
testUser.Colleagues = colleagues; // invocation site 2
testUser.BackingStore.InitializationCompleted = true; // initialize

Assert.Equal(2,invocationCount);// only called twice
}

/// <summary>
/// Helper function to pull out the private `subscriptions` collection property from the InMemoryBackingStore class
Expand Down

0 comments on commit 5166a62

Please sign in to comment.