Пример #1
0
        public void ThrowArgumentNullException_WhenPlayerIdDoesNotTargetExistingPlayer()
        {
            // arrange
            var fixtureRepo     = new Mock <IEfRepository <Fixture> >();
            var teamsRepo       = new Mock <IEfRepository <Team> >();
            var playersRepo     = new Mock <IEfRepository <Player> >();
            var fixturesFactory = new Mock <IFixturesFactory>();
            var mailService     = new Mock <IFixtureMailService>();


            var fixtureId    = Guid.NewGuid();
            var fixtureEvent = FixtureEventType.Goal;
            int minute       = 22;
            var playerId     = Guid.NewGuid();

            var fixtures = new List <Fixture>()
            {
                new Fixture()
                {
                    Id = fixtureId
                }
            }.AsQueryable();

            fixtureRepo.Setup(x => x.All).Returns(fixtures);

            var fixtureService = new FixtureService(
                fixtureRepo.Object,
                teamsRepo.Object,
                playersRepo.Object,
                fixturesFactory.Object,
                mailService.Object);

            // act & assert
            Assert.Throws <ArgumentNullException>(() => fixtureService.AddFixtureEvent(fixtureId, fixtureEvent, minute, playerId));
        }
Пример #2
0
        public void CallFixtureFactoriesGetFixtureEventMethodWithCorrectParameters_WhenPlayerIdAndFixtureIdAreValid()
        {
            // arrange
            var fixtureRepo     = new Mock <IEfRepository <Fixture> >();
            var teamsRepo       = new Mock <IEfRepository <Team> >();
            var playersRepo     = new Mock <IEfRepository <Player> >();
            var fixturesFactory = new Mock <IFixturesFactory>();
            var mailService     = new Mock <IFixtureMailService>();

            var fixtureId        = Guid.NewGuid();
            var fixtureEventType = FixtureEventType.Goal;
            int minute           = 22;
            var playerId         = Guid.NewGuid();

            var players = new List <Player>()
            {
                new Player()
                {
                    Id = playerId
                }
            };

            playersRepo.Setup(pr => pr.All).Returns(players.AsQueryable());

            var fixtures = new List <Fixture>()
            {
                new Fixture()
                {
                    Id            = fixtureId,
                    FixtureEvents = new List <FixtureEvent>(),
                    HomeTeam      = new Team()
                    {
                        Players = players
                    },
                }
            }.AsQueryable();

            fixtureRepo.Setup(x => x.All).Returns(fixtures);

            var fixtureEvent = new FixtureEvent();

            fixturesFactory.Setup(f => f.GetFixtureEvent(fixtureEventType, minute, players[0])).Returns(fixtureEvent);

            var fixtureService = new FixtureService(
                fixtureRepo.Object,
                teamsRepo.Object,
                playersRepo.Object,
                fixturesFactory.Object,
                mailService.Object);

            // act
            fixtureService.AddFixtureEvent(fixtureId, fixtureEventType, minute, playerId);

            // assert
            fixturesFactory.Verify(f => f.GetFixtureEvent(fixtureEventType, minute, players[0]), Times.Once);
        }
Пример #3
0
        public void IncreaseAwayTeamsScoreByOne_WhenPlayerIsNotFoundInHomeTeamsPlayers()
        {
            // arrange
            var fixtureRepo     = new Mock <IEfRepository <Fixture> >();
            var teamsRepo       = new Mock <IEfRepository <Team> >();
            var playersRepo     = new Mock <IEfRepository <Player> >();
            var fixturesFactory = new Mock <IFixturesFactory>();
            var mailService     = new Mock <IFixtureMailService>();

            var fixtureId        = Guid.NewGuid();
            var fixtureEventType = FixtureEventType.Goal;
            int minute           = 22;
            var playerId         = Guid.NewGuid();

            var players = new List <Player>()
            {
                new Player()
                {
                    Id = playerId
                }
            };

            playersRepo.Setup(pr => pr.All).Returns(players.AsQueryable());

            var fixtures = new List <Fixture>()
            {
                new Fixture()
                {
                    Id            = fixtureId,
                    FixtureEvents = new List <FixtureEvent>(),
                    HomeTeam      = new Team()
                    {
                        Players = new List <Player>()
                    },
                }
            }.AsQueryable();

            fixtureRepo.Setup(x => x.All).Returns(fixtures);

            var fixtureEvent = new FixtureEvent();

            fixturesFactory.Setup(f => f.GetFixtureEvent(fixtureEventType, minute, players[0])).Returns(fixtureEvent);

            var fixtureService = new FixtureService(
                fixtureRepo.Object,
                teamsRepo.Object,
                playersRepo.Object,
                fixturesFactory.Object,
                mailService.Object);

            // act
            fixtureService.AddFixtureEvent(fixtureId, fixtureEventType, minute, playerId);

            // assert
            fixtureRepo.Verify(r => r.Update(It.Is <Fixture>(f => f.ScoreAwayTeam == 1)));
        }
Пример #4
0
        public void AddCorrectFixtureEventToTargetFixturesEvents_WhenPlayerIdAndFixtureIdAreValid()
        {
            // arrange
            var fixtureRepo     = new Mock <IEfRepository <Fixture> >();
            var teamsRepo       = new Mock <IEfRepository <Team> >();
            var playersRepo     = new Mock <IEfRepository <Player> >();
            var fixturesFactory = new Mock <IFixturesFactory>();
            var mailService     = new Mock <IFixtureMailService>();

            var fixtureId        = Guid.NewGuid();
            var fixtureEventType = FixtureEventType.Goal;
            int minute           = 22;
            var playerId         = Guid.NewGuid();

            var players = new List <Player>()
            {
                new Player()
                {
                    Id = playerId
                }
            };

            playersRepo.Setup(pr => pr.All).Returns(players.AsQueryable());

            var fixtures = new List <Fixture>()
            {
                new Fixture()
                {
                    Id            = fixtureId,
                    FixtureEvents = new List <FixtureEvent>(),
                    HomeTeam      = new Team()
                    {
                        Players = players
                    },
                }
            }.AsQueryable();

            fixtureRepo.Setup(x => x.All).Returns(fixtures);

            var fixtureEvent = new FixtureEvent();

            fixturesFactory.Setup(f => f.GetFixtureEvent(fixtureEventType, minute, players[0])).Returns(fixtureEvent);

            var fixtureService = new FixtureService(
                fixtureRepo.Object,
                teamsRepo.Object,
                playersRepo.Object,
                fixturesFactory.Object,
                mailService.Object);

            // act
            fixtureService.AddFixtureEvent(fixtureId, fixtureEventType, minute, playerId);

            // assert
            fixtureRepo.Verify(r => r.Update(It.Is <Fixture>(f => f.FixtureEvents.First() == fixtureEvent)));
        }