I am trying to locate the data type for DbContextOptionsBuilder.
I have an Entity Framework DBContext file. I setup an InMemory database with NUnit. How can I set this up without var? I know its best practice to have a clean database for each test, but just trying to learn, and have a database for multiple tests.
Electronics DBContext File
public partial class ElectronicsContext : DbContext
{
public ElectronicsContext()
{
}
public ElectronicsContext(DbContextOptions<ElectronicsContext> options)
: base(options)
{
}
public virtual DbSet<Product> Product { get; set; }
public virtual DbSet<ProductCategory> ProductCategory { get; set; }
NUnit Test
public class TestClass
{
[SetUp]
public void TestProducts()
{
// This Works
// var context = new DbContextOptionsBuilder<ElectronicsContext>()
// .UseInMemoryDatabase(databaseName: "ProductsTest")
// .Options;
// This does not work
DbContextOptionsBuilder<ElectronicsContext> context = new DbContextOptionsBuilder<ElectronicsContext>()
.UseInMemoryDatabase(databaseName: "ProductsTest")
.Options;
When Running this: I receive error below, however it works other way Moq and setting up DB Context
[Test]
public void TestProducts()
{
DbContextOptionsBuilder<ElectronicsContext> context = new DbContextOptionsBuilder<ElectronicsContext>()
context.Product.Add(new Product { ProductId = 1, ProductName = "TV", ProductDescription = "TV testing", ImageLocation = "test" });
context.SaveChanges();
Error: 'DbContextOptionsBuilder<ElectronicsContext>' does not contain a definition for 'Product' and no accessible extension method 'Product' accepting a first argument of type 'DbContextOptionsBuilder<ElectronicsContext>' could be found (are you missing a using directive or an assembly reference?)