public void Setup() { var builder = new ConfigurationBuilder() .AddJsonFile("testsettings.json", false, true) .AddEnvironmentVariables(); _configuration = builder.Build(); //string connStr =_configuration.GetConnectionString("LorryLogAPIContext"); string testData = _configuration.GetSection("TestFiles")["vehicle"]; //var options = new DbContextOptionsBuilder<LorryLogAPIContext>() // .UseSqlServer(connStr) // .Options; var options = new DbContextOptionsBuilder <LorryLogAPIContext>() .UseInMemoryDatabase(databaseName: "LorryLog") .Options; _context = new LorryLogAPIContext(options); _controller = new VehiclesController(_context); string testPath = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory)) + testData; string json = File.ReadAllText(testPath); testTrucks = JsonSerializer.Deserialize <List <Vehicle> >(json); }
public VehiclesController(LorryLogAPIContext context) { _context = context; }