Beispiel #1
0
        public TeamValidatorTests()
        {
            #region *** Mocks ***

            var tenantContextMock = TestMocks.GetTenantContextMock();
            var appDbMock         = TestMocks.GetAppDbMock();

            var teamRepoMock = TestMocks.GetRepo <TeamRepository>();
            teamRepoMock
            .Setup(rep => rep.TeamNameExistsAsync(It.IsAny <TeamEntity>(), It.IsAny <CancellationToken>()))
            .Callback(() => { }).Returns((TeamEntity teamEntity, CancellationToken cancellationToken) =>
            {
                return(Task.FromResult(teamEntity.Id < 10 ? teamEntity.Name : null));
            });
            appDbMock.Setup(a => a.TeamRepository).Returns(teamRepoMock.Object);

            var dbContextMock = TestMocks.GetDbContextMock();
            dbContextMock.SetupAppDb(appDbMock);

            tenantContextMock.SetupDbContext(dbContextMock);

            _tenantContext = tenantContextMock.Object;

            _appDb = appDbMock.Object;

            #endregion
        }
Beispiel #2
0
        public TeamInRoundValidatorTests()
        {
            #region *** Mocks ***

            var tenantContextMock = TestMocks.GetTenantContextMock();
            var appDbMock         = TestMocks.GetAppDbMock();

            var roundsRepoMock = TestMocks.GetRepo <RoundRepository>();
            roundsRepoMock
            .Setup(rep => rep.GetRoundsWithTypeAsync(It.IsAny <PredicateExpression>(), It.IsAny <CancellationToken>()))
            .Callback(() => { }).Returns((PredicateExpression filter, CancellationToken cancellationToken) =>
            {
                var tournamentId = (long)((FieldCompareValuePredicate)filter[0].Contents).Value;

                return(Task.FromResult(new List <RoundEntity>(new [] { new RoundEntity {
                                                                           Id = 1, Name = "Round 1", TournamentId = tournamentId
                                                                       }, new RoundEntity {
                                                                           Id = 2, Name = "Round 2", TournamentId = tournamentId
                                                                       } })));
            });
            appDbMock.Setup(a => a.RoundRepository).Returns(roundsRepoMock.Object);

            var tournamentRepoMock = TestMocks.GetRepo <TournamentRepository>();
            tournamentRepoMock
            .Setup(rep => rep.GetTournamentAsync(It.IsAny <PredicateExpression>(), It.IsAny <CancellationToken>()))
            .Callback(() => { }).Returns((PredicateExpression filter, CancellationToken cancellationToken) =>
            {
                var tournamentId = (long)((FieldCompareValuePredicate)filter[0].Contents).Value;
                return(Task.FromResult(new TournamentEntity {
                    Id = tournamentId, Name = $"Tournament{tournamentId}", Description = $"DescriptionTournament{tournamentId}"
                }));
            });
            appDbMock.Setup(a => a.TournamentRepository).Returns(tournamentRepoMock.Object);

            var dbContextMock = TestMocks.GetDbContextMock();
            dbContextMock.SetupAppDb(appDbMock);
            tenantContextMock.SetupDbContext(dbContextMock);

            _tenantContext = tenantContextMock.Object;
            _appDb         = appDbMock.Object;

            #endregion
        }