コード例 #1
0
 public static async Task CreateTestParkingSpaceInDb(string name, string ownerName = "test-user")
 {
     using (var context = new ParkMateDbContext(GetNamedDbContextOptions(name)))
     {
         var command    = GetTestCreateParkingSpaceCommand(ownerName);
         var repository = new ParkingSpaceRepository(context);
         var handler    = new RegisterNewParkingSpaceCommandHandler(repository, new Mock <IMediator>().Object);
         await handler.Handle(command);
     }
 }
コード例 #2
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);
            }
        }
コード例 #3
0
        public async Task CreateNewParkingSpace()
        {
            await CreateTestParkingSpaceInDb("CreateNewParkingSpace");

            using (var context = new ParkMateDbContext(GetNamedDbContextOptions("CreateNewParkingSpace")))
            {
                Assert.Equal(1, context.ParkingSpaces.Count());
                var space = context.ParkingSpaces.Include(s => s.Availability).FirstOrDefault();

                Assert.NotNull(space.Availability);
                Assert.Equal(GetTestAddress(), space.Address);
                Assert.Equal(GetTestBookingRate(), space.BookingRate);
                Assert.Equal(GetTestDescription(), space.Description);
                Assert.Equal(GetTestAddress(), space.Address);
                Assert.Equal("test-user", space.OwnerId);
            }
        }
コード例 #4
0
        public async Task ChangeUnlistedSpaceToListed()
        {
            await CreateTestParkingSpaceInDb("SetParkingSpaceVisibilityShould");

            using (var context = new ParkMateDbContext(GetNamedDbContextOptions("SetParkingSpaceVisibilityShould")))
            {
                var  space         = context.ParkingSpaces.Include(s => s.Availability).FirstOrDefault();
                var  repository    = new ParkingSpaceRepository(context);
                var  command       = new SetParkingSpaceVisibilityCommand(space.Id, true);
                var  handler       = new SetParkingSpaceVisibilityCommandCommandHandler(repository, new Mock <IMediator>().Object);
                bool previousState = space.Availability.IsVisible;

                await handler.Handle(command);

                Assert.NotEqual(previousState, space.Availability.IsVisible);
                Assert.True(space.Availability.IsVisible);
            }
        }
コード例 #5
0
        public async Task ChangeParkingSpaceToCorrectBookingRate()
        {
            await CreateTestParkingSpaceInDb("EditParkingSpaceBookingRate");

            using (var context = new ParkMateDbContext(GetNamedDbContextOptions("EditParkingSpaceBookingRate")))
            {
                var space       = context.ParkingSpaces.FirstOrDefault();
                var repository  = new ParkingSpaceRepository(context);
                var bookingRate = new BookingRate(new Money(12), new Money(34));
                var command     = new EditParkingSpaceBookingRateCommand(space.Id, bookingRate);
                var handler     = new EditParkingSpaceBookingRateCommandHandler(repository, new Mock <IMediator>().Object);

                await handler.Handle(command);

                Assert.NotNull(space.BookingRate);
                Assert.NotEqual(GetTestBookingRate(), space.BookingRate);
                Assert.Equal(bookingRate, space.BookingRate);
            }
        }
コード例 #6
0
        public async Task ChangeToCorrectDescription()
        {
            await CreateTestParkingSpaceInDb("EditParkingSpaceDescription");

            using (var context = new ParkMateDbContext(GetNamedDbContextOptions("EditParkingSpaceDescription")))
            {
                var space       = context.ParkingSpaces.FirstOrDefault();
                var repository  = new ParkingSpaceRepository(context);
                var description = new ParkingSpaceDescription("New Test Title", "New Description", "newfile.jpg");
                var command     = new EditParkingSpaceDescriptionCommand(space.Id, description);
                var handler     = new EditParkingSpaceDescriptionCommandHandler(repository, new Mock <IMediator>().Object);

                await handler.Handle(command);

                Assert.NotNull(space.BookingRate);
                Assert.NotEqual(GetTestDescription(), space.Description);
                Assert.Equal(description, space.Description);
            }
        }
コード例 #7
0
        public async Task ChangeParkingSpaceToCorrectAddress()
        {
            await CreateTestParkingSpaceInDb("EditParkingSpaceAddress");

            using (var context = new ParkMateDbContext(GetNamedDbContextOptions("EditParkingSpaceAddress")))
            {
                var space      = context.ParkingSpaces.FirstOrDefault();
                var repository = new ParkingSpaceRepository(context);
                var address    = new Address("567 Test Road", "TestVille", "Tst", "56789", new Point(9, 10));
                var command    = new EditParkingSpaceAddressCommand(space.Id, address);
                var handler    = new EditParkingSpaceAddressCommandHandler(repository, new Mock <IMediator>().Object);

                await handler.Handle(command);

                Assert.NotNull(space.Address);
                Assert.NotEqual(GetTestAddress(), space.Address);
                Assert.Equal(address, space.Address);
            }
        }