private TestKitSilo BuildSut(Guid gameId)
        {
            var mockStreamProvider = new Mock <IPlayerSeatStreamProvider> ();

            mockStreamProvider.SetupGet(x => x.Name).Returns("Default");
            Silo.AddServiceProbe(mockStreamProvider);
            var game = Silo.AddProbe <IGame> (gameId);

            game.Setup(x => x.GetBoardState()).Returns(new Common.BoardState("fen", "orig", "new", "eTag").ToTask());
            return(Silo);
        }
예제 #2
0
        private (TestKitSilo sut, Mock <IGame> game, IBoard board) BuildSut(Guid gameId)
        {
            var mockStreamProvider = new Mock <IPlayerMoveStreamProvider> ();

            mockStreamProvider.SetupGet(x => x.Name).Returns("Default");
            Silo.AddServiceProbe(mockStreamProvider);

            var game = Silo.AddProbe <IGame> (gameId);

            game.Setup(x => x.IsValidMove(It.IsAny <IPlayerMove>())).Returns(Task.FromResult(true));
            var board = Silo.CreateGrain <Board> (id: gameId);

            return(Silo, game, board);
        }
        public async Task InjectedDependencyCanBeVerified()
        {
            //This creates a mock and injects it into the tested grain.
            var featureManagementService = Silo.AddServiceProbe <IFeatureManagerSnapshot>();

            featureManagementService.Setup(x => x.IsEnabledAsync("FeatureA"))
            .ReturnsAsync(true);
            var token = new GrainCancellationTokenSource().Token;
            var sut   = await Silo.CreateGrainAsync <HelloWorld>(1);

            await sut.SayHello("Mike", token);

            featureManagementService.Verify(x => x.IsEnabledAsync("FeatureA"), Times.Once);
        }
        private TestKitSilo BuildSut(Guid gameId)
        {
            var mockStreamProvider = new Mock <IPlayerMoveStreamProvider> ();

            mockStreamProvider.SetupGet(x => x.Name).Returns("Default");
            Silo.AddServiceProbe(mockStreamProvider);
            var game       = Silo.AddProbe <IGame> (gameId);
            var boardState = new Common.BoardState(fen, orig, @new, eTag);

            game.Setup(x => x.GetBoardState()).ReturnsAsync(boardState);
            game.Setup(x => x.ApplyValidatedMove(It.IsAny <IPlayerMove> ())).ReturnsAsync(boardState);
            game.Setup(x => x.IsValidMove(It.IsAny <IPlayerMove> ())).ReturnsAsync(true);
            return(Silo);
        }
예제 #5
0
        public async Task SayHelloTestShouldPrintDate()
        {
            // Arrange
            const string greeting = "Bonjour";
            var          date     = DateTime.UtcNow.Date;

            var dateServiceMock = Silo.AddServiceProbe <IDateTimeService>();

            dateServiceMock.Setup(i => i.GetCurrentDate())
            .ReturnsAsync(() => date);

            var grain = Silo.CreateGrain <HelloGrainWithServiceDependency>(10);

            // Act
            var reply = await grain.SayHello(greeting);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal($"[{date}]: You said: '{greeting}', I say: Hello!", reply);

            dateServiceMock.Verify(i => i.GetCurrentDate(), Times.Once);
        }