public async Task Given2Actors_WhenCreatedAndDeleted_ShouldPass() { int count = 0; int count2 = 0; const int max = 10; using IActorHost actorHost = new ActorHost(_loggerFactory) .Register <ICache>(() => new StringCache(y => CountControl(ref count, y))) .Register <ICache2>(() => new StringCache2(y => CountControl(ref count2, y))); Enumerable.Range(0, max) .ForEach(x => { ActorKey key = new ActorKey($"cache/test/{x}"); ICache cache = actorHost.GetActor <ICache>(key); cache.GetActorKey().Should().Be(key); cache.GetActorHost().Should().Be(actorHost); cache.Test(key); ActorKey key2 = new ActorKey($"cache/test/{max-x}"); ICache2 cache2 = actorHost.GetActor <ICache2>(key2); cache2.GetActorKey().Should().Be(key2); cache2.GetActorHost().Should().Be(actorHost); cache2.Test(key2); }); count.Should().Be(max); count2.Should().Be(max); Enumerable.Range(0, max) .ForEach(x => { ActorKey key = new ActorKey($"cache/test/{x}"); ICache cache = actorHost.GetActor <ICache>(key); cache.GetActorKey().Should().Be(key); cache.GetActorKey().Key.Should().Be(key.Key); cache.GetActorKey().Value.Should().Be(key.Value); cache.GetActorHost().Should().Be(actorHost); cache.Test(key); ActorKey key2 = new ActorKey($"cache/test/{max-x}"); ICache2 cache2 = actorHost.GetActor <ICache2>(key2); cache2.GetActorKey().Should().Be(key2); cache2.GetActorKey().Key.Should().Be(key2.Key); cache2.GetActorKey().Value.Should().Be(key2.Value); cache2.GetActorHost().Should().Be(actorHost); cache2.Test(key2); }); await Enumerable.Range(0, max) .Select(async x => { ActorKey key = new ActorKey($"cache/test/{x}"); (await actorHost.Deactivate <ICache>(key)).Should().BeTrue(); ActorKey key2 = new ActorKey($"cache/test/{max-x}"); (await actorHost.Deactivate <ICache2>(key2)).Should().BeTrue(); }) .WhenAll(); count.Should().Be(0); count2.Should().Be(0); await actorHost.DeactivateAll(); count.Should().Be(0); count2.Should().Be(0); }