コード例 #1
0
ファイル: RepositoryTests.cs プロジェクト: jodyunter/TeamApp
        public void ShouldExerciseCompetitionConfigRepositoryNHibernate()
        {
            var repo = new CompetitionConfigRepository(new RepositoryNHibernate <CompetitionConfig>());

            var config1 = new SeasonCompetitionConfig("Season 1", null, 1, 1, 12, 1, null, null, null, null, null, null);
            var config2 = new SeasonCompetitionConfig("Season 2", null, 1, 1, 12, 1, null, null, null, null, null, null);
            var config3 = new SeasonCompetitionConfig("Season 3", null, 1, 3, 12, 1, null, null, null, null, null, null);
            var config4 = new SeasonCompetitionConfig("Season 4", null, 5, 1, 12, 1, null, null, null, null, null, null);
            var config5 = new SeasonCompetitionConfig("Season 5", null, 5, 2, 12, 1, null, null, null, null, null, null);

            repo.Update(config1);
            repo.Update(config2);
            repo.Update(config3);
            repo.Update(config4);
            repo.Update(config5);

            //GetConfigByStartingDayAndYear
            StrictEqual(3, repo.GetConfigByStartingDayAndYear(1, 6).Count());
            StrictEqual(2, repo.GetConfigByStartingDayAndYear(1, 2).Count());
            //GetConfigByYear
            StrictEqual(5, repo.GetConfigByYear(8).Count());
            StrictEqual(4, repo.GetConfigByYear(2).Count());
        }
コード例 #2
0
ファイル: RepositoryTests.cs プロジェクト: jodyunter/TeamApp
        public void ShouldExerciseCompetitionRepositoryNHibernate()
        {
            var league1 = new League("NHL", 1, null);
            var league2 = new League("NHL 2", 1, null);

            var leagueRepo = new LeagueRepository(new RepositoryNHibernate <League>());

            var repo       = new CompetitionRepository(new RepositoryNHibernate <Competition>());
            var configRepo = new CompetitionConfigRepository(new RepositoryNHibernate <CompetitionConfig>());
            var cc0        = new SeasonCompetitionConfig("Test B", league1, 1, 1, null, 1, null, null, null, null, null, null);
            var cc1        = new SeasonCompetitionConfig("Test 1", league1, 1, 1, null, 1, null, null, null, null, null, null);
            var c1         = new Season(cc1, "Test 1", 5, null, null, null, null, true, false, 5, 55);
            var cc2        = new PlayoffCompetitionConfig("P3", league1, 2, 25, null, 1, null, null, null, new List <CompetitionConfig> {
                cc1, cc0
            }, null);
            var c8  = new Playoff(cc2, "P3", 5, 5, null, null, null, null, false, false, 5, 12);
            var c2  = new Season(null, "Test 2", 6, null, null, null, null, true, true, 5, 55);
            var c3  = new Season(null, "Test 3", 7, null, null, null, null, true, false, 5, 55);
            var c4  = new Season(cc1, "Test 4", 8, null, null, null, null, true, false, 5, 55);
            var c5  = new Season(null, "Test 5", 9, null, null, null, null, true, false, 5, 55);
            var c6  = new Playoff(null, "P1", 8, 5, null, null, null, null, true, false, 5, 12);
            var c7  = new Playoff(null, "P2", 8, 5, null, null, null, null, false, false, 5, 12);
            var c9  = new Playoff(cc2, "P9", 15, 5, null, null, null, null, false, false, 5, 12);
            var c10 = new Playoff(cc2, "P10", 15, 5, null, null, null, null, false, true, 5, 12);
            var c11 = new Playoff(cc2, "P11", 15, 5, null, null, null, null, true, false, 5, 12);
            var c12 = new Playoff(cc2, "P12", 15, 5, null, null, null, null, true, true, 5, 12);

            configRepo.Update(cc2);
            repo.Update(c1);
            repo.Update(c2);
            repo.Update(c3);
            repo.Update(c4);
            repo.Update(c5);
            repo.Update(c6);
            repo.Update(c7);
            repo.Update(c8);
            repo.Update(c9);
            repo.Update(c10);
            repo.Update(c11);
            repo.Update(c12);

            var c10Id = c10.Id;

            //getall
            StrictEqual(12, repo.GetAll().Count());
            //GetByNameAndYear
            Equal("P3", repo.GetByNameAndYear("P3", 5).Name);
            //GetByYear
            StrictEqual(3, repo.GetByYear(8).Count());
            //GetStartedAndUnfinishedCompetitionsByYear
            StrictEqual(2, repo.GetStartedAndUnfinishedCompetitionsByYear(8).Count());
            StrictEqual(0, repo.GetStartedAndUnfinishedCompetitionsByYear(6).Count());
            //IsCompetitionCompleteForYear
            False(repo.IsCompetitionCompleteForYear(5, cc1));
            False(repo.IsCompetitionCompleteForYear(12, cc1)); //hasn't even been created yet!
            //GetParentCompetitionsForCompetitionConfig
            var parents = repo.GetParentCompetitionsForCompetitionConfig(cc2, 5).ToList();

            StrictEqual(1, parents.Count());
            Equal("Test 1", parents[0].Name);
            Equal(5, parents[0].Year);
            //GetCompetitionsForCompetitionConfig
            var competitionForConfig = repo.GetCompetitionForCompetitionConfig(cc2, 5);

            Equal("P3", competitionForConfig.Name);
            Equal(5, competitionForConfig.Year);

            var shouldBeNull = repo.GetCompetitionForCompetitionConfig(cc0, 5);

            Null(shouldBeNull);

            //IEnumerable<Competition> GetByLeagueAndYear(int leagueId, int year)
            StrictEqual(2, repo.GetByLeagueAndYear(league1.Id, 5).Count());
            StrictEqual(1, repo.GetByLeagueAndYear(league1.Id, 8).Count());
            StrictEqual(0, repo.GetByLeagueAndYear(league2.Id, 15).Count());

            //IEnumerable<Competition> GetByLeagueAndYear(int leagueId, int year, bool started, bool finished)

            Equal("P9", repo.GetByLeagueAndYear(league1.Id, 15, false, false).First().Name);
            Equal("P10", repo.GetByLeagueAndYear(league1.Id, 15, false, true).First().Name);
            Equal("P11", repo.GetByLeagueAndYear(league1.Id, 15, true, false).First().Name);
            Equal("P12", repo.GetByLeagueAndYear(league1.Id, 15, true, true).First().Name);

            //IEnumerable<CompetitionSimpleViewModel> GetCompetitionsByYear(int year);
            Single(repo.GetByYear(9));
            StrictEqual(2, repo.GetByYear(5).Count());

            //Competition GetCompetition(long id);
            Equal("P10", repo.Get(c10Id).Name);
        }