Ejemplo n.º 1
0
        public void SetLeagueStatusToCompletedAndReturnAllCompletedLeagues()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "CompletedLeagues_Leagues_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService   = new TownsService(dbContext);
            var leaguesService = new LeaguesService(dbContext, townsService);

            for (int i = 1; i <= 5; i++)
            {
                leaguesService.CreateLeague($"League{i}", $"Description{i}", DateTime.UtcNow.AddDays(i), DateTime.UtcNow.AddDays(i * i), "Sofia");
            }

            var leagues = dbContext.Leagues.ToList();

            foreach (var league in leagues)
            {
                leaguesService.SetLeagueStatusToCompleted(league.Id);
            }

            var completedLeagues = leaguesService.AllCompletedLeagues <CompletedLeagueViewModel>().ToList();

            var completedLeaguesCount = completedLeagues.Count;

            var expectedCompletedLeaguesCount = 5;

            Assert.AreEqual(expectedCompletedLeaguesCount, completedLeaguesCount);
        }
Ejemplo n.º 2
0
        public void SetLeagueStatusShouldReturnCompletedStatus()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "SetCompletedStatus_Leagues_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService   = new TownsService(dbContext);
            var leaguesService = new LeaguesService(dbContext, townsService);

            leaguesService.CreateLeague($"LeagueC", $"Description", DateTime.UtcNow.AddDays(3), DateTime.UtcNow.AddMonths(3), "Varna");

            var league = dbContext.Leagues.FirstOrDefault(n => n.Name == "LeagueC");

            leaguesService.SetLeagueStatusToCompleted(league.Id);

            var expectedLeagueStatus = "Completed";

            Assert.AreEqual(expectedLeagueStatus, league.Status.ToString());
        }
Ejemplo n.º 3
0
        public void CreateTrophyShouldNotReturnNull()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateTrophy_Trophies_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService = new TownsService(dbContext);

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var town = townsService.CreateTown("Sofia");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var leaguesService     = new LeaguesService(dbContext, townsService);
            var teamsService       = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);
            var teamLeaguesService = new TeamLeaguesService(dbContext, teamsService, leaguesService);
            var trophiesService    = new TrophiesService(dbContext, teamLeaguesService);

            teamsService.CreateTeam("TeamWinner", "TWR", user.UserName);
            var team = dbContext.Teams.FirstOrDefault(t => t.Name == "TeamWinner");

            leaguesService.CreateLeague("League", "Desc", DateTime.UtcNow.AddDays(7), DateTime.UtcNow.AddMonths(2), "Sofia");
            var league = dbContext.Leagues.FirstOrDefault(l => l.Name == "League");

            leaguesService.SetLeagueStatusToCompleted(league.Id);

            var teamLeague = new TeamLeague
            {
                Team   = team,
                League = league
            };

            dbContext.TeamsLeagues.Add(teamLeague);
            dbContext.SaveChanges();

            trophiesService.CreateTrophy(league.Id);

            var hasTeamTrophy = team.Trophies.Any();

            Assert.True(hasTeamTrophy);
        }