public async void VehiclesController_GetVehicleByUuid(Guid uuid) { 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 expected = await context.Vehicles.SingleOrDefaultAsync(v => v.Uuid == uuid); vehiclesController = new VehiclesController(context); var actionResult = await vehiclesController.GetVehicleByUuid(uuid); if (expected == null) { Assert.IsType <NotFoundResult>(actionResult.Result); } else { var okResult = actionResult.Result as OkObjectResult; var actual = okResult?.Value as Vehicle; Assert.Equal(expected, actual); } } } finally { connection.Close(); } }