Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
            }
        }