コード例 #1
0
        public void NotEqualDifferentObjectWithDifferentValue()
        {
            var time1 = AvailabilityTime.CreateAvailabilityWithHours(DayOfWeek.Monday, new TimeSpan(1, 0, 0), new TimeSpan(2, 0, 0));
            var time2 = AvailabilityTime.CreateAvailabilityWithHours(DayOfWeek.Monday, new TimeSpan(1, 0, 0), new TimeSpan(2, 0, 1));

            Assert.NotEqual(time1, time2);
        }
コード例 #2
0
        public void NotThrowExceptionIfEqualOrMoreThanOneHour()
        {
            var start = new TimeSpan(1, 0, 0);
            var end   = new TimeSpan(2, 0, 0);

            _ = AvailabilityTime.CreateAvailabilityWithHours(DayOfWeek.Monday, start, end);
        }
コード例 #3
0
        public void ThrowExceptionIfLessThanOneHour()
        {
            var start = new TimeSpan(1, 0, 0);
            var end   = new TimeSpan(1, 59, 0);

            Assert.Throws <InvalidAvailabilityTimeException>(() =>
                                                             AvailabilityTime.CreateAvailabilityWithHours(DayOfWeek.Monday, start, end));
        }
コード例 #4
0
        public async Task ChangeToCorrectAvailability()
        {
            await CreateTestParkingSpaceInDb("ChangeToCorrectAvailability");

            using (var context = new ParkMateDbContext(GetNamedDbContextOptions("ChangeToCorrectAvailability")))
            {
                var monday    = AvailabilityTime.CreateUnavailableDay(DayOfWeek.Monday);
                var tuesday   = AvailabilityTime.CreateUnavailableDay(DayOfWeek.Tuesday);
                var wednesday = AvailabilityTime.CreateAvailabilityWithHours(
                    DayOfWeek.Wednesday,
                    new TimeSpan(12, 0, 0),
                    new TimeSpan(13, 0, 0));
                var thursday = AvailabilityTime.CreateAvailabilityWithHours(
                    DayOfWeek.Thursday,
                    new TimeSpan(14, 0, 0),
                    new TimeSpan(15, 0, 0));
                var friday = AvailabilityTime.CreateAvailabilityWithHours(
                    DayOfWeek.Friday,
                    new TimeSpan(16, 0, 0),
                    new TimeSpan(17, 0, 0));
                var saturday = AvailabilityTime.CreateAvailabilityWithHours(
                    DayOfWeek.Saturday,
                    new TimeSpan(18, 0, 0),
                    new TimeSpan(19, 0, 0));
                var sunday = AvailabilityTime.CreateAvailabilityWithHours(
                    DayOfWeek.Sunday,
                    new TimeSpan(20, 0, 0),
                    new TimeSpan(21, 0, 0));

                var times = new List <AvailabilityTime>()
                {
                    monday, tuesday, wednesday, thursday, friday, saturday, sunday
                };

                var repository = new ParkingSpaceRepository(context);

                var space   = context.ParkingSpaces.FirstOrDefault();
                var command = new EditParkingSpaceAvailabilityCommand(space.Id, times);
                var handler = new EditParkingSpaceAvailabilityCommandHandler(repository, new Mock <IMediator>().Object);

                await handler.Handle(command);

                Assert.NotNull(space.Availability);
                Assert.Equal(monday, space.Availability.Monday);
                Assert.Equal(tuesday, space.Availability.Tuesday);
                Assert.Equal(wednesday, space.Availability.Wednesday);
                Assert.Equal(thursday, space.Availability.Thursday);
                Assert.Equal(friday, space.Availability.Friday);
                Assert.Equal(saturday, space.Availability.Saturday);
                Assert.Equal(sunday, space.Availability.Sunday);
            }
        }
コード例 #5
0
        public async Task <IActionResult> EditAvailability(List <AvailableTimeDTO> days, int parkingSpaceId)
        {
            var updatedDays = days
                              .Select(d => AvailabilityTime
                                      .CreateAvailabilityWithHours(d.Day, d.AvailableFrom, d.AvailableTo))
                              .ToList();

            var command = new EditParkingSpaceAvailabilityCommand(parkingSpaceId, updatedDays);

            var result = await _mediator.Send(command);

            return(Index());
        }
コード例 #6
0
        public void ReturnTrueOnIsAvailableIfAvailable()
        {
            var availability = AvailabilityTime.CreateAvailabilityWithHours(DayOfWeek.Monday, new TimeSpan(1, 0, 0), new TimeSpan(2, 0, 0));

            Assert.True(availability.IsAvailable);
        }
コード例 #7
0
        public void ReturnFalseOnIsAvailable24HoursIfNot24Hours()
        {
            var availability = AvailabilityTime.CreateAvailabilityWithHours(DayOfWeek.Monday, new TimeSpan(1, 0, 0), new TimeSpan(2, 0, 0));

            Assert.False(availability.IsAvailable24Hours());
        }