コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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();
        }
コード例 #3
0
 public UsersController(cSharpContext context)
 {
     _context = context;
 }
コード例 #4
0
 public AdminsController(cSharpContext context)
 {
     _context = context;
 }
コード例 #5
0
 public RelativesController(cSharpContext context)
 {
     _context = context;
 }
コード例 #6
0
 public HomeController(cSharpContext context)
 {
     _context = context;
 }