Пример #1
0
        public async Task UpdateAsync_WithReport_CallsOnUpdateWithUncoverableCells()
        {
            // Arrange

            // Game Field   => x = 5, y = 3
            // Clicked      => x = 2, y = 1
            // Report (x = covered, number = uncovered cell):
            // x x x x x
            // 1 2 1 x x
            // 0 0 2 x x
            IEnumerable <GameCell>   gameCells  = GetCells(5, 3);
            Mock <IGameUpdateReport> gameReport = new(MockBehavior.Strict);

            gameReport.Setup(report => report.Cells).Returns(GetUncoveredCells());
            GameUpdaterForTests instanceUnderTest = new();

            instanceUnderTest.WithReport(gameReport.Object);

            // Act
            await instanceUnderTest.UpdateAsync(gameCells, new Location(2, 1));

            // Assert
            instanceUnderTest.UncoverableCells.Should()
            .NotBeNullOrEmpty()
            .And
            .HaveCount(6);

            IEnumerable <GameCell> GetCells(uint x, uint y)
            {
                using TestContext testContext = new();
                testContext.Services.AddSingleton(new Mock <ICellStatusManager>(MockBehavior.Strict).Object);
                testContext.Services.AddSingleton(new Mock <ICellVisualizationManager>(MockBehavior.Strict).Object);

                for (uint i = 0; i < x; i++)
                {
                    for (uint j = 0; j < y; j++)
                    {
                        Location           location      = new(i, j);
                        ComponentParameter parameter     = ComponentParameterFactory.Parameter(nameof(GameCell.Location), location);
                        GameCell           cellComponent = testContext.RenderComponent <GameCell>(parameter).Instance;
                        yield return(cellComponent);
                    }
                }
            }

            IUncoveredCell[] GetUncoveredCells()
            {
                return(new[]
                {
                    new UncoveredCellForTests(new Location(1, 0), false, 1),
                    new UncoveredCellForTests(new Location(1, 1), false, 2),
                    new UncoveredCellForTests(new Location(1, 2), false, 1),
                    new UncoveredCellForTests(new Location(2, 0), false, 0),
                    new UncoveredCellForTests(new Location(2, 1), false, 0),
                    new UncoveredCellForTests(new Location(2, 2), false, 2),
                });
            }
        }
Пример #2
0
        public void GivenPageIsLoading_WhenUsernameIsPassedInPath_DispatchesActionsFromFacade()
        {
            // Arrange
            var profileState = new ProfileState(true, null, null);

            _mockProfileState.Setup(m => m.Value).Returns(profileState);

            // Act
            var componentParameter = ComponentParameterFactory.Parameter(nameof(Profile.Username), "test");
            var component          = RenderComponent <Profile>(componentParameter);

            // Assert
            _mockProfileState.VerifyAll();
            _mockFacade.Verify(m => m.GetUserProfile(It.IsAny <string>()), Times.Once);
            _mockFacade.Verify(m => m.GetArticles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()), Times.Once);
        }