public async Task Should_add_parkingLot_when_add_parkingLot_with_unique_name_via_parkingLotService()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotContext context = scopedServices.GetRequiredService <ParkingLotContext>();
            var parkingLotDto         = GenerateParkingLotDto();

            ParkingLotService parkingLotService = new ParkingLotService(context);
            var parkingLotName = await parkingLotService.AddParkingLot(parkingLotDto);

            var foundParkingLot = await context.ParkingLots.FirstOrDefaultAsync(parkingLotEntity => parkingLotEntity.Name == parkingLotName);

            Assert.Equal(1, context.ParkingLots.Count());
            Assert.Equal(parkingLotDto.Name, foundParkingLot.Name);
        }
コード例 #2
0
ファイル: AllocationTests.cs プロジェクト: merken/ParkShark
        public async Task AllocationGetAllShouldReturnPassive()
        {
            using (var context = await NewParkSharkInMemoryTestContext())
            {
                await AllocationTestData(context.ParkSharkDbContext);

                var parkingLotService = new ParkingLotService(context.ParkSharkDbContext);
                var memberService     = new MemberService(context.ParkSharkDbContext);
                var allocationService =
                    new AllocationService(context.ParkSharkDbContext, memberService, parkingLotService);

                var allocations = await allocationService.GetAllocations(status : AllocationStatus.Passive);

                Assert.AreEqual(2, allocations.Count());
            }
        }
        public async Task Should_get_parkingLot_when_get_parkingLot_by_name_via_parkingLotService()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotContext context = scopedServices.GetRequiredService <ParkingLotContext>();
            var parkingLotDto         = GenerateParkingLotDto();

            ParkingLotService parkingLotService = new ParkingLotService(context);

            var parkingLotName = await parkingLotService.AddParkingLot(parkingLotDto);

            var foundParkingLot = await parkingLotService.GetParkingLotByName(parkingLotName);

            Assert.Equal(1, context.ParkingLots.Count());
            Assert.Equal(parkingLotDto.Name, foundParkingLot.Name);
        }
        public async Task Should_update_parkingLot_capacity_when_update_parkingLot_by_name_via_parkingLotService()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotContext context       = scopedServices.GetRequiredService <ParkingLotContext>();
            var parkingLotCapacityUpdateDto = new UpdateParkingLotCapacityDto(10);

            ParkingLotService parkingLotService = new ParkingLotService(context);

            var parkingLotDto  = GenerateParkingLotDto();
            var parkingLotName = await parkingLotService.AddParkingLot(parkingLotDto);

            var foundParkingLot = await parkingLotService.UpdateParkingLotCapacity(parkingLotName, parkingLotCapacityUpdateDto);

            Assert.Equal(parkingLotCapacityUpdateDto.Capacity, foundParkingLot.Capacity);
        }
        public async Task Should_Add_ParkingLot_Successfully()
        {
            //given
            var parkingLot        = GenerateParkingLotDtoInstance();
            var dbContext         = GetContext();
            var parkingLotService = new ParkingLotService(dbContext);

            //when
            await parkingLotService.AddParkingLotAsync(parkingLot);

            //then
            Assert.Equal(1, dbContext.ParkingLots.Count());

            var actualParkingLot = await dbContext.ParkingLots.FirstOrDefaultAsync(lot => lot.Name == parkingLot.Name);

            Assert.Equal(parkingLot, new ParkingLotDto(actualParkingLot));
        }
コード例 #6
0
ファイル: AllocationTests.cs プロジェクト: merken/ParkShark
        public async Task AllocationShouldBeStopped_Fails_On_Passive()
        {
            using (var context = await NewParkSharkInMemoryTestContext())
            {
                var parkingLotService = new ParkingLotService(context.ParkSharkDbContext);
                var memberService     = new MemberService(context.ParkSharkDbContext);
                var allocationService =
                    new AllocationService(context.ParkSharkDbContext, memberService, parkingLotService);

                var now        = DateTime.Now;
                var allocation = await allocationService.CreateAllocation(new Allocation(1, 1, new LicensePlate("VXK014", "BE"), now));

                await allocationService.StopAllocation(allocation.Id, 1);

                await Assert.ThrowsExceptionAsync <AllocationException>(async() => await allocationService.StopAllocation(allocation.Id, 1));
            }
        }
        public async Task Should_update_parkingLot_Successfully_Via_Service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context           = scopedServices.GetRequiredService <ParkingLotDbContext>();
            ParkingLotService   parkingLotService = new ParkingLotService(context);

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.SaveChanges();
            var update    = new UpdateParkingLotDto(50);
            var addReturn = await parkingLotService.AddParkingLot(parkingLotDto1);

            var updateReturn = await parkingLotService.UpdateParkingLot(addReturn, update);

            Assert.Equal(50, updateReturn.Capacity);
        }
コード例 #8
0
        public CommandExecutorFactory(ParkingLotService parkingLotService)
        {
            _commands.Add(CreateParkingLotCommandExecutor.CommandName,
                          new CreateParkingLotCommandExecutor(parkingLotService));

            _commands.Add(ParkCommandExecutor.CommandName,
                          new ParkCommandExecutor(parkingLotService));

            _commands.Add(LeaveCommandExecutor.CommandName,
                          new LeaveCommandExecutor(parkingLotService));

            _commands.Add(ExitCommandExecutor.CommandName,
                          new ExitCommandExecutor(parkingLotService));

            _commands.Add(StatusCommandExecutor.CommandName,
                          new StatusCommandExecutor(parkingLotService));
        }
コード例 #9
0
        public void TilfoejeEnBilTilParkeringspladsen_Ved_Ankomst()
        {
            var regNr      = "12345678";
            var car        = A.Fake <ICar>();
            var parkingLot = A.Fake <IParkingLot>();

            A.CallTo(() => car.RegistrationNumber).Returns(regNr);
            A.CallTo(() => parkingLot.Cars).Returns(new List <ICar>
            {
                car
            });

            var sut = new ParkingLotService(parkingLot);

            sut.Arrive(car);

            Assert.Contains(parkingLot.Cars, a => a.RegistrationNumber == regNr);
        }
        public async Task Should_get_x_parkingLots_for_page_y_Via_Service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context           = scopedServices.GetRequiredService <ParkingLotDbContext>();
            ParkingLotService   parkingLotService = new ParkingLotService(context);

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.SaveChanges();
            var addReturn1 = await parkingLotService.AddParkingLot(parkingLotDto1);

            var addReturn2 = await parkingLotService.AddParkingLot(parkingLotDto2);

            var getAllReturn = await parkingLotService.GetByPageSizeAndIndex(1, 1);

            Assert.Equal(1, getAllReturn.Count);
        }
コード例 #11
0
        public async Task Should_get_parkingLots_when_give_pageIndex_Test()
        {
            var scope                       = Factory.Services.CreateScope();
            var scopeServices               = scope.ServiceProvider;
            ParkingLotDbContext context     = scopeServices.GetRequiredService <ParkingLotDbContext>();
            ParkingLotDto       parkingLot1 = new ParkingLotDto();

            parkingLot1.Name     = "345";
            parkingLot1.Capacity = 0;
            parkingLot1.Location = "southRoad";

            ParkingLotService parkingLotService = new ParkingLotService(context);
            var name1 = await parkingLotService.AddParkingLot(parkingLot1);

            var actualParkingLots = await parkingLotService.GetParkingLotByPageIndex(2);

            Assert.Equal(new List <ParkingLotDto>(), actualParkingLots);
        }
コード例 #12
0
ファイル: AllocationTests.cs プロジェクト: merken/ParkShark
        public async Task AllocationShouldBeCreated_Active()
        {
            using (var context = await NewParkSharkInMemoryTestContext())
            {
                var parkingLotService = new ParkingLotService(context.ParkSharkDbContext);
                var memberService     = new MemberService(context.ParkSharkDbContext);
                var allocationService =
                    new AllocationService(context.ParkSharkDbContext, memberService, parkingLotService);

                var now        = DateTime.Now;
                var allocation = await allocationService.CreateAllocation(new Allocation(1, 1, new LicensePlate("VXK014", "BE"), now));

                var allocationInDb = await context.ParkSharkDbContext.Allocations.FindAsync(allocation.Id);

                Assert.AreEqual(AllocationStatus.Active, allocation.Status);
                Assert.AreEqual(AllocationStatus.Active, allocationInDb.Status);
            }
        }
コード例 #13
0
ファイル: AllocationTests.cs プロジェクト: merken/ParkShark
        public async Task AllocationShouldFail_Validations()
        {
            using (var context = await NewParkSharkInMemoryTestContext())
            {
                var parkingLotService = new ParkingLotService(context.ParkSharkDbContext);
                var memberService     = new MemberService(context.ParkSharkDbContext);
                var allocationService =
                    new AllocationService(context.ParkSharkDbContext, memberService, parkingLotService);

                var now         = DateTime.Now;
                var allocation1 = await allocationService.CreateAllocation(new Allocation(1, 1, new LicensePlate("VXK014", "BE"), now));

                var allocation2 = await allocationService.CreateAllocation(new Allocation(1, 1, new LicensePlate("VXK014", "BE"), now));

                await Assert.ThrowsExceptionAsync <ValidationException <Allocation> >(async() => await allocationService.CreateAllocation(new Allocation(1, 1, new LicensePlate("VXK914", "BE"), now)));

                await Assert.ThrowsExceptionAsync <AllocationException>(async() => await allocationService.CreateAllocation(new Allocation(1, 1, new LicensePlate("VXK014", "BE"), now)));
            }
        }
コード例 #14
0
        public async Task Should_create_a_new_parkingLot_when_give_name_capacity_and_location_Test()
        {
            var scope                        = Factory.Services.CreateScope();
            var scopeServices                = scope.ServiceProvider;
            ParkingLotDbContext context      = scopeServices.GetRequiredService <ParkingLotDbContext>();
            ParkingLotDto       paringLotDto = new ParkingLotDto();

            paringLotDto.Name     = "123";
            paringLotDto.Capacity = 0;
            paringLotDto.Location = "southRoad";

            ParkingLotService parkingLotService = new ParkingLotService(context);
            await parkingLotService.AddParkingLot(paringLotDto);

            Assert.Equal(1, context.ParkingLots.Count());
            var createdParkingLot = await context.ParkingLots.FirstOrDefaultAsync(item => item.Name == paringLotDto.Name);

            Assert.Equal(paringLotDto, new ParkingLotDto(createdParkingLot));
        }
コード例 #15
0
        public void FjerneBilenFraParkeringspladsen_Ved_ForladPladsen()
        {
            var regNr      = "12345678";
            var car        = A.Fake <ICar>();
            var parkingLot = A.Fake <IParkingLot>();

            A.CallTo(() => car.RegistrationNumber).Returns(regNr);
            A.CallTo(() => parkingLot.Cars).Returns(new List <ICar>
            {
                car
            });


            var sut = new ParkingLotService(parkingLot);

            sut.Leave(car);

            Assert.DoesNotContain(parkingLot.Cars, a => a.RegistrationNumber == regNr);
        }
        public async Task Should_get_parkingLot_Successfully_by_name_Via_Service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>();

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.SaveChanges();
            ParkingLotService parkingLotService = new ParkingLotService(context);
            await parkingLotService.AddParkingLot(parkingLotDto1);

            var getByName = await parkingLotService.GetByName("IBM");

            var parkingLotDto1String = JsonConvert.SerializeObject(parkingLotDto1);
            var getByNameString      = JsonConvert.SerializeObject(getByName);

            Assert.Equal(parkingLotDto1String, getByNameString);
        }
        public async Task Should_add_car_successfully_when_position_available_via_service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>();

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.Orders.RemoveRange(context.Orders);
            context.Cars.RemoveRange(context.Cars);
            context.SaveChanges();
            ParkingLotService parkingLotService = new ParkingLotService(context);
            CarService        carService        = new CarService(context);
            var addParkingLotReturn             = await parkingLotService.AddParkingLot(parkingLotDto1);

            await carService.AddCar(addParkingLotReturn, carDto1);

            Assert.Equal(1, context.Cars.Count());
        }
        public async Task Should_update_order_status_to_close_when_car_left_via_service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>();

            context.Orders.RemoveRange(context.Orders);
            context.SaveChanges();
            ParkingLotService parkingLotService = new ParkingLotService(context);
            OrderService      orderService      = new OrderService(context);

            parkingLotService.AddParkingLot(parkingLotDto1);
            UpdateOrderDto updateOrderDto = new UpdateOrderDto("closed");
            var            addOrderNumber = await orderService.AddOrder(orderDto1);

            var orderDto = await orderService.UpdateOrder(addOrderNumber, updateOrderDto);

            Assert.Equal("closed", orderDto.OrderStatus);
        }
        public async Task Should_not_delete_parkingLot_when_can_not_find_by_name_via_service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context           = scopedServices.GetRequiredService <ParkingLotDbContext>();
            ParkingLotService   parkingLotService = new ParkingLotService(context);

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.SaveChanges();
            var addReturn1 = await parkingLotService.AddParkingLot(parkingLotDto1);

            var addReturn2 = await parkingLotService.AddParkingLot(parkingLotDto2);

            await parkingLotService.DeleteParkingLot(addReturn1);

            await parkingLotService.DeleteParkingLot(addReturn1);

            Assert.Equal(1, context.ParkingLots.Count());
        }
コード例 #20
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);
            }
        }
        public async Task Should_updated_parkingLot_successfully()
        {
            //given
            var parkingLot        = GenerateParkingLotDtoInstance();
            var dbContext         = GetContext();
            var parkingLotService = new ParkingLotService(dbContext);
            var name = await parkingLotService.AddParkingLotAsync(parkingLot);

            //when
            var updatedCapacity = new CapacityDto()
            {
                Capacity = 2
            };
            var acatualParkingLots = await parkingLotService.UpdateCapacityAsync(name, updatedCapacity);

            //then
            Assert.Equal(updatedCapacity.Capacity.Value, acatualParkingLots.Capacity.Value);

            var actualParkingLot = await dbContext.ParkingLots.FirstOrDefaultAsync(lot => lot.Name == name);

            Assert.Equal(updatedCapacity.Capacity.Value, actualParkingLot.Capacity);
        }
コード例 #22
0
        public async Task ParkingLotsShouldBeReturned()
        {
            using (var context = await NewParkSharkInMemoryTestContext())
            {
                //Setup test data
                var division = new Division("Apple", "Apple Computer", "Steve Jobs");
                await context.ParkSharkDbContext.Divisions.AddAsync(division);

                await context.ParkSharkDbContext.ParkingLots.AddAsync(new ParkingLot(
                                                                          "PL1",
                                                                          division.Id,
                                                                          new Contact("Maarten", "00554433", null, "*****@*****.**", new Address("Streety", "Numbery", "Codey", "Namey")),
                                                                          BuildingTypes.Underground,
                                                                          15.55m,
                                                                          500
                                                                          ));

                await context.ParkSharkDbContext.ParkingLots.AddAsync(new ParkingLot(
                                                                          "PL2",
                                                                          division.Id,
                                                                          new Contact("John", "005777433", null, "*****@*****.**", new Address("Streety2", "Numbery3", "Codey4", "Namey5")),
                                                                          BuildingTypes.Underground,
                                                                          15.55m,
                                                                          500
                                                                          ));

                await context.ParkSharkDbContext.SaveChangesAsync();

                var parkingLotService = new ParkingLotService(context.ParkSharkDbContext);

                var controller  = new ParkingLotsController(context.Mapper, parkingLotService);
                var parkingLots = GetResult <IEnumerable <ParkingLotDto> >((await controller.GetParkingLots()));

                Assert.AreEqual(2, parkingLots.Count());
                Assert.AreEqual(parkingLots.ElementAt(0).Name, "PL1");
                Assert.AreEqual(parkingLots.ElementAt(1).Name, "PL2");
            }
        }
        public async Task Should_Get_Parking_Lots_By_Range()
        {
            // given
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotContext context = scopedServices.GetRequiredService <ParkingLotContext>();

            // when
            int           startindex     = 1;
            int           endindex       = 2;
            ParkingLotDto parkingLotDto1 = new ParkingLotDto()
            {
                Name     = "parkinglot1",
                Capacity = 4,
                Location = "Beijing",
            };
            ParkingLotDto parkingLotDto2 = new ParkingLotDto()
            {
                Name     = "parkinglot2",
                Capacity = 3,
                Location = "Beijing",
            };
            ParkingLotService parkingLotService = new ParkingLotService(context);
            await parkingLotService.AddParkingLot(parkingLotDto1);

            await parkingLotService.AddParkingLot(parkingLotDto2);

            var parkingLotList = await parkingLotService.GetParkingLotsByRange(startindex, endindex);

            var expectedList = new List <ParkingLotDto>()
            {
                parkingLotDto2
            };

            Assert.Equal(expectedList, parkingLotList);
        }
コード例 #24
0
        public async Task ParkingLotShouldBeCreated()
        {
            using (var context = await NewParkSharkInMemoryTestContext())
            {
                var parkingLotService    = new ParkingLotService(context.ParkSharkDbContext);
                var parkingLotController = new ParkingLotsController(context.Mapper, parkingLotService);

                var parkingLotDto = new CreateNewParkingLotDto
                {
                    Name                = "PL2",
                    DivisionId          = 1,
                    BuildingTypeId      = BuildingTypes.Underground,
                    Capacity            = 500,
                    PricePerHour        = 15.55m,
                    ContactName         = "Maarten Merken",
                    ContactMobilePhone  = "00486743685",
                    ContactEmail        = "*****@*****.**",
                    ContactStreet       = "Aardeweg",
                    ContactStreetNumber = "39",
                    ContactPostalCode   = "3582",
                    ContactPostalName   = "Koersel"
                };

                var newParkingLot  = GetResult <ParkingLotDto>(await parkingLotController.CreateNewParkingLot(parkingLotDto));
                var parkingLotInDb = await context.ParkSharkDbContext.ParkingLots.FindAsync(newParkingLot.Id);

                var contactInDb = await context.ParkSharkDbContext.Contacts.FindAsync(newParkingLot.Contact.Id);

                var buildingTypeInDb = await context.ParkSharkDbContext.Set <BuildingType>().FindAsync(newParkingLot.BuildingType.Id);

                Assert.AreEqual(parkingLotInDb.Capacity, parkingLotDto.Capacity);
                Assert.AreEqual(buildingTypeInDb.Name, nameof(BuildingTypes.Underground));
                Assert.AreEqual(contactInDb.Email, contactInDb.Email);
                Assert.AreEqual(contactInDb.Address.Street, contactInDb.Address.Street);
            }
        }
        public async Task Should_Add_New_Factory_Success_Via_Service()
        {
            // Given
            ParkingLotDto parkingLotDto = new ParkingLotDto();

            parkingLotDto.Name     = "ParkingLot_A";
            parkingLotDto.Capacity = 30;
            parkingLotDto.Location = "Beijing";

            ParkingLotDbContext context = GetContext();
            ParkingLotService   service = new ParkingLotService(context);

            // When
            await service.AddParkingLot(parkingLotDto);

            // Then
            Assert.Equal(1, context.ParkingLots.ToList().Count);

            var firstParkingLot = await context.ParkingLots.FirstOrDefaultAsync();

            Assert.Equal(parkingLotDto.Name, firstParkingLot.Name);
            Assert.Equal(parkingLotDto.Capacity, firstParkingLot.Capacity);
            Assert.Equal(parkingLotDto.Location, firstParkingLot.Location);
        }
 public ParkingLotController(ParkingLotService parkingLotService)
 {
     this.parkingLotService = parkingLotService;
 }
コード例 #27
0
 public CreateParkingLotCommandExecutor(ParkingLotService parkingLotService)
 {
     _parkingLotService = parkingLotService;
 }
 public ParkingLotController(ParkingLotService parkingLotService, ParkingLotContext parkingLotContext)
 {
     this.parkingLotService = parkingLotService;
     this.parkingLotContext = parkingLotContext;
 }
コード例 #29
0
 public ExitCommandExecutor(ParkingLotService parkingLotService)
 {
     _parkingLotService = parkingLotService;
 }
コード例 #30
0
 public ParkingLotController(ParkingLotService service, OrderService orderService)
 {
     this.service      = service;
     this.orderService = orderService;
 }