public void GivenAnAllocationService_WhenStartAllocation_ThenANewLocationIsReturned() { //Given Allocation startAllocation = new Allocation() { MemberPersonId = 1, ParkinglotId = 1 }; Parkinglot parkinglot = new Parkinglot() { Id = 1 }; _parkinglotService.GetOneParkinglot(1).Returns(parkinglot); _personService.GetById(1).Returns(_testPerson); _parkinglotService.ReduceAvailableParkingSpots(parkinglot).Returns(true); _allocationRepository.SaveNewAllocation(startAllocation).Returns(startAllocation); var allocationService = new AllocationService(_allocationRepository, _parkinglotService, _personService); //When var returnAllocation = allocationService.StartAllocation(startAllocation, _testPerson.LicensePlate); //Then Assert.IsType <Allocation>(returnAllocation); }
public Allocation StartAllocation(Allocation newAllocation, LicensePlate memberLicensePlate) { Parkinglot parkinglotToChange = _parkinglotService.GetOneParkinglot(newAllocation.ParkinglotId); Person person = GetPersonFromAllocation(newAllocation); if (person.LicensePlate.Equals(memberLicensePlate)) { _parkinglotService.ReduceAvailableParkingSpots(parkinglotToChange); } if (!person.LicensePlate.Equals(memberLicensePlate)) { throw new EntityNotValidException("Licenseplate", memberLicensePlate); } return(_allocationRepository.SaveNewAllocation(newAllocation)); }