public void ShouldGetInitialStatsFromDatabase()
        {
            // TestActorRef<MockDatabaseActor> mockDb = ActorOfAsTestActorRef<MockDatabaseActor>();

            TestProbe mockDb = CreateTestProbe();

            var messageHandler = new DelegateAutoPilot((sender, message) =>
            {
                if (message is GetInitialStatisticsMessage)
                {
                    var stats = new Dictionary <string, int>
                    {
                        { "Conan the Barbarian", 42 }
                    };

                    sender.Tell(new InitialStatisticsMessage(new ReadOnlyDictionary <string, int>(stats)));
                }

                return(AutoPilot.KeepRunning);
            });

            mockDb.SetAutoPilot(messageHandler);



            TestActorRef <StatisticsActor> actor =
                ActorOfAsTestActorRef(() => new StatisticsActor(mockDb));

            Assert.Equal(42, actor.UnderlyingActor.PlayCounts["Conan the Barbarian"]);
        }
Beispiel #2
0
        public void UsingTestProbe()
        {
            // arrange
            var mockDbActor = CreateTestProbe();
            var autoPilot   = new DelegateAutoPilot((sender, message) => {
                var stats = new Dictionary <string, int> {
                    { "Batman", 100 }
                    , { "Batman Returns", 200 }
                };
                sender.Tell(new InitialStatisticsMesage(new ReadOnlyDictionary <string, int>(stats)));
                return(AutoPilot.KeepRunning);
            });

            mockDbActor.SetAutoPilot(autoPilot);

            var actor = ActorOfAsTestActorRef(() => new StatisticsActor(mockDbActor));


            actor.UnderlyingActor.PlayCounts["Batman"].Should().Be(100);
        }