Пример #1
0
        public void TestExampleSetupViaOnConfiguringOk()
        {
            //SETUP
            const string connectionString                                     //#A
                = "Server=(localdb)\\mssqllocaldb;Database=EfCore.TestSupport-Test;Trusted_Connection=True";
            var builder = new                                                 //#B
                          DbContextOptionsBuilder <DbContextOnConfiguring>(); //#B

            builder.UseSqlServer(connectionString);                           //#C
            var options = builder.Options;                                    //#D

            //ATTEMPT
            using (var context = new DbContextOnConfiguring //#B
                                     (options))             //#B
            {
                //VERIFY
                context.Database.GetDbConnection().ConnectionString.ShouldEqual(connectionString);
            }

            /********************************************************************
            #A This holds the connection string for the database to be used for the unit test
            #B I set up the options I want to use
            #C I then provide the options to the DbContext via is new, one-parameter constructor
            * ******************************************************************/
        }
Пример #2
0
        public void TestExampleSetupViaConstructorOk()
        {
            //SETUP
            const string connectionString                          //#A
                = "Server=(localdb)\\mssqllocaldb;Database=EfCore.TestSupport-Test;Trusted_Connection=True";
            var builder = new                                      //#B
                          DbContextOptionsBuilder <BookContext>(); //#B

            builder.UseSqlServer(connectionString);                //#C
            var options = builder.Options;                         //#D

            using (var context = new BookContext(options))         //#E
            {
                //VERIFY
                context.Database.GetDbConnection().ConnectionString.ShouldEqual(connectionString);
            }

            /********************************************************************
            #A This holds the connection string for the SQL Server database
            #B We need to create DbContextOptionsBuilder<T> class to build the options
            #C Here I define that I want to use the SQL Server database provider
            #D I then build the final DbContextOptions<EfCoreContext> options that the application's DbContext needs
            #E This then allows me to create an instance for my unit tests
            * ******************************************************************/
        }
Пример #3
0
        public void AccessCosmosEmulatorViaConnectionString()
        {
            //SETUP
            var connectionString =                                    //#A
                                   "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";
            var builder = new                                         //#B
                          DbContextOptionsBuilder <CosmosDbContext>() //#B
                          .UseCosmos(                                 //#C
                connectionString,                                     //#D
                "MyCosmosDatabase");                                  //#E

            using var context = new CosmosDbContext(builder.Options); //#F

            //ATTEMPT

            //VERIFY
        }