title: C# Nunit and Running same database populate everytime before test
body: <p>I have an Entity Framework DB Context file.
  How would I setup the DBContext, and run SetUp everytime (to have clean populated database) before running a test? It cannot see the dbcontext in the NUnit tests.</p>
  
  <p><strong>Electronics DB Context file</strong></p>
  
  <pre><code>public partial class ElectronicsContext : DbContext
  {
      public ElectronicsContext()
      {
      }
  
      public ElectronicsContext(DbContextOptions&lt;ElectronicsContext&gt; options)
          : base(options)
      {
      }
  
      public virtual DbSet&lt;Product&gt; Product { get; set; }
      public virtual DbSet&lt;ProductCategory&gt; ProductCategory { get; set; }
  </code></pre>
  
  <p><strong>Nunit SetUp</strong></p>
  
  <pre><code>public class TestClass
  {
  
      [SetUp]
      public void TestProducts()
      {
          var options = new DbContextOptionsBuilder&lt;ElectronicsContext&gt;()
              .UseInMemoryDatabase(databaseName: "Products Test")
              .Options;
  
          using (var context = new ElectronicsContext(options))
          {
              context.Product.Add(new Product { ProductId = 1, ProductName = "TV", ProductDescription = "TV testing", ImageLocation = "test" , ProductCategoryId = 2});
              context.SaveChanges();
          }
      }
  </code></pre>
  
  <p><strong>Error Message here</strong></p>
  
  <pre><code>The name 'context' does not exist in the current context    
  
      [Test]
      public void TestProductRepository()
      {
          ProductRepository productRepository = new ProductRepository(context);
          Assert.AreEqual("TV", productRepository.GetById(1).ProductName);
      }
  }
  </code></pre>
  
  <p>Alternative Idea for SetUp was not working either:</p>
  
  <pre><code>    [SetUp]
      public void TestProducts()
      {
          var options = new DbContextOptionsBuilder&lt;ElectronicsContext&gt;()
              .UseInMemoryDatabase(databaseName: "Products Test")
              .Options;
  
          ElectronicsContext context = new ElectronicsContext(options);
  </code></pre>