Пример #1
0
        public DatabaseTestingFixture()
        {
            var serviceCollection = new ServiceCollection();

            var args = new UniversityDbArguments
            {
                ConnectionString = $"Server=(localdb)\\mssqllocaldb;Database={typeof(T)}_University;Trusted_Connection=True;MultipleActiveResultSets=true",
                //DemoConstant file is not checked in and will never be. Either create your own or use the line above to run
                //ConnectionString = $"Server={DemoConstant.DatabaseConnection};Database={typeof(T)}_University;User Id={DemoConstant.UserName};Password={DemoConstant.Password};MultipleActiveResultSets=true;",
                CreateDbIfNotFound = true
            };

            serviceCollection.RegisterUniversityDb(args);

            var app = new TestAppBuilder();

            ServiceProvider = serviceCollection.BuildServiceProvider();

            //Delete the database before we start
            var context = ServiceProvider.GetRequiredService <UniversityDbContext>();

            context.Database.EnsureDeleted();

            app.ApplicationServices = ServiceProvider;

            app.UseUniversityDb();

            //set up automapper
            var mapperProfiles = ServiceProvider.GetServices <Profile>();

            Mapper.Initialize(cfg =>
            {
                foreach (var profile in mapperProfiles)
                {
                    cfg.AddProfile(profile);
                }
            });
        }
Пример #2
0
        public DatabaseTestingFixture()
        {
            var serviceCollection = new ServiceCollection();

            var args = new UniversityDbArguments
            {
                ConnectionString   = $"Server=(localdb)\\mssqllocaldb;Database={typeof(T)}_University;Trusted_Connection=True;MultipleActiveResultSets=true",
                CreateDbIfNotFound = true
            };

            serviceCollection.RegisterUniversityDb(args);

            var app = new TestAppBuilder();

            ServiceProvider = serviceCollection.BuildServiceProvider();

            //Delete the database before we start
            var context = ServiceProvider.GetRequiredService <UniversityDbContext>();

            context.Database.EnsureDeleted();

            app.ApplicationServices = ServiceProvider;

            app.UseUniversityDb();

            //set up automapper
            var mapperProfiles = ServiceProvider.GetServices <Profile>();

            Mapper.Initialize(cfg =>
            {
                foreach (var profile in mapperProfiles)
                {
                    cfg.AddProfile(profile);
                }
            });
        }