Esempio n. 1
0
        public void TestInit()
        {
            AutomapperConfig.CreateMapping();
            this.lanes = new List<Lane>();
            this.timeSlots = new List<TimeSlot>();
            DependencyResolverInitializer.Initialize();

            this._configuration = ServiceLocator.Current.GetInstance<Configuration>();
            this._sessionFactory = LocalSessionInitializer.Initialize();
            this._session = this._sessionFactory.GetCurrentSession();

            new SchemaExport(_configuration).Execute(true, true, false);

            // add some lanes and timeslots to the database
            // there are timeslots from 1000 hours => 2300 hours
            for (int i = 0; i < 10; i++)
            {
                var timeSlot = new TimeSlot() { Start = TimeSpan.FromHours(10 + i), End = TimeSpan.FromHours(11 + i) };
                this.timeSlots.Add(timeSlot);
                _session.Save(timeSlot);

                var lane = new Lane() { Name = (i + 1).ToString() };
                this.lanes.Add(lane);
                _session.Save(lane);
            }
        }
Esempio n. 2
0
        public void TestAddingSameTimeSlotReturnsFalse()
        {
            var slot1 = new TimeSlot { Start = TimeSpan.FromHours(10), End = TimeSpan.FromHours(11) };
            var slot2 = new TimeSlot { Start = TimeSpan.FromHours(11), End = TimeSpan.FromHours(12) };
            this._session.Save(slot1);
            this._session.Save(slot2);

            Reservation resv = new Reservation();
            Assert.That(resv.AddTimeSlot(slot1), Is.True);
            Assert.That(resv.AddTimeSlot(slot2), Is.True);
            Assert.That(resv.AddTimeSlot(slot2), Is.False);
        }
Esempio n. 3
0
        public void TestReservationCRUD()
        {
            var theLanes = new Lane[] {
                        new Lane {
                            Name = "1" },
                        new Lane {
                            Name = "2" },
                        new Lane {
                            Name = "3" }
                        };
            var theSlots = new TimeSlot[] {
                        new TimeSlot {
                            Start = new TimeSpan(13, 0, 0),
                            End = new TimeSpan(14, 0,0) },
                        new TimeSlot {
                            Start = new TimeSpan(14, 0, 0),
                            End = new TimeSpan(15, 0,0) },
                        new TimeSlot {
                            Start = new TimeSpan(15, 0, 0),
                            End = new TimeSpan(16, 0,0)}
                        };

            foreach (var lane in theLanes)
            {
                this._session.Save(lane);
            }
            foreach (var slot in theSlots)
            {
                this._session.Save(slot);
            }

            new PersistenceSpecification<Reservation>(this._session)
              .CheckProperty(c => c.Id, 1)
              .CheckProperty(c => c.Name, "John Doe")
              .CheckProperty(c => c.CreatedAt, DateTime.Now, new DateTimeEqualityComparer())
              .CheckProperty(c => c.NumberOfPlayers, 6)
              .CheckProperty(c => c.PhoneNumber, 12345678)
              .CheckProperty(c => c.PlayAt, DateTime.Now.AddDays(1), new DateTimeEqualityComparer())
              .CheckProperty(c => c.Status, ReservationStatus.Pending)
              .CheckReference(
                    c => c.Member,
                    new Member()
                    {
                        Email = "*****@*****.**",
                        DefaultNumberOfPlayers = 42,
                        DialCode = "+45",
                        Name = "John Doe",
                        Password = "******",
                        ReceiveNewsLetter = true,
                        Title = MemberTitle.Dr
                    })
               .CheckComponentList(
                    x => x.Lanes,
                    theLanes,(r, l) => {
                            r.AddLane(l);
                        })
              .CheckComponentList(
                    x => x.TimeSlots,
                   theSlots, (r, t) => {
                            r.AddTimeSlot(t);
                        })
              .VerifyTheMappings();
        }
Esempio n. 4
0
 public virtual bool AddTimeSlot(TimeSlot timeSlot)
 {
     if (this.timeSlots.Contains(timeSlot))
     {
         return false;
     }
     TimeSlots.Add(timeSlot);
     return true;
 }