public void Throws_with_new_when_no_provider_use_Database()
        {
            var options = new DbContextOptionsBuilder<ConstructorTestContext1A>()
                .UseInternalServiceProvider(new ServiceCollection().AddEntityFramework().BuildServiceProvider())
                .Options;

            using (var context = new ConstructorTestContext1A(options))
            {
                Assert.Equal(
                    CoreStrings.NoProviderConfiguredFailedToResolveService(typeof(IRelationalConnection).FullName),
                    Assert.Throws<InvalidOperationException>(() => context.Database.GetDbConnection()).Message);
            }
        }
        public void Throws_with_new_when_no_EF_services_use_Database()
        {
            var options = new DbContextOptionsBuilder<ConstructorTestContext1A>()
                .UseInternalServiceProvider(new ServiceCollection().BuildServiceProvider())
                .Options;

            using (var context = new ConstructorTestContext1A(options))
            {
                Assert.Equal(
                    CoreStrings.NoEfServices,
                    Assert.Throws<InvalidOperationException>(() => context.Database.GetDbConnection()).Message);
            }
        }
Esempio n. 3
0
        public void Throws_with_new_when_no_provider_use_Database()
        {
            var options = new DbContextOptionsBuilder <ConstructorTestContext1A>()
                          .UseInternalServiceProvider(new ServiceCollection().AddEntityFramework().BuildServiceProvider())
                          .Options;

            using (var context = new ConstructorTestContext1A(options))
            {
                Assert.Equal(
                    CoreStrings.NoProviderConfiguredFailedToResolveService(typeof(IRelationalConnection).FullName),
                    Assert.Throws <InvalidOperationException>(() => context.Database.GetDbConnection()).Message);
            }
        }
Esempio n. 4
0
        public void Throws_with_new_when_no_EF_services_use_Database()
        {
            var options = new DbContextOptionsBuilder <ConstructorTestContext1A>()
                          .UseInternalServiceProvider(new ServiceCollection().BuildServiceProvider())
                          .Options;

            using (var context = new ConstructorTestContext1A(options))
            {
                Assert.Equal(
                    CoreStrings.NoEfServices,
                    Assert.Throws <InvalidOperationException>(() => context.Database.GetDbConnection()).Message);
            }
        }
        public void Throws_with_new_when_non_relational_provider_in_use()
        {
            var options = new DbContextOptionsBuilder <ConstructorTestContext1A>()
                          .UseInternalServiceProvider(
                new ServiceCollection()
                .AddEntityFrameworkInMemoryDatabase()
                .BuildServiceProvider())
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            using var context = new ConstructorTestContext1A(options);
            Assert.Equal(
                RelationalStrings.RelationalNotInUse,
                Assert.Throws <InvalidOperationException>(() => context.Database.GetDbConnection()).Message);
        }
Esempio n. 6
0
        public void Throws_with_new_when_no_provider_use_Database()
        {
            var serviceCollection = new ServiceCollection();

            new EntityFrameworkServicesBuilder(serviceCollection).TryAddCoreServices();
            var serviceProvider = serviceCollection.BuildServiceProvider();

            var options = new DbContextOptionsBuilder <ConstructorTestContext1A>()
                          .UseInternalServiceProvider(serviceProvider)
                          .Options;

            using var context = new ConstructorTestContext1A(options);
            Assert.Equal(
                CoreStrings.NoProviderConfigured,
                Assert.Throws <InvalidOperationException>(() => context.Database.GetDbConnection()).Message);
        }
        public void Throws_with_new_when_non_relational_provider_in_use1110938893()
        {
            var options = new DbContextOptionsBuilder<ConstructorTestContext1A>()
                .UseInternalServiceProvider(
                    new ServiceCollection()
                        .AddEntityFrameworkSqlServer()
                        .AddEntityFrameworkInMemoryDatabase()
                        .BuildServiceProvider())
                .UseInMemoryDatabase()
                .Options;

            using (var context = new ConstructorTestContext1A(options))
            {
                Assert.Equal(
                    RelationalStrings.RelationalNotInUse,
                    Assert.Throws<InvalidOperationException>(() => context.Database.GetDbConnection()).Message);
            }
        }