예제 #1
0
        public void Schedule_HasChildValidator()
        {
            var rsv = new RoomScheduleValidator();
            var rv  = new RoomValidator(rsv);

            rv.ShouldHaveChildValidator(x => x.Schedule, typeof(RoomScheduleValidator));
        }
예제 #2
0
        public void Room_TwoSchedulesWithTimesThatDoOverlap_HasErrorMessage()
        {
            var rsv = new RoomScheduleValidator();
            var rv  = new RoomValidator(rsv);

            var schedule = new List <RoomSchedule> {
                new RoomSchedule {
                    Start = DateTime.Parse("2020-03-01 07:30"), End = DateTime.Parse("2020-03-01 14:00")
                },
                new RoomSchedule {
                    Start = DateTime.Parse("2020-03-01 13:30"), End = DateTime.Parse("2020-03-01 18:30")
                }
            };

            var room = new Room {
                RoomBooked = DateTime.Parse("2020-03-01"), Schedule = schedule
            };

            var validationResult = rv.TestValidate(room);

            //Assert.That(validationResult.Errors.Count, Is.EqualTo(1));
            //validationResult.ShouldHaveValidationErrorFor(x => x.Schedule)
            //    .WithErrorMessage("Schedule can not have overlapping times.");

            Assert.That(validationResult.Errors.Count, Is.EqualTo(2));
            validationResult.ShouldHaveValidationErrorFor(x => x.Schedule)
            .WithErrorMessage("Schedule 7:30 AM-2:00 PM overlaps another schedule.")
            .WithErrorMessage("Schedule 1:30 PM-6:30 PM overlaps another schedule.");
        }
예제 #3
0
        public void RoomBooked_NotSet_HasErrorMessage()
        {
            var rsv = new RoomScheduleValidator();
            var rv  = new RoomValidator(rsv);

            var room = new Room();

            rv.ShouldHaveValidationErrorFor(x => x.RoomBooked, room).WithErrorMessage("Booking can not be empty.");
        }
예제 #4
0
        public void Room_TwoSchedulesWithTimesThatAreContiguous_HasNoErrorMessage()
        {
            var rsv = new RoomScheduleValidator();
            var rv  = new RoomValidator(rsv);

            var schedule = new List <RoomSchedule> {
                new RoomSchedule {
                    Start = DateTime.Parse("2020-03-01 07:30"), End = DateTime.Parse("2020-03-01 13:30")
                },
                new RoomSchedule {
                    Start = DateTime.Parse("2020-03-01 13:30"), End = DateTime.Parse("2020-03-01 18:30")
                }
            };

            var room = new Room {
                RoomBooked = DateTime.Parse("2020-03-01"), Schedule = schedule
            };

            var validationResult = rv.TestValidate(room);

            Assert.That(validationResult.Errors.Count, Is.EqualTo(0));
        }