public void HomeAboutTest() { ///////////////////////////CONNECTING TO THE ACTUAL DATABASW //var context = new DbContextOptionsBuilder<cSharpContext>().UseNpgsql("Host=localhost;Database=cSharp;Username=postgres;Password=4310;Persist Security Info=True"); ///////////////////////////IN MEMORY DATABASE //var optionsBuilder = new DbContextOptionsBuilder<cSharpContext>(); //optionsBuilder.UseInMemoryDatabase();//THISSS IS NOT POSSIBLE WITH POSTGRESS!!!!!!!!!!!! //var _dbContext = new cSharpContext(optionsBuilder.Options); //var _context = Services ///////////////////////////SQLITE COPY //var connection = new SqliteConnection("DataSource=:memory:"); //connection.Open(); //try //{ // var options = new DbContextOptionsBuilder<cSharpContext>() //trying to useSqlite as a temprary copy of a postgres database // .UseSqlite(connection) // .Options; // // Create the schema in the database // using (var context = new cSharpContext(options)) // { // context.Database.EnsureCreated(); // } // //// Run the test against one instance of the context // using (var context = new cSharpContext(options)) // { // var service = new HomeController(context); // //service.Add("http://sample.com"); // service.About(); // } // // Use a separate instance of the context to verify correct data was saved to database // using (var context = new cSharpContext(options)) // { // var controller = new HomeController(context); //I don't know if this is going to work // var actResult = controller.About() as ViewResult; // Assert.Equal("About", actResult.ViewName); // } //} //finally //{ // connection.Close(); //} ///////////////////////////USING DbOptionsFactory CLASS using (var context = new cSharpContext(DbOptionsFactory.DbContextOptions)) { var controller = new HomeController(context); //I don't know if this is going to work, it doesn't :( var actResult = controller.About() as ViewResult; Assert.Equal("About", actResult.ViewName); } }
public DatabaseFixture() { var connectionString = "User ID=postgres;Password=4310;Server=localhost;Database=cSharpTest;"; testDatabase = new TestDatabaseBuilder().WithConnectionString(connectionString).Build(); testDatabase.Create(); //testDatabase.RunScripts("./DatabaseScripts"); var builder = new DbContextOptionsBuilder <cSharpContext>(); builder.UseNpgsql(testDatabase.ConnectionString); DbContext = new cSharpContext(builder.Options); DbContext.Database.EnsureCreated(); }
public UsersController(cSharpContext context) { _context = context; }
public AdminsController(cSharpContext context) { _context = context; }
public RelativesController(cSharpContext context) { _context = context; }
public HomeController(cSharpContext context) { _context = context; }