public bool StopAllocation(int allocationDtoMemberPeronId, string allocationDtoId) { Allocation stopAllocation = _allocationRepository.GetAllocationById(allocationDtoId); if (stopAllocation == null) { throw new EntityNotFoundException("CheckAllocationExist", "Allocation", stopAllocation.Id); } if (stopAllocation.Status != StatusAllocation.Active) { throw new EntityNotValidException("StatusAllocation", stopAllocation); } if (stopAllocation.MemberPersonId != allocationDtoMemberPeronId) { throw new EntityNotValidException("MemberAllocation", stopAllocation); } stopAllocation.Status = StatusAllocation.Passive; stopAllocation.EndTime = DateTime.Now; //stopAllocation.Parkinglot.AvailablePlaces++; _parkinglotService.AddAvailableParkingSpots(stopAllocation.Parkinglot); return(_allocationRepository.UpdateAllocation(stopAllocation)); }
public void GivenAnAllocationService_WhenStopAllocation_ThenReturnTrue() { //Given Parkinglot parkinglot = new Parkinglot() { Id = 1 }; Allocation stopAllocation = new Allocation() { MemberPersonId = 1, ParkinglotId = 1, Status = StatusAllocation.Active, Parkinglot = parkinglot }; _parkinglotService.AddAvailableParkingSpots(stopAllocation.Parkinglot).Returns(true); _allocationRepository.GetAllocationById("AllocationID").Returns(stopAllocation); _allocationRepository.UpdateAllocation(stopAllocation).Returns(true); var allocationService = new AllocationService(_allocationRepository, _parkinglotService, _personService); //When var result = allocationService.StopAllocation(1, "AllocationID"); //Then Assert.True(result); }