Example #1
0
        public async Task <CustomerVehicle> AddVehicleToCustomer(string registration, Guid customerId, Guid clientId)
        {
            var vehicles = await repo.FindAllByCustomer(customerId, clientId);

            var existing = vehicles.FirstOrDefault(x => x.Registration == registration);

            if (existing != null)
            {
                throw new Exception("Vehicle with this registration already exists");
            }

            var lookup = await vehicleData.GetVehicleData(registration);

            var vehicle = MapLookupToCustomerVehicle(lookup);
            var result  = await repo.Create(vehicle, customerId, clientId);

            return(result);
        }
        public async Task DeleteCustomerVehicle_Should_ReturnWithoutError()
        {
            // Arrange
            var v1 = new CustomerVehicle {
                CustomerId = Guid.NewGuid(), ClientId = Guid.NewGuid()
            };
            await repo.Create(v1, v1.CustomerId, v1.ClientId);

            var sut = new CustomerVehicleService(repo, new MockVehicleDataService());
            // Act
            var ex = await Record.ExceptionAsync(async() => await sut.DeleteCustomerVehicle(v1.Id, v1.CustomerId, v1.ClientId));

            // Assert
            Assert.Null(ex);
        }