Пример #1
0
        public async Task TestGetByIdAsyncWhitInvalidIdAndReturnsUnsuccess()
        {
            // Arrange
            var expected = new Response <StandingViewModel>(false, "Standing with the fetched id does not exist");

            _repositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(It.IsAny <Standing>()));
            var service = new StandingService(_repositoryMock.Object, _mapperMock.Object);
            // Act
            var result = await service.GetByIdAsync(It.IsAny <string>());

            // Assert
            _repositoryMock.Verify(x => x.GetByIdAsync(It.IsAny <string>()), Times.Once);
            result.Should().BeEquivalentTo(expected);
        }
Пример #2
0
        public async Task TestCreateAsync()
        {
            // Arrange
            string content    = File.ReadAllText($"DataTests{Path.DirectorySeparatorChar}StandingViewModel.json");
            var    expected   = JsonConvert.DeserializeObject <StandingViewModel>(content);
            var    tournament = new TournamentBuilder().Build();

            _repositoryMock.Setup(x => x.InsertOneAsync(It.IsAny <Standing>()))
            .Returns(Task.CompletedTask);
            _mapperMock.Setup(x => x.Map <StandingViewModel>(It.IsAny <Standing>()))
            .Returns(expected);
            var service = new StandingService(_repositoryMock.Object, _mapperMock.Object);
            // Act
            var result = await service.CreateAsync(tournament);

            // Assert
            _repositoryMock.Verify(x => x.InsertOneAsync(It.IsAny <Standing>()), Times.Once);
            _mapperMock.Verify(x => x.Map <StandingViewModel>(It.IsAny <Standing>()), Times.Once);
            result.Should().BeEquivalentTo(expected);
        }
Пример #3
0
        public async Task TestGetByIdAsyncWhitInvalidIdAndReturnsSuccess()
        {
            // Arrange
            string contentStanding = File.ReadAllText($"DataTests{Path.DirectorySeparatorChar}Standing.json");
            var    standing        = JsonConvert.DeserializeObject <Standing>(contentStanding);
            string content         = File.ReadAllText($"DataTests{Path.DirectorySeparatorChar}StandingViewModel.json");
            var    data            = JsonConvert.DeserializeObject <StandingViewModel>(content);
            var    expected        = new Response <StandingViewModel>(true, "Standing search successfully performed", data);

            _repositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(standing));
            _mapperMock.Setup(x => x.Map <StandingViewModel>(It.IsAny <Standing>()))
            .Returns(data);
            var service = new StandingService(_repositoryMock.Object, _mapperMock.Object);
            // Act
            var result = await service.GetByIdAsync(It.IsAny <string>());

            // Assert
            _repositoryMock.Verify(x => x.GetByIdAsync(It.IsAny <string>()), Times.Once);
            _mapperMock.Verify(x => x.Map <StandingViewModel>(It.IsAny <Standing>()), Times.Once);
            result.Should().BeEquivalentTo(expected);
        }
Пример #4
0
        public async void GetStanding(string circuito)
        {
            IsBusyStanding = true;
            Standing       = new List <Standing>();

            var standingService = new StandingService();

            Standing = await standingService.GetStanding(circuito);

            if (circuito.Equals("N"))
            {
                HasBordeVisita = Color.FromHex("#01579b");
                HasBordeCasa   = Color.Transparent;
            }
            else
            {
                HasBordeVisita = Color.Transparent;
                HasBordeCasa   = Color.FromHex("#01579b");
            }

            IsBusyStanding = false;
        }
 public StandingsController(DystirDBContext dystirDBContext, StandingService standingService)
 {
     _standingService = standingService;
     _dystirDBContext = dystirDBContext;
 }
Пример #6
0
        public StandingServiceTests()
        {
            var loggerMock = new Mock <ILogger <StandingService> >();

            _target = new StandingService(loggerMock.Object);
        }
        public void Initilaize()
        {
            MapperInitialize.Configure();

            options = new DbContextOptionsBuilder <ApplicationContext>()
                      .UseInMemoryDatabase(databaseName: "TestDataBase").Options;
            _applicationContext = new ApplicationContext(options);
            _standingService    = new StandingService(_applicationContext);
            _tableService       = new TableService(_applicationContext, _standingService);
            _matchService       = new MatchService(_applicationContext, _tableService);

            matches = new List <Match>()
            {
                new Match {
                    Id       = 1, LeagueTitle = "Test league", Matchday = 1, Group = "A",
                    HomeTeam = "Team 1", AwayTeam = "Team 2", KickoffAt = DateTime.Now, Score = "2:1"
                },
                new Match {
                    Id       = 2, LeagueTitle = "Test league", Matchday = 1, Group = "A",
                    HomeTeam = "Team 3", AwayTeam = "Team 4", KickoffAt = DateTime.Now, Score = "1:3"
                },
                new Match {
                    Id       = 3, LeagueTitle = "Test league", Matchday = 2, Group = "A",
                    HomeTeam = "Team 2", AwayTeam = "Team 3", KickoffAt = DateTime.Now, Score = "1:6"
                },
                new Match {
                    Id       = 4, LeagueTitle = "Test league", Matchday = 2, Group = "A",
                    HomeTeam = "Team 4", AwayTeam = "Team 1", KickoffAt = DateTime.Now.AddDays(-7), Score = "0:1"
                },
            };

            matchesDto = new List <MatchDto>()
            {
                new MatchDto {
                    LeagueTitle = "Test league", Matchday = 1, Group = "A",
                    HomeTeam    = "Team 1", AwayTeam = "Team 2", KickoffAt = DateTime.Now.ToString("s"), Score = "1:1"
                },
                new MatchDto {
                    LeagueTitle = "Test league", Matchday = 1, Group = "A",
                    HomeTeam    = "Team 3", AwayTeam = "Team 4", KickoffAt = DateTime.Now.ToString("s"), Score = "1:0"
                },
                new MatchDto {
                    LeagueTitle = "Test league", Matchday = 2, Group = "A",
                    HomeTeam    = "Team 2", AwayTeam = "Team 3", KickoffAt = DateTime.Now.ToString("s"), Score = "1:3"
                },
                new MatchDto {
                    LeagueTitle = "Test league", Matchday = 2, Group = "A",
                    HomeTeam    = "Team 4", AwayTeam = "Team 1", KickoffAt = DateTime.Now.ToString("s"), Score = "2:1"
                },
            };

            matchesDto2 = new List <MatchDto>()
            {
                new MatchDto {
                    LeagueTitle = "Test league", Matchday = 1, Group = "A",
                    HomeTeam    = "Team 1", AwayTeam = "Team 2", KickoffAt = DateTime.Now.ToString("s"), Score = "2:1"
                },
                new MatchDto {
                    LeagueTitle = "Test league", Matchday = 1, Group = "A",
                    HomeTeam    = "Team 3", AwayTeam = "Team 4", KickoffAt = DateTime.Now.ToString("s"), Score = "1:1"
                },
                new MatchDto {
                    LeagueTitle = "Test league", Matchday = 2, Group = "A",
                    HomeTeam    = "Team 2", AwayTeam = "Team 3", KickoffAt = DateTime.Now.ToString("s"), Score = "0:1"
                },
                new MatchDto {
                    LeagueTitle = "Test league", Matchday = 2, Group = "A",
                    HomeTeam    = "Team 4", AwayTeam = "Team 1", KickoffAt = DateTime.Now.ToString("s"), Score = "2:2"
                },
            };
        }
Пример #8
0
        public void Initialize()
        {
            MapperInitialize.Configure();

            options = new DbContextOptionsBuilder <ApplicationContext>()
                      .UseInMemoryDatabase(databaseName: "TestDataBase").Options;
            _applicationContext = new ApplicationContext(options);
            _standingService    = new StandingService(_applicationContext);
            _tableService       = new TableService(_applicationContext, _standingService);

            tables = new List <Table>
            {
                new Table
                {
                    Id       = 1, LeagueTitle = "Test league", Group = "A", Matchday = 1,
                    Standing = new List <Standing>
                    {
                        new Standing {
                            Id           = 1, Team = "Team 1", PlayedGames = 1, Points = 3, Goals = 3,
                            GoalsAgainst = 1, GoalDifference = 2, Win = 1, Lose = 0, Draw = 0
                        },
                        new Standing {
                            Id           = 2, Team = "Team 2", PlayedGames = 1, Points = 0, Goals = 1,
                            GoalsAgainst = 3, GoalDifference = -2, Win = 0, Lose = 1, Draw = 0
                        }
                    }
                },
                new Table()
                {
                    Id       = 2, LeagueTitle = "Test league", Group = "B", Matchday = 1,
                    Standing = new List <Standing>
                    {
                        new Standing {
                            Id           = 3, Team = "Team 3", PlayedGames = 1, Points = 1, Goals = 1,
                            GoalsAgainst = 1, GoalDifference = 0, Win = 0, Lose = 0, Draw = 1
                        },
                        new Standing {
                            Id           = 4, Team = "Team 4", PlayedGames = 1, Points = 1, Goals = 1,
                            GoalsAgainst = 1, GoalDifference = 0, Win = 0, Lose = 1, Draw = 1
                        }
                    }
                }
            };

            matches = new List <Match>()
            {
                new Match {
                    Id       = 1, LeagueTitle = "Test league", Matchday = 1, Group = "A",
                    HomeTeam = "Team 1", AwayTeam = "Team 2", KickoffAt = DateTime.Now, Score = "3:1"
                },
                new Match {
                    Id       = 2, LeagueTitle = "Test league", Matchday = 1, Group = "B",
                    HomeTeam = "Team 3", AwayTeam = "Team 4", KickoffAt = DateTime.Now, Score = "1:1"
                },
            };

            matchDto = new MatchDto
            {
                LeagueTitle = "Test league",
                Matchday    = 1,
                Group       = "B",
                HomeTeam    = "Team 3",
                AwayTeam    = "Team 4",
                KickoffAt   = DateTime.Now.ToString("s"),
                Score       = "1:1"
            };

            matchDto2 = new MatchDto
            {
                LeagueTitle = "Test league",
                Matchday    = 1,
                Group       = "B",
                HomeTeam    = "Team 3",
                AwayTeam    = "Team 4",
                KickoffAt   = DateTime.Now.ToString("s"),
                Score       = "1:3"
            };
        }