public void ReturnsLeagues()
        {
            //Arrange

            var service     = new Mock <TeamService>();
            var teamService = new Mock <ITeamService>();
            var handler     = new Mock <IMatchHandler>();
            var options     = TestUtils.GetOptions(nameof(ReturnsLeagues));

            using (var arrangeContext = new FMDbContext(options))
            {
                var league = new League()
                {
                    Name = "Test",
                    Id   = 1
                };
                arrangeContext.Leagues.Add(league);
                arrangeContext.SaveChanges();
            }
            //Act,Assert
            using (var assertContext = new FMDbContext(options))
            {
                var sut     = new LeagueService(assertContext, teamService.Object, handler.Object);
                var leagues = sut.ShowAllLeagues().ToList();
                Assert.AreEqual(leagues.Count(), 1);
                Assert.AreEqual(leagues[0].Name, "Test");
            }
        }
Ejemplo n.º 2
0
        public void CreateMatches_IfLeagueHasMatches_ReturnCollectionOfMatches()
        {
            var teamService = new Mock <ITeamService>();
            var handler     = new Mock <IMatchHandler>();
            var match       = new Mock <Match>();
            var options     = TestUtils.GetOptions(nameof(CreateMatches_IfLeagueHasMatches_ReturnCollectionOfMatches));
            var league      = new League()
            {
                Name = "l"
            };
            var matchesMock = new List <Match>()
            {
                match.Object
            };

            handler.Setup(h => h.CreateMatches(league)).Returns(matchesMock);
            using (var arrangeContext = new FMDbContext(options))
            {
                arrangeContext.Leagues.Add(league);
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new FMDbContext(options))
            {
                var sut     = new LeagueService(assertContext, teamService.Object, handler.Object);
                var matches = sut.CreateMatches("l");
                Assert.AreEqual(0, matches.Count());
            }
        }
Ejemplo n.º 3
0
        public void ReturnsManager()
        {
            //Arrange
            var teamService = new Mock <ITeamService>();
            var options     = TestUtils.GetOptions(nameof(ReturnsManager));
            var firstName   = "Hristo";
            var lastName    = "Konov";
            var nationality = "Bulgarian";


            using (var arrangeContext = new FMDbContext(options))
            {
                var manager = new Manager()
                {
                    FirstName   = firstName,
                    LastName    = lastName,
                    Nationality = nationality
                };
                arrangeContext.Managers.Add(manager);
                arrangeContext.SaveChanges();
            }
            //Act,Assert
            using (var assertContext = new FMDbContext(options))
            {
                var sut     = new ManagerService(assertContext, teamService.Object);
                var manager = sut.RetrieveManager(firstName, lastName);

                Assert.AreEqual(manager.FirstName, firstName);
                Assert.AreEqual(manager.LastName, lastName);
                Assert.AreEqual(manager.Nationality, nationality);
            }
        }
Ejemplo n.º 4
0
        public void ReturnTeam()
        {
            //Arrange
            var playerService = new Mock <IPlayerService>();
            var options       = TestUtils.GetOptions(nameof(ReturnTeam));
            var teamName      = "Cunami";
            var teamCity      = "Sofia";

            //Act,Assert
            using (var arrangeContext = new FMDbContext(options))
            {
                arrangeContext.Teams.Add(new Team()
                {
                    Name = teamName, City = teamCity
                });
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new FMDbContext(options))
            {
                var sut  = new TeamService(assertContext, playerService.Object);
                var team = sut.ShowTeam(teamName, teamCity);
                Assert.AreEqual(team.Name, teamName);
                Assert.AreEqual(team.City, teamCity);
            }
        }
        public void Throws_PlayerAlreadyRetired()
        {
            //Arrange
            var teamName      = "Cunami";
            var teamCity      = "Sofia";
            var firstName     = "Hristo";
            var lastName      = "Konov";
            var playerService = new Mock <IPlayerService>();
            var player        = new Mock <Player>();

            player.SetupAllProperties();
            player.Object.FirstName = firstName;
            player.Object.LastName  = lastName;
            player.Object.IsDeleted = true;
            var options = TestUtils.GetOptions(nameof(Throws_PlayerAlreadyRetired));

            playerService.Setup(p => p.RetrievePlayer(firstName, lastName)).Returns(player.Object);//new List<Match>(){match.Object}
            using (var arrangeContext = new FMDbContext(options))
            {
                arrangeContext.Teams.Add(new Team()
                {
                    Name = teamName, City = teamCity
                });

                arrangeContext.SaveChanges();
            }
            //Act,Assert
            using (var assertContext = new FMDbContext(options))
            {
                var sut = new TeamService(assertContext, playerService.Object);
                var ex  = Assert.ThrowsException <EntityDoesntExistsException>(() => sut.BuyPlayer(teamName, teamCity, firstName, lastName));
                Assert.AreEqual(ex.Message, "Player already retired");
            }
        }
Ejemplo n.º 6
0
 public MatchService(FMDbContext context, ITeamService teamService,
                     ILeagueService leagueService, IMatchHandler matchHandler)
 {
     this.context       = context ?? throw new ArgumentNullException(nameof(context));
     this.teamService   = teamService;
     this.leagueService = leagueService;
     this.matchHandler  = matchHandler;
 }
Ejemplo n.º 7
0
        public void ReturnsNoTeam()
        {
            //Arrange
            var playerService = new Mock <IPlayerService>();
            var options       = TestUtils.GetOptions(nameof(ReturnsNoTeam));
            var teamName      = "Cunami";
            var teamCity      = "Sofia";

            //Act,Assert
            using (var arrangeContext = new FMDbContext(options))
            {
                var sut  = new TeamService(arrangeContext, playerService.Object);
                var team = sut.RetrieveTeam(teamName, teamCity);

                Assert.IsNull(team);
            }
        }
Ejemplo n.º 8
0
        public void ReturnsTeam()
        {
            //Arrange
            var playerService = new Mock <IPlayerService>();
            var options       = TestUtils.GetOptions(nameof(ReturnsTeam));
            var teamName      = "Cunami";
            var teamCity      = "Sofia";
            var country       = "Bulgaria";
            var owner         = "Hristo Konov";
            var manager       = new Manager()
            {
                FirstName   = "Hristo",
                LastName    = "Konov",
                Nationality = "Bulgarian",
                TeamId      = 1
            };

            using (var arrangeContext = new FMDbContext(options))
            {
                arrangeContext.Teams.Add(new Team()
                {
                    Name    = teamName,
                    City    = teamCity,
                    Country = country,
                    Owner   = owner,
                    Id      = 1
                });
                arrangeContext.Managers.Add(manager);
                arrangeContext.SaveChanges();
            }
            //Act,Assert
            using (var arrangeContext = new FMDbContext(options))
            {
                var sut  = new TeamService(arrangeContext, playerService.Object);
                var team = sut.RetrieveTeam(teamName, teamCity);

                Assert.AreEqual(team.Name, teamName);
                Assert.AreEqual(team.City, teamCity);
                Assert.AreEqual(team.Country, country);
                Assert.AreEqual(team.Owner, owner);
                Assert.AreEqual(1, arrangeContext.Teams.Count());
                Assert.AreEqual(team.Manager.FirstName, manager.FirstName);
                Assert.AreEqual(team.Manager.LastName, manager.LastName);
            }
        }
        public void TeamBudgetChanged()
        {
            //Arrange
            var teamName      = "Cunami";
            var teamCity      = "Sofia";
            var firstName     = "Hristo";
            var lastName      = "Konov";
            var playerService = new Mock <IPlayerService>();

            var player = new Mock <Player>();

            player.SetupAllProperties();
            player.Object.FirstName = firstName;
            player.Object.LastName  = lastName;
            player.Object.IsDeleted = false;
            player.Object.TeamId    = null;
            player.Object.Price     = 20;
            var options = TestUtils.GetOptions(nameof(TeamBudgetChanged));

            playerService.Setup(p => p.RetrievePlayer(firstName, lastName)).Returns(player.Object);
            using (var arrangeContext = new FMDbContext(options))
            {
                arrangeContext.Teams.Add(new Team()
                {
                    Name = teamName, City = teamCity, Budget = 50, Id = 1
                });

                arrangeContext.SaveChanges();
            }
            //Act,Assert
            using (var arrangeContext = new FMDbContext(options))
            {
                var sut  = new TeamService(arrangeContext, playerService.Object);
                var team = sut.BuyPlayer(teamName, teamCity, firstName, lastName);

                Assert.AreEqual(30, team.Budget);
                Assert.IsInstanceOfType(team, typeof(Team));
                Assert.AreEqual(teamName, team.Name);
                Assert.AreEqual(teamCity, team.City);
                Assert.AreEqual(1, arrangeContext.Teams.Count());
            }
        }
Ejemplo n.º 10
0
      public void ReturnManager()
      {
          //Arrange
          var teamService = new Mock <ITeamService>();
          var options     = TestUtils.GetOptions(nameof(ReturnManager));
          var firstName   = "Hristo";
          var lastName    = "Konov";
          var nationality = "Bulgarian";

          //Act,Assert
          using (var assertContext = new FMDbContext(options))
          {
              var sut     = new ManagerService(assertContext, teamService.Object);
              var manager = sut.CreateManager(firstName, lastName, nationality);

              Assert.AreEqual(manager.FirstName, firstName);
              Assert.AreEqual(manager.LastName, lastName);
              Assert.AreEqual(manager.Nationality, nationality);
              Assert.AreEqual(1, assertContext.Managers.Count());
          }
      }
Ejemplo n.º 11
0
        public void ResetTeamData_ResetPoints_ReturnZero()
        {
            var team = new Mock <Team>();

            team.SetupAllProperties();
            team.Object.Points = 1;

            var teamService = new Mock <ITeamService>();
            var handler     = new Mock <IMatchHandler>();

            var options = TestUtils.GetOptions(nameof(ResetTeamData_ResetPoints_ReturnZero));

            using (var assertContext = new FMDbContext(options))
            {
                var sut = new LeagueService(assertContext, teamService.Object, handler.Object);

                sut.ResetTeamData(team.Object);

                Assert.AreEqual(team.Object.Points, 0);
            }
        }
Ejemplo n.º 12
0
        public void RetrieveLeague_WhenExecuted_FirstOrDefaultReturnNull()
        {
            var teamService = new Mock <ITeamService>();
            var handler     = new Mock <IMatchHandler>();

            using (var arrangeContext = new FMDbContext(TestUtils.GetOptions(nameof(RetrieveLeague_WhenExecuted_FirstOrDefaultReturnNull))))
            {
                arrangeContext.Leagues.Add(new League()
                {
                    Name = "League"
                });
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new FMDbContext(TestUtils.GetOptions(nameof(RetrieveLeague_WhenExecuted_FirstOrDefaultReturnNull))))
            {
                var sut = new LeagueService(assertContext, teamService.Object, handler.Object);
                var res = sut.RetrieveLeague("L");
                Assert.IsNull(res);
            }
        }
Ejemplo n.º 13
0
        public void ReturnsTeams()
        {
            //Arrange
            var playerService = new Mock <IPlayerService>();
            var options       = TestUtils.GetOptions(nameof(ReturnsTeams));
            var teamName      = "Cunami";
            var teamCity      = "Sofia";
            var country       = "Bulgaria";
            var owner         = "Hristo Konov";
            var league        = new League()
            {
                Name = "Test",
                Id   = 1
            };
            var team = new Team()
            {
                Name     = teamName,
                City     = teamCity,
                Country  = country,
                Owner    = owner,
                LeagueId = 1
            };

            using (var arrangeContext = new FMDbContext(options))
            {
                arrangeContext.Leagues.Add(league);
                arrangeContext.Teams.Add(team);
                arrangeContext.SaveChanges();
            }
            //Act,Assert
            using (var assertContext = new FMDbContext(options))
            {
                var sut   = new TeamService(assertContext, playerService.Object);
                var teams = sut.RetrieveLeagueTeams(league);
                Assert.AreEqual(1, teams.Count);
                Assert.AreEqual(teamName, teams[0].Name);
                Assert.AreEqual(teamCity, teams[0].City);
            }
        }
Ejemplo n.º 14
0
        public void ShowMatches_IfLeagueDoesntExists_ThrowEntityDoesntExistsException()
        {
            var teamService = new Mock <ITeamService>();
            var handler     = new Mock <IMatchHandler>();

            var options = TestUtils.GetOptions(nameof(ShowMatches_IfLeagueDoesntExists_ThrowEntityDoesntExistsException));

            using (var context = new FMDbContext(options))
            {
                var league = new League();
                league.Name = "Primera";
                context.Leagues.Add(league);
                context.SaveChanges();
            }

            using (var context = new FMDbContext(options))
            {
                var sut = new LeagueService(context, teamService.Object, handler.Object);

                Assert.ThrowsException <EntityDoesntExistsException>(() => sut.ShowAllMatches("Premier"));
            }
        }
        public void ReturnsTeamRating()
        {
            //Arrange
            var playerService = new Mock <IPlayerService>();
            var options       = TestUtils.GetOptions(nameof(ReturnsTeamRating));
            var teamName      = "Cunami";
            var teamCity      = "Sofia";
            var country       = "Bulgaria";
            var owner         = "Hristo Konov";
            var player        = new Mock <Player>();

            player.SetupAllProperties();
            player.Object.Rating = 100;
            var team = new Team()
            {
                Name    = teamName,
                City    = teamCity,
                Country = country,
                Owner   = owner
            };

            playerService.Setup(p => p.RetrieveTeamPlayers(team))
            .Returns(new List <Player>()
            {
                player.Object
            });
            using (var arrangeContext = new FMDbContext(options))
            {
                arrangeContext.Teams.Add(team);
                arrangeContext.SaveChanges();
            }
            //Act,Assert
            using (var assertContext = new FMDbContext(options))
            {
                var sut    = new TeamService(assertContext, playerService.Object);
                var rating = sut.RetrieveTeamRatings(team);
                Assert.AreEqual(rating, 100);
            }
        }
Ejemplo n.º 16
0
        public void ReturnsManager()
        {
            //Arrange
            var teamService = new Mock <ITeamService>();
            var options     = TestUtils.GetOptions(nameof(ReturnsManager));
            var firstName   = "Hristo";
            var lastName    = "Konov";
            var nationality = "Bulgarian";
            var team        = new Mock <Team>();
            var manager     = new Manager()
            {
                FirstName   = firstName,
                LastName    = lastName,
                Nationality = nationality,
                TeamId      = 1
            };

            team.Object.Name    = "Cunami";
            team.Object.City    = "Sofia";
            team.Object.Id      = 1;
            team.Object.Manager = manager;
            teamService.Setup(t => t.RetrieveTeam("Cunami", "Sofia")).Returns(team.Object);
            using (var arrangeContext = new FMDbContext(options))
            {
                arrangeContext.Managers.Add(manager);
                arrangeContext.SaveChanges();
            }
            //Act,Assert
            using (var assertContext = new FMDbContext(options))
            {
                var sut         = new ManagerService(assertContext, teamService.Object);
                var managerTest = sut.FireManager(firstName, lastName, "Cunami", "Sofia");


                Assert.IsNull(managerTest.TeamId);
                Assert.IsNull(team.Object.Manager);
            }
        }
Ejemplo n.º 17
0
        public void ReturnAndCreateTeam()
        {
            //Arrange
            var playerService = new Mock <IPlayerService>();
            var options       = TestUtils.GetOptions(nameof(ReturnAndCreateTeam));
            var teamName      = "Cunami";
            var teamCity      = "Sofia";
            var country       = "Bulgaria";
            var owner         = "Hristo Konov";

            //Act,Assert
            using (var arrangeContext = new FMDbContext(options))
            {
                var sut  = new TeamService(arrangeContext, playerService.Object);
                var team = sut.CreateTeam(teamName, teamCity, country, owner);

                Assert.AreEqual(team.Name, teamName);
                Assert.AreEqual(team.City, teamCity);
                Assert.AreEqual(team.Country, country);
                Assert.AreEqual(team.Owner, owner);
                Assert.AreEqual(1, arrangeContext.Teams.Count());
            }
        }
Ejemplo n.º 18
0
        public void UnitOfWorkDisposeTest()
        {
            IDataContext context    = new FMDbContext();
            IUnitOfWork  unitOfWork = new UnitOfWork(null, context);

            // opening connection
            unitOfWork.BeginTransaction();
            unitOfWork.Commit();

            // calling dispose 1st time
            unitOfWork.Dispose();
            var isDisposed = (bool)GetInstanceField(typeof(UnitOfWork), unitOfWork, "_disposed");

            Assert.IsTrue(isDisposed);

            // calling dispose 2nd time, should not throw any excpetions
            unitOfWork.Dispose();
            context.Dispose();

            // calling dispose 3rd time, should not throw any excpetions
            context.Dispose();
            unitOfWork.Dispose();
        }
Ejemplo n.º 19
0
        public void RetrieveLeague_WhenExecuted_ReturnLeague()
        {
            var teamService = new Mock <ITeamService>();
            var handler     = new Mock <IMatchHandler>();
            var options     = TestUtils.GetOptions(nameof(RetrieveLeague_WhenExecuted_ReturnLeague));

            using (var arrangeContext = new FMDbContext(options))
            {
                var league = new League()
                {
                    Name = "League"
                };
                arrangeContext.Leagues.Add(league);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new FMDbContext(options))
            {
                var sut = new LeagueService(assertContext, teamService.Object, handler.Object);
                var ex  = sut.RetrieveLeague("League");
                Assert.IsInstanceOfType(ex, typeof(League));
            }
        }
Ejemplo n.º 20
0
        public void Throws_TeamDoesntHaveMoneyToBuyPlayer()
        {
            //Arrange
            var teamName      = "Cunami";
            var teamCity      = "Sofia";
            var firstName     = "Hristo";
            var lastName      = "Konov";
            var playerService = new Mock <IPlayerService>();

            var player = new Mock <Player>();

            player.SetupAllProperties();
            player.Object.FirstName = firstName;
            player.Object.LastName  = lastName;
            player.Object.IsDeleted = false;
            player.Object.TeamId    = null;
            player.Object.Price     = 20;
            var options = TestUtils.GetOptions(nameof(Throws_TeamDoesntHaveMoneyToBuyPlayer));

            playerService.Setup(p => p.RetrievePlayer(firstName, lastName)).Returns(player.Object);
            using (var arrangeContext = new FMDbContext(options))
            {
                arrangeContext.Teams.Add(new Team()
                {
                    Name = teamName, City = teamCity, Budget = 0
                });

                arrangeContext.SaveChanges();
            }
            //Act,Assert
            using (var assertContext = new FMDbContext(options))
            {
                var sut = new TeamService(assertContext, playerService.Object);
                var ex  = Assert.ThrowsException <ArgumentOutOfRangeException>(() => sut.BuyPlayer(teamName, teamCity, firstName, lastName));
                Assert.AreEqual(ex.ParamName, $"Team doesn't have enogh money to buy {firstName} {lastName}");
            }
        }
        public void CreateLeague_IfLeagueIsReturned_ReturnLeague()
        {
            var teamService = new Mock <ITeamService>();
            var handler     = new Mock <IMatchHandler>();

            using (var arrangeContext = new FMDbContext(TestUtils.GetOptions(nameof(CreateLeague_IfLeagueIsReturned_ReturnLeague))))
            {
                arrangeContext.Leagues.Add(new League()
                {
                    Name = "League"
                });
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new FMDbContext(TestUtils.GetOptions(nameof(CreateLeague_IfLeagueIsReturned_ReturnLeague))))
            {
                var sut    = new LeagueService(assertContext, teamService.Object, handler.Object);
                var ex     = sut.CreateLeague("League1");
                var league = assertContext.Leagues.FirstOrDefault(l => l.Name == "League1");

                //Assert.IsInstanceOfType(ex, typeof(League));
                Assert.IsNotNull(league);
            }
        }
Ejemplo n.º 22
0
 //[Ignore]
 public void Initialize()
 {
     context = new FMDbContext();
 }
Ejemplo n.º 23
0
 public TeamService(FMDbContext context, IPlayerService playerService)
 {
     this.context       = context ?? throw new ArgumentNullException(nameof(context));
     this.playerService = playerService;
 }
Ejemplo n.º 24
0
 public ManagerService(FMDbContext context, ITeamService teamService)
 {
     this.context     = context ?? throw new ArgumentNullException(nameof(context));
     this.teamService = teamService;
 }
Ejemplo n.º 25
0
 public PlayerService(FMDbContext context)
 {
     this.context = context ?? throw new ArgumentNullException(nameof(context));
 }