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),
                });
            }
        }
Example #2
0
        public async Task when_no_user_is_select_adding_a_user_shoud_do_nothing()
        {
            var hasEventCallBackBeenCalled = false;
            var eventCallback = ComponentParameterFactory.EventCallback <UserObject>("Add", _ => hasEventCallBackBeenCalled = true);
            var target        = CreateComponent(eventCallback);

            target.Instance.UserObjectToAdd = null;
            await target.Instance.AddUser();

            hasEventCallBackBeenCalled.Should().BeFalse();
        }
        public void HeadingBuilt()
        {
            var renderedComponent = RenderComponent <Alert>(ComponentParameterFactory.RenderFragment(nameof(Alert.Heading), "heading-content"));

            var divisionElement = renderedComponent.Find("div");

            divisionElement.ClassName.Should().Be("alert");
            var headerElement = divisionElement.FindChild <IHtmlHeadingElement>();

            headerElement.LocalName.Should().Be("h1");
            headerElement.ClassName.Should().Be("alert-heading");
            headerElement.GetInnerText().Should().Be("heading-content");
        }
Example #4
0
        public async Task when_no_user_is_select_adding_a_user_shoud_call_the_add_eventcallback_with_the_user()
        {
            var hasEventCallBackBeenCalled = false;
            var eventCallback = ComponentParameterFactory.EventCallback <UserObject>("Add", _ => hasEventCallBackBeenCalled = true);
            var target        = CreateComponent(eventCallback);

            target.Instance.UserObjectToAdd = new UserObject {
                Id = 171, UserName = "******"
            };
            await target.Instance.AddUser();

            hasEventCallBackBeenCalled.Should().BeTrue();
        }
Example #5
0
        public void DinnerGuestsSelfStatus_NotHome_ReasonChangedEvent()
        {
            // Arrange
            var expected = new DinnerGuestsReasonChangedEvent(2, 2);
            DinnerGuestsReasonChangedEvent result = null;
            var cut = RenderComponent <DinnerGuestsSelfStatus>(
                ("ViewModel", DinnerGuestsTestModels.DinnerGuestsSelfNotHomeModel()),
                ComponentParameterFactory.EventCallback("OnComponentEvent", (evt) => result = (DinnerGuestsReasonChangedEvent)evt));

            // Act
            cut.FindAll(".options div")[1].Click();

            // Assert
            Assert.Equal(expected, result);
        }
Example #6
0
        public void DinnerGuestsSelfStatus_IsHome_StatusChangedEvent()
        {
            // Arrange
            var expected = new DinnerGuestsHomeForDinnerStatusChangeEvent(1, false);
            DinnerGuestsHomeForDinnerStatusChangeEvent result = null;
            var cut = RenderComponent <DinnerGuestsSelfStatus>(
                ("ViewModel", DinnerGuestsTestModels.DinnerGuestsSelfHomeModel()),
                ComponentParameterFactory.EventCallback("OnComponentEvent", (evt) => result = (DinnerGuestsHomeForDinnerStatusChangeEvent)evt));

            // Act
            cut.Find("input.switch").Click();

            // Assert
            Assert.Equal(expected, result);
        }
        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);
        }
Example #8
0
        public void Should_CallSignInMethod_When_SignInWasClick()
        {
            //Arrange
            var modalService = new Mock <IModalService>();

            Services.AddSingleton <IModalService>(modalService.Object);
            Services.AddMockUnAuthenticateAuthorization();
            var authenticationStateProvider = Services.GetService <AuthenticationStateProvider>();

            var index = RenderComponent <Index>(ComponentParameterFactory.CascadingValue(authenticationStateProvider.GetAuthenticationStateAsync()), ComponentParameterFactory.CascadingValue(modalService.Object));

            // Act
            index.Find(".alert-link").Click();

            // Assert
            modalService.Verify(mock => mock.Show <Login>(It.IsAny <string>()), Times.Once());
        }
Example #9
0
        public void ToDoListItem_Initial_Checked_ToDoStatusChangedEvent()
        {
            // Arrange
            var expected = new ToDoStatusChangedEvent(1, false);
            ToDoStatusChangedEvent result = null;
            var cut = RenderComponent <ToDoListItem>(
                ("ViewModel", ToDoListTestModels.ToDoListItemCheckedModel()),
                ComponentParameterFactory.EventCallback("OnComponentEvent", (evt) => result = (ToDoStatusChangedEvent)evt)
                );

            // Act
            cut.Find(".checkbox span").Click();


            // Assert
            Assert.Equal(expected, result);
        }
        public void GivenParameters_WhenAddingGoal_ThenGoalShouldBeReturned()
        {
            // Assert
            Goal goalReturned = null;
            var  addDialog    = RenderComponent <AddGoalDialog>(ComponentParameterFactory.EventCallback(nameof(AddGoalDialog.GoalAddedCallback), (Goal goal) => { goalReturned = goal; }));

            GetTitle(addDialog).Change("Title");
            GetRank(addDialog).Change(Rank.Important.Key);

            // Act
            SubmitForm(addDialog);

            // Assert
            goalReturned.ShouldNotBeNull();
            goalReturned.Title.ShouldBe("Title");
            goalReturned.Rank.ShouldBe(Rank.Important);
            goalReturned.GoalStatus.ShouldBe(GoalStatus.Todo);
        }
Example #11
0
        public void Should_DisplayUserLogin_When_UserIsAuthenticated()
        {
            //Arrange
            var modalService = new Mock <IModalService>();

            Services.AddSingleton <IModalService>(modalService.Object);

            var claims = new List <Claim>();

            claims.Add(new Claim(ClaimTypes.NameIdentifier, "UserTestLogin"));
            var claimIdentity = new ClaimsIdentity(claims);

            Services.AddMockAuthenticatedAuthorization(claimIdentity);
            var authenticationStateProvider = Services.GetService <AuthenticationStateProvider>();

            var index = RenderComponent <Index>(ComponentParameterFactory.CascadingValue(authenticationStateProvider.GetAuthenticationStateAsync()));

            // Act
            var homeLoggedMessage = index.Find("#home-logged-message");

            // Assert
            homeLoggedMessage.MarkupMatches(@"<span id=""home-logged-message"">You are logged in as user ""UserTestLogin"".</span>");
        }
        public void Should_DeleteJob_WhenDeleteButtonClicked()
        {
            //Arrange
            var jobs = _fixture.CreateMany <JobModel>(10);

            _jobService.Setup(service => service.GetAll()).Returns(Task.FromResult(jobs.ToList() as IList <JobModel>));

            var modalRef = new Mock <IModalReference>();

            modalRef.Setup(mock => mock.Result).Returns(Task.FromResult(ModalResult.Ok(new { })));
            _modalService.Setup(service => service.Show <DeleteModal>(It.IsAny <string>())).Returns(modalRef.Object);
            var jobPage = RenderComponent <Jhipster.Client.Pages.Entities.Job.Job>(ComponentParameterFactory.CascadingValue(_modalService.Object));

            // Act
            var jobToDelete = jobs.First();

            // Assert
            jobPage.Find("td>div>button").Click();
            _jobService.Verify(service => service.Delete(jobToDelete.Id.ToString()), Times.Once);
            var jobsTableBody = jobPage.Find("tbody");

            jobsTableBody.ChildElementCount.Should().Be(9);
        }