public async Task PutVehicle_WhenCalled_ReturnsBadRequest()
        {
            // Arrange
            var id = "ab2bd817";

            // Act
            var result = await _controller.PutVehicle(id, new VehicleResource { Id = id + "-" });

            // Assert
            Assert.NotNull(result);
            Assert.IsType <BadRequestResult>(result);
        }
        public async Task dUpdateTruck()
        {
            ActionResult <Vehicle> result = await _controller.GetVehicleName(testTrucks[1].Name);

            Vehicle truck = result.Value;

            truck.Model = testTrucks[2].Model;
            truck.Year  = testTrucks[2].Year;
            var res = await _controller.PutVehicle(truck.Id, truck);

            result = await _controller.GetVehicleId(truck.Id);

            Vehicle updatedTruck = result.Value;

            if (truck.Model == updatedTruck.Model && truck.Make == updatedTruck.Make && truck.Year == updatedTruck.Year)
            {
                Assert.Pass();
            }
            else
            {
                Assert.Fail();
            }
        }
        public async void VehiclesController_PutVehicle(Guid uuid, Vehicle vehicle)
        {
            try
            {
                var options = new DbContextOptionsBuilder <NMTFleetManagerContext>()
                              .UseSqlite(connection)
                              .Options;

                using (context = new NMTFleetManagerContext(options))
                {
                    context.Database.OpenConnection();
                    context.Database.EnsureCreated();
                }

                using (context = new NMTFleetManagerContext(options))
                {
                    SeedCollection seedCollection = SeedData.Seed();
                    context.Vehicles.AddRange(seedCollection.Vehicles);
                    context.SaveChanges();
                }

                using (context = new NMTFleetManagerContext(options))
                {
                    var controller   = new VehiclesController(context);
                    var actionResult = await controller.PutVehicle(uuid, vehicle);

                    bool validVehicle = await context.Vehicles.AnyAsync(v => v.Uuid == uuid && v.Uuid == vehicle.Uuid);

                    if (validVehicle)
                    {
                        Assert.IsType <NoContentResult>(actionResult);
                        var expected = vehicle;
                        var actual   = await context.Vehicles.SingleOrDefaultAsync(v => v.Uuid == uuid);

                        output.WriteLine(expected.ToString());
                        output.WriteLine(actual.ToString());

                        Assert.Equal(expected, actual);
                    }
                    else
                    {
                        Assert.IsNotType <NoContentResult>(actionResult);

                        var invalidVehicle = vehicle;
                        var actual         = await context.Vehicles.SingleOrDefaultAsync(v => v.Uuid == uuid);

                        if (actual == null)
                        {
                            actual = await context.Vehicles.SingleOrDefaultAsync(v => v.Uuid == vehicle.Uuid);

                            if (actual == null)
                            {
                                // since actual does not refer to any existing vehicle in the context, pass test
                                Assert.Null(actual);
                                return;
                            }
                        }

                        // ensure that the corresponding vehicle in the context has not been updated
                        Assert.NotEqual(invalidVehicle.Odometer, actual.Odometer);
                        Assert.NotEqual(invalidVehicle.Registration, actual.Registration);
                    }
                }
            }
            finally
            {
                connection.Close();
            }
        }