Exemplo n.º 1
0
        public async Task CreateAsyncShouldSuccessfullyCreateTournament()
        {
            // Arrange
            var dbContext = Testing.CreateDatabaseContext();
            var mapper    = Testing.CreateMapper();

            var moderatorTournamentService = new ModeratorTournamentService(dbContext, mapper);

            // Act
            var startDate = DateTime.Now.AddDays(1);
            await moderatorTournamentService.CreateAsync(
                "TestTournament", PrizeType.Money, startDate, 1);

            // Assert
            dbContext
            .Tournaments
            .Should()
            .Contain(g => g.Name == "TestTournament" &&
                     g.Prize == PrizeType.Money &&
                     g.StartDate == startDate &&
                     g.GameId == 1);
        }
        public async Task TotalAsyncShouldReturnTeamsCount()
        {
            // Arrage
            var dbContext = Testing.CreateDatabaseContext();
            var mapper    = Testing.CreateMapper();

            await dbContext.AddRangeAsync(
                new Team { Id = 1 },
                new Team { Id = 2 },
                new Team { Id = 3 });

            await dbContext.SaveChangesAsync();

            var teamService = new TeamService(dbContext, mapper);

            // Act
            var result = await teamService.TotalAsync();

            // Assert
            result
            .Should()
            .Be(3);
        }
        public async Task DetailsAsyncShouldReturnTeamDetailsModel()
        {
            // Arrage
            var dbContext = Testing.CreateDatabaseContext();
            var mapper    = Testing.CreateMapper();

            await dbContext
            .AddAsync(new Game { Id = 1, Name = "GameTest" });

            await dbContext
            .AddAsync(new User { Id = "1", UserName = "******" });

            await dbContext
            .AddRangeAsync(
                new Team
            {
                Id        = 1,
                Name      = "Team Test",
                Image     = "testimage.test",
                Tag       = "Test",
                CaptainId = "1",
                Players   = new List <PlayerTeam>
                {
                    new PlayerTeam
                    {
                        PlayerId = "1",
                        TeamId   = 1
                    }
                },
                TournamentsWon = 0
            });

            await dbContext.SaveChangesAsync();

            var teamService = new TeamService(dbContext, mapper);

            // Act
            var result = await teamService.DetailsAsync(1);

            // Assert
            result
            .Id
            .Should()
            .Be(1);
            result
            .Name
            .Should()
            .Be("Team Test");
            result
            .Tag
            .Should()
            .Be("Test");
            result
            .Image
            .Should()
            .Be("testimage.test");
            result.Captain
            .Should()
            .Be("Tester");
            result
            .Players
            .Should()
            .Contain(p => p.Equals("Tester"));
        }