コード例 #1
0
        public void Create_Tour_With_Competitions_And_Players()
        {
            var courseconfig = new Courseconfiguration
            {
                CourseMap   = "coursemap",
                CourseName  = "first",
                Description = "my first course"
            };

            courseconfig.AddHole(new Hole {
                Length = 100, Number = 1, Par = 3
            });
            courseconfig.AddHole(new Hole {
                Length = 86, Number = 2, Par = 3
            });
            courseconfig.AddHole(new Hole {
                Length = 149, Number = 3, Par = 4
            });

            var player1 = new Player
            {
                Email     = "*****@*****.**",
                FirstName = "firstname",
                LastName  = "lastname",
                Phone     = "08112233"
            };

            var player2 = new Player
            {
                Email     = "*****@*****.**",
                FirstName = "john",
                LastName  = "doe",
                Phone     = "08334422"
            };

            var competition = new Competition {
                Date = DateTime.UtcNow, Name = "dgt1"
            };

            competition.AddPlayer(new PlayerStatus {
                Player = player1, Status = PlayerCompetitionStatus.Registered
            });
            competition.AddPlayer(new PlayerStatus {
                Player = player2, Status = PlayerCompetitionStatus.Payed
            });

            competition.AddRound(new Round {
                Courseconfig = courseconfig, RoundNumber = 1
            });
            competition.AddRound(new Round {
                Courseconfig = courseconfig, RoundNumber = 2
            });

            var tour = new Tour {
                Year = "2015", Description = "testTour"
            };

            tour.AddCompetition(competition);

            Player dbPlayer1;
            Player dbPlayer2;
            Courseconfiguration dbCourseconfig;
            Tour dbTour;

            using (var session = NHibernateFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var pid1 = session.Save(player1);
                    var pid2 = session.Save(player2);
                    var cid  = session.Save(courseconfig);
                    var tid  = session.Save(tour);

                    dbPlayer1      = session.Get <Player>(pid1);
                    dbPlayer2      = session.Get <Player>(pid2);
                    dbCourseconfig = session.Get <Courseconfiguration>(cid);
                    dbTour         = session.Get <Tour>(tid);

                    session.Delete(dbPlayer1);
                    session.Delete(dbPlayer2);
                    session.Delete(dbCourseconfig);
                    session.Delete(dbTour);

                    transaction.Commit();
                }
            }

            Assert.AreEqual(player1, dbPlayer1);
            Assert.AreEqual(player2, dbPlayer2);
            Assert.AreEqual(courseconfig, dbCourseconfig);
            Assert.AreEqual(tour, dbTour);
        }