Exemplo n.º 1
0
        public void Edit_InValidTeamViewModel_JsonReturned()
        {
            // Arrange
            var viewModel = new TeamMvcViewModelBuilder().Build();
            var sut       = BuildSUT();

            sut.ModelState.AddModelError(string.Empty, string.Empty);

            // Act
            var result = sut.Edit(viewModel);

            // Assert
            _teamServiceMock.Verify(ts => ts.Edit(It.IsAny <Team>()), Times.Never());
            Assert.IsNotNull(result, ASSERT_FAIL_JSON_RESULT_MESSAGE);
        }
Exemplo n.º 2
0
        public void Create_RosterPlayerIsCaptainOfAnotherTeam_ValidationExceptionThrown()
        {
            // Arrange
            var viewModel = new TeamMvcViewModelBuilder().Build();

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

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

            // Assert
            Assert.IsNotNull(modelResult);
        }
Exemplo n.º 3
0
        public void Create_InValidTeamViewModel_JsonReturned()
        {
            // Arrange
            var viewModel = new TeamMvcViewModelBuilder().Build();
            var sut       = BuildSUT();

            sut.ModelState.AddModelError(string.Empty, string.Empty);

            // Act
            var result = sut.Create(viewModel);

            // Assert
            _teamServiceMock.Verify(ts => ts.Create(It.IsAny <CreateTeamDto>()), Times.Never());
            result.Should().NotBeNull(ASSERT_FAIL_JSON_RESULT_MESSAGE);
        }
Exemplo n.º 4
0
        public void Edit_TeamNotValid_ArgumentExceptionThrown()
        {
            // Arrange
            var viewModel = new TeamMvcViewModelBuilder().Build();

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

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

            // Assert
            _teamServiceMock.Verify(ts => ts.Edit(It.IsAny <Team>()), Times.Once());
            Assert.IsNotNull(modelResult);
        }
Exemplo n.º 5
0
        public void Create_RosterPlayerIsCaptainOfAnotherTeam_ValidationExceptionThrown()
        {
            // Arrange
            var viewModel = new TeamMvcViewModelBuilder().Build();

            _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.Create(viewModel);
            var modelResult = jsonResult;

            // Assert
            _teamServiceMock.Verify(ts => ts.UpdateRosterTeamId(It.IsAny <List <Player> >(), It.IsAny <int>()), Times.Once());
            Assert.IsNotNull(modelResult);
        }
Exemplo n.º 6
0
        public void Edit_InvalidCaptainId_MissingEntityExceptionThrown()
        {
            // Arrange
            var viewModel = new TeamMvcViewModelBuilder().Build();

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

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

            // Assert
            _teamServiceMock.Verify(ts => ts.Edit(It.IsAny <Team>()), Times.Once());
            _teamServiceMock.Verify(ts => ts.UpdateRosterTeamId(It.IsAny <List <Player> >(), It.IsAny <int>()), Times.Never());
            Assert.IsNotNull(modelResult);
        }
Exemplo n.º 7
0
        public void Create_TeamNotValid_ArgumentExceptionThrown()
        {
            // Arrange
            var viewModel = new TeamMvcViewModelBuilder().Build();

            _teamServiceMock.Setup(ts => ts.Create(It.IsAny <Team>()))
            .Throws(new ArgumentException(SPECIFIED_EXCEPTION_MESSAGE));
            var sut = BuildSUT();

            // Act
            var jsonResult     = sut.Create(viewModel);
            var actualMessage  = jsonResult.Data.ToString();
            var expetedMessage = $"{{ Success = False, Message = {SPECIFIED_EXCEPTION_MESSAGE} }}";

            // Assert
            _teamServiceMock.Verify(ts => ts.Create(It.IsAny <Team>()), Times.Once());
            Assert.AreEqual(actualMessage, expetedMessage);
        }
Exemplo n.º 8
0
        public void Create_TeamPassed_EntityIdIsSet()
        {
            // Arrange
            var viewModel      = new TeamMvcViewModelBuilder().WithId(0).Build();
            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.Create(viewModel);

            // Assert
            Assert.AreEqual(viewModel.Id, SPECIFIED_TEAM_ID);
        }
Exemplo n.º 9
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());
        }
Exemplo n.º 10
0
        public void Edit_CaptainOfAnotherTeam_ValidationExceptionThrown()
        {
            // Arrange
            var viewModel = new TeamMvcViewModelBuilder().Build();

            _teamServiceMock.Setup(ts => ts.Edit(It.IsAny <Team>()))
            .Throws(new ValidationException(SPECIFIED_EXCEPTION_MESSAGE));
            _teamServiceMock.Setup(ts => ts.Get(viewModel.Id)).Returns(MakeTestTeams().First());
            _playerServiceMock.Setup(ps => ps.GetPlayerTeam(It.IsAny <Player>())).Returns(MakeTestTeams().First());
            _playerServiceMock.Setup(ps => ps.CreateBulk(It.IsAny <ICollection <CreatePlayerDto> >()))
            .Returns(MakeTestPlayers());
            // Act
            var sut        = BuildSUT();
            var jsonResult = sut.Edit(viewModel);

            // Assert
            _teamServiceMock.Verify(ts => ts.Edit(It.IsAny <Team>()), Times.Once());
            _teamServiceMock.Verify(ts => ts.ChangeCaptain(It.IsAny <TeamId>(), It.IsAny <PlayerId>()), Times.Never());
            Assert.IsNotNull(jsonResult);
        }
Exemplo n.º 11
0
        public void Create_TeamNotValid_ArgumentExceptionThrown()
        {
            // Arrange
            var viewModel = new TeamMvcViewModelBuilder().Build();

            _teamServiceMock.Setup(ts => ts.Create(It.IsAny <CreateTeamDto>()))
            .Throws(new ArgumentException(SPECIFIED_EXCEPTION_MESSAGE));
            var players = MakeTestPlayers();

            _playerServiceMock.Setup(ps => ps.CreateBulk(It.IsAny <ICollection <CreatePlayerDto> >()))
            .Returns(players);

            var sut = BuildSUT();

            // Act
            var jsonResult     = sut.Create(viewModel);
            var actualMessage  = jsonResult.Data.ToString();
            var expetedMessage = $"{{ Success = False, Message = {SPECIFIED_EXCEPTION_MESSAGE} }}";

            // Assert
            _teamServiceMock.Verify(ts => ts.Create(It.IsAny <CreateTeamDto>()), Times.Once());
            Assert.Equal(actualMessage, expetedMessage);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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());
        }
Exemplo n.º 14
0
        public void Create_CreateTeamDtoPassed_EntityIdIsSet()
        {
            // Arrange
            var viewModel         = new TeamMvcViewModelBuilder().WithId(0).Build();
            var returnedviewModel = new TeamMvcViewModelBuilder().WithId(SPECIFIED_TEAM_ID).Build();
            var returnedDomain    = returnedviewModel.ToDomain();

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

            var players = MakeTestPlayers();

            _playerServiceMock.Setup(ps => ps.CreateBulk(It.IsAny <ICollection <CreatePlayerDto> >()))
            .Returns(players);

            // Act
            var sut    = BuildSUT();
            var result = sut.Create(viewModel);

            // Assert
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(viewModel.Id, SPECIFIED_TEAM_ID);
        }