Ejemplo n.º 1
0
        public void EditGetAction_TeamId_TeamViewModelIsReturned()
        {
            var team    = CreateTeam();
            var captain = CreatePlayer(SPECIFIED_PLAYER_ID);
            var roster  = new PlayerServiceTestFixture()
                          .TestPlayers()
                          .AddPlayer(captain)
                          .Build();

            MockTeamServiceGetTeam(team);
            _teamServiceMock.Setup(ts => ts.GetTeamCaptain(It.IsAny <Team>())).Returns(captain);
            _teamServiceMock.Setup(ts => ts.GetTeamRoster(It.IsAny <int>())).Returns(roster.ToList());

            var sut = BuildSUT();

            SetupControllerContext(sut);

            var expected = CreateViewModel();

            // Act
            var actual = TestExtensions.GetModel <TeamViewModel>(sut.Edit(SPECIFIED_TEAM_ID));

            // Assert
            TestHelper.AreEqual <TeamViewModel>(expected, actual, new TeamViewModelComparer());
        }
Ejemplo n.º 2
0
        public void Details_ExistingTeam_TeamViewModelIsReturned()
        {
            // Arrange
            var team    = CreateTeam();
            var captain = CreatePlayer(SPECIFIED_PLAYER_ID);
            var roster  = new PlayerServiceTestFixture()
                          .TestPlayers()
                          .AddPlayer(captain)
                          .Build();

            MockTeamServiceGetTeam(team);
            _teamServiceMock.Setup(ts => ts.GetTeamCaptain(It.IsAny <Team>())).Returns(captain);
            _teamServiceMock.Setup(ts => ts.GetTeamRoster(It.IsAny <int>())).Returns(roster.ToList());
            SetupRequestRawUrl("/Teams");
            var sut = BuildSUT();

            SetupControllerContext(sut);

            var expected = CreateViewModel();

            // Act
            var actual = TestExtensions.GetModel <TeamRefererViewModel>(sut.Details(SPECIFIED_TEAM_ID));

            // Assert
            TestHelper.AreEqual <TeamViewModel>(expected, actual.Model, new TeamViewModelComparer());
            Assert.AreEqual(actual.CurrentReferrer, sut.Request.RawUrl);
        }
Ejemplo n.º 3
0
        public void Edit_RosterPlayerIsCaptainOfAnotherTeam_ValidationExceptionThrown()
        {
            // Arrange
            var team    = CreateTeam();
            var captain = CreatePlayer(SPECIFIED_PLAYER_ID);
            var roster  = new PlayerServiceTestFixture()
                          .TestPlayers()
                          .AddPlayer(captain)
                          .Build();

            MockTeamServiceGetTeam(team);
            _teamServiceMock.Setup(ts => ts.GetTeamCaptain(It.IsAny <Team>())).Returns(captain);
            _teamServiceMock.Setup(ts => ts.GetTeamRoster(It.IsAny <int>())).Returns(roster.ToList());

            var viewModel = CreateViewModel();

            _teamServiceMock.Setup(ts => ts.UpdateRosterTeamId(It.IsAny <List <Player> >(), It.IsAny <int>()))
            .Throws(new ValidationException(SPECIFIED_EXCEPTION_MESSAGE));

            // Act
            var sut         = BuildSUT();
            var jsonResult  = sut.Edit(viewModel);
            var modelResult = jsonResult;

            // Assert
            _teamServiceMock.Verify(ts => ts.UpdateRosterTeamId(It.IsAny <List <Player> >(), It.IsAny <int>()), Times.Once());
            Assert.IsNotNull(modelResult);
        }
Ejemplo n.º 4
0
        public void Edit_TeamPassed_EntityIdIsSet()
        {
            // Arrange
            var team    = CreateTeam();
            var captain = CreatePlayer(SPECIFIED_PLAYER_ID);
            var roster  = new PlayerServiceTestFixture()
                          .TestPlayers()
                          .AddPlayer(captain)
                          .Build();

            MockTeamServiceGetTeam(team);
            _teamServiceMock.Setup(ts => ts.GetTeamCaptain(It.IsAny <Team>())).Returns(captain);
            _teamServiceMock.Setup(ts => ts.GetTeamRoster(It.IsAny <int>())).Returns(roster.ToList());

            var viewModel      = CreateViewModel();
            var expectedDomain = viewModel.ToDomain();
            var comparer       = new TeamComparer();

            _teamServiceMock.Setup(ts => ts.Create(It.Is <Team>(t => comparer.AreEqual(t, expectedDomain))))
            .Callback <Team>(t => t.Id = SPECIFIED_TEAM_ID);

            // Act
            var sut = BuildSUT();

            sut.Edit(viewModel);

            // Assert
            Assert.AreEqual(viewModel.Id, SPECIFIED_TEAM_ID);
        }
Ejemplo n.º 5
0
        public void Delete_TeamPassed_TeamDeleted()
        {
            // Arrange
            var testData = new PlayerServiceTestFixture()
                           .Build();

            MockGetTeamRosterQuery(testData.ToList());

            // Act
            var ts = BuildSUT();

            ts.Delete(SPECIFIC_TEAM_ID);

            // Assert
            VerifyDeleteTeam(SPECIFIC_TEAM_ID, Times.Once());
        }
Ejemplo n.º 6
0
        public void Delete_TeamPassed_RosterPlayersUpdated()
        {
            // Arrange
            IQueryable <Player> expectedRoster = new PlayerServiceTestFixture().TestPlayers().Build().AsQueryable <Player>();
            int expectedCountOfPlayers         = expectedRoster.Count();

            MockGetTeamRosterQuery(expectedRoster.ToList());

            // Act
            var ts = BuildSUT();

            ts.Delete(SPECIFIC_TEAM_ID);

            // Assert
            _playerRepositoryMock.Verify(
                pr => pr.Update(It.Is <Player>(player => expectedRoster.Contains(player))),
                Times.Exactly(expectedCountOfPlayers));

            _unitOfWorkMock.Verify(tr => tr.Commit(), Times.Once());
        }
Ejemplo n.º 7
0
        public void Edit_RosterPlayerPassed_PlayersUpdated()
        {
            // Arrange
            var team         = CreateTeam();
            var captain      = CreatePlayer(SPECIFIED_PLAYER_ID);
            var rosterDomain = new PlayerServiceTestFixture()
                               .TestPlayers()
                               .AddPlayer(captain)
                               .Build();

            MockTeamServiceGetTeam(team);
            _teamServiceMock.Setup(ts => ts.GetTeamCaptain(It.IsAny <Team>())).Returns(captain);
            _teamServiceMock.Setup(ts => ts.GetTeamRoster(It.IsAny <int>())).Returns(rosterDomain.ToList());

            var rosterPlayer = new PlayerNameViewModel()
            {
                Id = SPECIFIED_PLAYER_ID, FirstName = SPECIFIED_FIRST_PLAYER_NAME, LastName = SPECIFIED_LAST_PLAYER_NAME
            };
            var roster = new List <PlayerNameViewModel>()
            {
                rosterPlayer
            };
            var viewModel = new TeamMvcViewModelBuilder().WithRoster(roster).Build();

            _teamServiceMock.Setup(ts => ts.Edit(It.IsAny <Team>()))
            .Callback <Team>(t => t.Id = SPECIFIED_TEAM_ID);

            // Act
            var sut = BuildSUT();

            sut.Edit(viewModel);

            // Assert
            _teamServiceMock.Verify(
                ts => ts.UpdateRosterTeamId(It.IsAny <List <Player> >(), It.IsAny <int>()),
                Times.Once());
        }
Ejemplo n.º 8
0
        public void Edit_RosterPlayerPassed_PlayersUpdated()
        {
            // Arrange
            var team         = CreateTeam();
            var captain      = CreatePlayer(SPECIFIED_PLAYER_ID);
            var rosterDomain = new PlayerServiceTestFixture()
                               .TestPlayers()
                               .AddPlayer(captain)
                               .Build();

            MockTeamServiceGetTeam(team);
            _teamServiceMock.Setup(ts => ts.GetTeamCaptain(It.IsAny <Team>())).Returns(captain);
            _teamServiceMock.Setup(ts => ts.GetTeamRoster(It.IsAny <TeamId>())).Returns(rosterDomain.ToList());

            var rosterPlayer = new PlayerNameViewModel()
            {
                Id = SPECIFIED_PLAYER_ID, FirstName = SPECIFIED_FIRST_PLAYER_NAME, LastName = SPECIFIED_LAST_PLAYER_NAME
            };
            var roster = new List <PlayerNameViewModel>()
            {
                rosterPlayer
            };
            var viewModel = new TeamMvcViewModelBuilder().WithRoster(roster).Build();

            _teamServiceMock.Setup(ts => ts.Edit(It.IsAny <Team>()));
            _playerServiceMock.Setup(ps => ps.GetPlayerTeam(It.IsAny <Player>())).Returns(team);
            _playerServiceMock.Setup(ps => ps.CreateBulk(It.IsAny <ICollection <CreatePlayerDto> >()))
            .Returns(rosterDomain);


            // Act
            var sut        = BuildSUT();
            var jsonResult = sut.Edit(viewModel);

            // Assert
            Assert.IsNotNull(jsonResult);
        }
Ejemplo n.º 9
0
        public void Edit_RosterPlayerIsCaptainOfAnotherTeam_ValidationExceptionThrown()
        {
            // Arrange
            var team    = CreateTeam();
            var captain = CreatePlayer(SPECIFIED_PLAYER_ID);
            var roster  = new PlayerServiceTestFixture()
                          .TestPlayers()
                          .AddPlayer(captain)
                          .Build();

            MockTeamServiceGetTeam(team);
            _teamServiceMock.Setup(ts => ts.GetTeamCaptain(It.IsAny <Team>())).Returns(captain);
            _teamServiceMock.Setup(ts => ts.GetTeamRoster(It.IsAny <TeamId>())).Returns(roster.ToList());

            var viewModel = CreateViewModel();

            // Act
            var sut        = BuildSUT();
            var jsonResult = sut.Edit(viewModel);

            // Assert
            Assert.IsNotNull(jsonResult);
        }
Ejemplo n.º 10
0
        public void Edit_InvalidRosterPlayerId_ArgumentExceptionThrown()
        {
            // Arrange
            var team    = CreateTeam();
            var captain = CreatePlayer(SPECIFIED_PLAYER_ID);
            var roster  = new PlayerServiceTestFixture()
                          .TestPlayers()
                          .AddPlayer(captain)
                          .Build();

            MockTeamServiceGetTeam(team);
            _teamServiceMock.Setup(ts => ts.GetTeamCaptain(It.IsAny <Team>())).Returns(captain);
            _teamServiceMock.Setup(ts => ts.GetTeamRoster(It.IsAny <TeamId>())).Returns(roster.ToList());

            var viewModel = CreateViewModel();

            _teamServiceMock.Setup(ts => ts.Edit(It.IsAny <Team>()))
            .Throws(new MissingEntityException(SPECIFIED_EXCEPTION_MESSAGE));

            // Act
            var sut        = BuildSUT();
            var jsonResult = sut.Edit(viewModel);

            // Assert
            Assert.IsNotNull(jsonResult);
        }
Ejemplo n.º 11
0
        public void Create_RosterPlayerPassed_PlayersUpdated()
        {
            // Arrange
            var team         = CreateTeam();
            var captain      = CreatePlayer(SPECIFIED_PLAYER_ID);
            var rosterDomain = new PlayerServiceTestFixture()
                               .TestPlayers()
                               .AddPlayer(captain)
                               .Build();

            MockTeamServiceGetTeam(team);
            _teamServiceMock.Setup(ts => ts.GetTeamCaptain(It.IsAny <Team>())).Returns(captain);
            _teamServiceMock.Setup(ts => ts.GetTeamRoster(It.IsAny <TeamId>())).Returns(rosterDomain.ToList());
            _teamServiceMock.Setup(ts => ts.AddPlayers(It.IsAny <TeamId>(), It.IsAny <List <PlayerId> >()));
            _playerServiceMock.Setup(ps => ps.CreateBulk(It.IsAny <ICollection <CreatePlayerDto> >()))
            .Returns(rosterDomain);


            var rosterPlayer = new PlayerNameViewModel()
            {
                Id        = SPECIFIED_PLAYER_ID,
                FirstName = SPECIFIED_FIRST_PLAYER_NAME,
                LastName  = SPECIFIED_LAST_PLAYER_NAME
            };

            var roster = new List <PlayerNameViewModel>()
            {
                rosterPlayer
            };
            var viewModel = new TeamMvcViewModelBuilder().WithRoster(roster).WithAddedPlayers().Build();

            _teamServiceMock.Setup(ts => ts.Create(It.IsAny <CreateTeamDto>())).Returns(MakeTestTeams().First);

            // Act
            var sut = BuildSUT();

            sut.Create(viewModel);

            // Assert
            _playerServiceMock.Verify(
                ts => ts.CreateBulk(It.IsAny <List <CreatePlayerDto> >()),
                Times.Once());
        }
        public void TeamDetails_ExistingTeam_TeamViewModelIsReturned()
        {
            // Arrange
            var team    = CreateTeam();
            var captain = CreatePlayer(SPECIFIED_PLAYER_ID);
            var roster  = new PlayerServiceTestFixture()
                          .TestPlayers()
                          .AddPlayer(captain)
                          .Build();

            MockTeamServiceGetTeam(team);
            _teamServiceMock.Setup(ts => ts.GetTeamCaptain(It.IsAny <Team>())).Returns(captain);
            _teamServiceMock.Setup(ts => ts.GetTeamRoster(It.IsAny <TeamId>())).Returns(roster.ToList());

            var sut      = BuildSUT();
            var expected = CreateTeamViewModel();

            // Act
            var actual = TestExtensions.GetModel <TeamViewModel>(sut.TeamDetails(SPECIFIED_TEAM_ID));

            // Assert
            TestHelper.AreEqual <TeamViewModel>(expected, actual, new TeamViewModelComparer());
        }