public void should_park_to_parking_lot_with_higher_vacancy_rate(
            int parkingLot0Capacity,
            int parkingLot0OccupiedParkingSpace,
            int parkingLot1Capacity,
            int parkingLot1OccupiedParkingSpace,
            int chosenParkingLotIndex)
        {
            var parkingLot0 = new ParkingLotBuilder()
                              .WithCapacity(parkingLot0Capacity)
                              .WithOccupiedParkingSpace(parkingLot0OccupiedParkingSpace)
                              .Create();
            var parkingLot1 = new ParkingLotBuilder()
                              .WithCapacity(parkingLot1Capacity)
                              .WithOccupiedParkingSpace(parkingLot1OccupiedParkingSpace)
                              .Create();
            var parkingLots     = new[] { parkingLot0, parkingLot1 };
            var superParkingBoy = new SuperParkingBoy(parkingLots);
            var car             = new Car();

            var token = superParkingBoy.Park(car);

            var pickedCar = parkingLots[chosenParkingLotIndex].Pick(token);

            pickedCar.Should().BeSameAs(car);
        }
示例#2
0
        public ParkingLot FromParkingLotCreateToParkingLot(ParkingLotDTO_Create parkingLotDTO)
        {
            BuildingType buildingType;

            try
            {
                buildingType = (BuildingType)Enum.Parse(typeof(BuildingType), parkingLotDTO.Buildingtype);
            }
            catch
            {
                buildingType = BuildingType.AboveGround;
            }

            var parkingLot = ParkingLotBuilder.CreateNewParkingLot()
                             .WithCapacity(parkingLotDTO.Capacity)
                             .WithContactPerson(_contactPersonMapper.FromContactPersonDTOTOContactPerson(parkingLotDTO.ContactPerson))
                             .WithDivision(parkingLotDTO.DivisionID)
                             .WithName(parkingLotDTO.Name)
                             .WithPricePerHour(parkingLotDTO.PricePerHour)
                             .WithAddress(_adressMappers.DTOToAddress(parkingLotDTO.Address))
                             .WithBuildingType(buildingType)
                             .Build();

            return(parkingLot);
        }
示例#3
0
        public void GivenGetAllParkingLots_WhenRequestingAllParkingLots_ThenReturnListOfAllParkingLots()
        {
            using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase()))
            {
                var city = City.CreateCity(2050, "Antwerpen", "Belgium");

                var parkingLot1 = ParkingLotBuilder.CreateNewParkingLot()
                                  .WithName("test")
                                  .WithAddress(Address.CreateAddress("Parkinglotstraat", "20a", city))
                                  .WithContactPerson(ContactPerson.CreateNewContactPerson("Bas", "Adriaans", Address.CreateAddress("Contactpersoonstraat", "30", city), "*****@*****.**", "000000", ""))
                                  .WithCapacity(20)
                                  .WithDivision(Guid.NewGuid())
                                  .WithPricePerHour(4.5m)
                                  .Build();
                var parkingLot2 = ParkingLotBuilder.CreateNewParkingLot()
                                  .WithName("test2")
                                  .WithAddress(Address.CreateAddress("Parkinglotstraat", "20a", city))
                                  .WithContactPerson(ContactPerson.CreateNewContactPerson("Bas", "Adriaans", Address.CreateAddress("Contactpersoonstraat", "30", city), "*****@*****.**", "000000", ""))
                                  .WithCapacity(20)
                                  .WithDivision(Guid.NewGuid())
                                  .WithPricePerHour(4.5m)
                                  .Build();
                context.Set <ParkingLot>().Add(parkingLot1);
                context.Set <ParkingLot>().Add(parkingLot2);
                context.SaveChanges();

                var service = new ParkingLotService(context);
                var result  = context.ParkingLots.CountAsync();
                Assert.Equal(2, result.Result);
            }
        }
示例#4
0
        public void GivenGetSingleParkingLot_WhenRequestingSingleParkingLot_ReturnRequestedParkingLot()
        {
            using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase()))
            {
                var city       = City.CreateCity(2050, "Antwerpen", "Belgium");
                var service    = new ParkingLotService(context);
                var parkingLot = ParkingLotBuilder.CreateNewParkingLot()
                                 .WithName("test")
                                 .WithAddress(Address.CreateAddress("Parkinglotstraat", "20a", city))
                                 .WithContactPerson(ContactPerson.CreateNewContactPerson("Bas", "Adriaans", Address.CreateAddress("Contactpersoonstraat", "30", city), "*****@*****.**", "000000", ""))
                                 .WithCapacity(20)
                                 .WithDivision(Guid.NewGuid())
                                 .WithPricePerHour(4.5m)
                                 .Build();
                context.Set <ParkingLot>().Add(parkingLot);
                var id = parkingLot.ParkingLotID;
                context.SaveChanges();

                var result = service.GetSingleParkingLot(id);

                Assert.IsType <ParkingLot>(result);
                Assert.Equal(id, result.ParkingLotID);
                Assert.Equal("test", result.Name);
            }
        }
        public void should_report_when_manager_manages_one_parking_lot_and_different_parking_boys()
        {
            var parkingLot = new ParkingLotBuilder()
                             .WithCapacity(100)
                             .WithOccupiedParkingSpace(10)
                             .Create();
            var parkingBoy =
                new ParkingBoy(new ParkingLotBuilder().WithCapacity(200).WithOccupiedParkingSpace(20).Create());
            var smartParkingBoy =
                new SmartParkingBoy(new ParkingLotBuilder().WithCapacity(300).WithOccupiedParkingSpace(30).Create());
            var superParkingBoy = new SuperParkingBoy(
                new ParkingLotBuilder().WithCapacity(400).WithOccupiedParkingSpace(40).Create());
            var parkingManager  = new ParkingManager(parkingBoy, smartParkingBoy, superParkingBoy, parkingLot);
            var parkingDirector = new ParkingDirector(parkingManager);

            var actualReportText = parkingDirector.ParkingReport.ToString("markdown");

            actualReportText.Should().StartWith(
                "# M 100 1000" + NewLine +
                "* P 10 100");
            actualReportText.Should().Contain("## B 20 200" + NewLine +
                                              "* P 20 200");
            actualReportText.Should().Contain("## B 30 300" + NewLine +
                                              "* P 30 300");
            actualReportText.Should().Contain("## B 40 400" + NewLine +
                                              "* P 40 400");
        }
示例#6
0
        public void GivenCreateParkingLotDTOReturnFromParkingLot_WhenGivenParkinglotDTOReturnToCreate_ThenCreateParkingLotDTOReturn()
        {
            var              memstub     = Substitute.For <IMemberServices>();
            var              stubpark    = Substitute.For <IParkingLotMapper>();
            var              stubAddress = Substitute.For <IAddressMapper>();
            AddressMapper    addressmap  = new AddressMapper(new CityMapper(memstub));
            ParkingLotMapper parkmap     = new ParkingLotMapper(new AddressMapper(new CityMapper(memstub)), new ContactPersonMapper(new AddressMapper(new CityMapper(memstub))));

            var city          = City.CreateCity(2050, "Antwerpen", "Belgium");
            var contactPerson = ContactPerson.CreateNewContactPerson("lasr", "peelman", Address.CreateAddress("test", "5", city), "*****@*****.**", "5454548564", "5456456456");

            var parkinglot = ParkingLotBuilder.CreateNewParkingLot()
                             .WithBuildingType(BuildingType.AboveGround)
                             .WithCapacity(5)
                             .WithContactPerson(contactPerson)
                             .WithDivision(new Guid())
                             .WithName("lasr")
                             .WithPricePerHour(5.00M)
                             .WithAddress(Address.CreateAddress("test", "5", city))
                             .Build();

            var result = parkmap.FromParkingLotToParkingLotDTOReturn(parkinglot);

            Assert.IsType <ParkingLotDTO_Return>(result);
        }
        public void should_get_cannot_park_info_when_parking_lot_is_full()
        {
            var parkingLot = new ParkingLotBuilder()
                             .WithCapacity(1)
                             .WithOccupiedParkingSpace(1)
                             .Create();

            parkingLot.CanPark().Should().BeFalse();
        }
示例#8
0
        void should_report_when_manager_manages_one_parking_lot()
        {
            var parkingLot = ParkingLotBuilder.Build(2, 1);

            var parkingManager = new ParkingManager(parkingLot);

            Assert.Equal("M 1 2" + NewLine +
                         "  P 1 2", parkingManager.Report.ToString());
        }
        public void should_park_unsucccessfully_when_parking_lot_is_full()
        {
            var parkingLot = new ParkingLotBuilder()
                             .WithCapacity(1)
                             .WithOccupiedParkingSpace(1)
                             .Create();

            parkingLot.Invoking(p => p.Park(new Car()))
            .ShouldThrow <ParkingFailedException>()
            .WithMessage("No space.");
        }
        public void should_not_park_car_when_all_managed_parking_lots_are_full()
        {
            var parkingLot = new ParkingLotBuilder()
                             .WithCapacity(1)
                             .WithOccupiedParkingSpace(1)
                             .Create();
            var smartParkingBoy = new SmartParkingBoy(parkingLot);

            smartParkingBoy.Invoking(p => p.Park(new Car()))
            .ShouldThrow <ParkingFailedException>()
            .WithMessage("Cannot park at this moment.");
        }
        public void should_report_when_manager_manages_one_parking_lot()
        {
            var parkingLot = new ParkingLotBuilder()
                             .WithCapacity(2)
                             .WithOccupiedParkingSpace(1)
                             .Create();
            var parkingManager  = new ParkingManager(parkingLot);
            var parkingDirector = new ParkingDirector(parkingManager);

            parkingDirector.ParkingReport.ToString("markdown").Should().Be(
                "# M 1 2" + NewLine +
                "* P 1 2");
        }
        public void should_park_car_when_manages_multiple_parking_lots()
        {
            var fullParkingLot = new ParkingLotBuilder()
                                 .WithCapacity(1)
                                 .WithOccupiedParkingSpace(1)
                                 .Create();
            var parkingManager = new ParkingManager(fullParkingLot, new ParkingLot(1));
            var car            = new Car();

            var token     = parkingManager.Park(car);
            var pickedCar = parkingManager.Pick(token);

            pickedCar.Should().BeSameAs(car);
        }
示例#13
0
        public void GivenParkingLot_WhenPriceIsBelow0_ThenWholeObjectIsNull()
        {
            var city = City.CreateCity(2050, "Antwerpen", "Belgium");

            var parkinglot = ParkingLotBuilder.CreateNewParkingLot()
                             .WithName("Name")
                             .WithBuildingType(BuildingType.AboveGround)
                             .WithCapacity(2)
                             .WithAddress(Address.CreateAddress("test", "test", city))
                             .WithPricePerHour(-5)
                             .WithContactPerson(ContactPerson.CreateNewContactPerson("x", "x", Address.CreateAddress("x", "x", city), "*****@*****.**", "x", "x"))
                             .Build();

            Assert.Null(parkinglot);
        }
示例#14
0
        public void GivenParkingLot_WhenContactPersonIsNUllOrWhiteSpace_ThenWholeObjectIsNull()
        {
            var city = City.CreateCity(2050, "Antwerpen", "Belgium");

            var parkinglot = ParkingLotBuilder.CreateNewParkingLot()
                             .WithName("Name")
                             .WithBuildingType(BuildingType.AboveGround)
                             .WithCapacity(2)
                             .WithAddress(Address.CreateAddress("test", "test", city))
                             .WithPricePerHour(5)
                             .WithContactPerson(null)
                             .Build();

            Assert.Null(parkinglot);
        }
示例#15
0
        public void should_pick_the_right_car_successfully_when_manages_two_parking_lot()
        {
            var oneParkingLot = new ParkingLotBuilder()
                                .WithCapacity(1)
                                .WithOccupiedParkingSpace(1)
                                .Create();
            var anotherParkingLot = new ParkingLot(1);
            var parkingBoy        = new ParkingBoy(oneParkingLot, anotherParkingLot);
            var car   = new Car();
            var token = parkingBoy.Park(car);

            var pickedCar = parkingBoy.Pick(token);

            pickedCar.Should().BeSameAs(car);
        }
示例#16
0
        public void should_report_when_manager_manages_one_super_parking_boy()
        {
            var parkingLot = new ParkingLotBuilder()
                             .WithCapacity(2)
                             .WithOccupiedParkingSpace(1)
                             .Create();
            var parkingBoy      = new SuperParkingBoy(parkingLot);
            var parkingManager  = new ParkingManager(parkingBoy);
            var parkingDirector = new ParkingDirector(parkingManager);

            parkingDirector.ParkingReport.ToString().Should().Be(
                "M 1 2" + NewLine +
                "  B 1 2" + NewLine +
                "    P 1 2");
        }
示例#17
0
        public void should_park_successfully_when_one_parking_lot_is_full_but_another_is_not_full()
        {
            var oneParkingLot = new ParkingLotBuilder()
                                .WithCapacity(1)
                                .WithOccupiedParkingSpace(1)
                                .Create();
            var anotherParkingLot = new ParkingLot(1);
            var parkingBoy        = new ParkingBoy(oneParkingLot, anotherParkingLot);
            var car = new Car();

            var token = parkingBoy.Park(car);

            var pickedCar = anotherParkingLot.Pick(token);

            pickedCar.Should().BeSameAs(car);
        }
示例#18
0
        void should_report_when_manager_manages_one_parking_lot_and_different_parking_boys()
        {
            var parkingLot      = ParkingLotBuilder.Build(100, 10);
            var parkingBoy      = new ParkingBoy(ParkingLotBuilder.Build(200, 20));
            var smartParkingBoy = new SmartParkingBoy(ParkingLotBuilder.Build(300, 30));
            var superParkingBoy = new SuperParkingBoy(ParkingLotBuilder.Build(400, 40));
            var parkingManager  = new ParkingManager(parkingLot, parkingBoy, smartParkingBoy, superParkingBoy);

            Assert.Equal("M 100 1000" + NewLine +
                         "  P 10 100" + NewLine +
                         "  B 20 200" + NewLine +
                         "    P 20 200" + NewLine +
                         "  B 30 300" + NewLine +
                         "    P 30 300" + NewLine +
                         "  B 40 400" + NewLine +
                         "    P 40 400", parkingManager.Report.ToString());
        }
示例#19
0
        public void GivenHappyPath2_WhenAddingNewParkingLotToDb_ObjectIsAddedToDb()
        {
            using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase()))
            {
                var city = City.CreateCity(2050, "Antwerpen", "Belgium");

                var parkingLot = ParkingLotBuilder.CreateNewParkingLot()
                                 .WithName("test")
                                 .WithAddress(Address.CreateAddress("Parkinglotstraat", "20a", city))
                                 .WithContactPerson(ContactPerson.CreateNewContactPerson("Bas", "Adriaans", Address.CreateAddress("Contactpersoonstraat", "30", city), "*****@*****.**", "000000", ""))
                                 .WithCapacity(20)
                                 .WithDivision(Guid.NewGuid())
                                 .WithPricePerHour(4.5m)
                                 .Build();

                var service = new ParkingLotService(context);
                var result  = service.CreateParkingLot(parkingLot);

                Assert.Single(context.ParkingLots);
            }
        }