Exemplo n.º 1
0
        protected override void OnConfiguring(DbContextOptions builder)
        {
            var dir = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
            var connection = "Filename=" + System.IO.Path.Combine(dir, "FavoriteForum.db");

            builder.UseSQLite(connection);
        }
 public ContactsDbContext(DbContextOptions<ContactsDbContext> options)
     : base(options)
 {
     if (_created) return;
     Database.Migrate();
     _created = true;
 }
Exemplo n.º 3
0
        public void SimpleConversion()
        {
            var options = new DbContextOptions()
                .UseInMemoryStore();

            using (var db = new CycleSalesContext(options))
            {
                // Arange
                db.Bikes.Add(new Bike { Bike_Id = 1, Retail = 100M });
                db.Bikes.Add(new Bike { Bike_Id = 2, Retail = 99.95M });
                db.SaveChanges();

                // Act
                var convertor = new PriceService(db);
                var results = convertor.CalculateForeignPrices(exchangeRate: 2).ToArray();

                // Assert
                Assert.AreEqual(2, results.Length);

                Assert.AreEqual(100M, results[0].USPrice);
                Assert.AreEqual(199.95M, results[0].ForeignPrice);

                Assert.AreEqual(99.95M, results[1].USPrice);
                Assert.AreEqual(199.90M, results[1].ForeignPrice);
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            Logger.Info("Update Batch Starting");

            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .AddEnvironmentVariables();
            Configuration = builder.Build();

            DbContextOptionsBuilder<BddContext> options = new DbContextOptionsBuilder<BddContext>();
            options.UseSqlite(Program.Configuration["Data:DefaultConnection:ConnectionString"]);

            Options = options.Options;

            string[] equipe = new string[] { "equipe1", "equipe2", "equipe3"};

            // Parsing classement
            ParseClassement(equipe);

            // Parsing des actualités
            ParseActus();

            // Parsing des pages Agendas
            ParseAgendas();

            // Parsing des pages par journées
            ParseJournees();

            Logger.Info("Update Batch End");
        }
Exemplo n.º 5
0
 protected override void OnConfiguring(DbContextOptions options)
 {
     if (!options.IsAlreadyConfigured())
     {
         options.UseSqlServer(@"Server=(localdb)\v11.0;Database=CycleSales;integrated security=True;");
     }
 }
Exemplo n.º 6
0
 public DbContext CreateContext(string tableName)
 {
     var options = new DbContextOptions()
         .UseModel(CreateModel(tableName))
         .UseAzureTableStorage(TestConfig.Instance.ConnectionString);
     return new DbContext(options);
 }
Exemplo n.º 7
0
        public BlavenDbContext(DbContextOptions<BlavenDbContext> options, Action<ModelBuilder> onModelCreating = null)
            : base(options)
        {
            this.Options = options;

            this.onModelCreating = onModelCreating;
        }
        public virtual DbContextConfiguration Initialize(
            [NotNull] IServiceProvider externalProvider,
            [NotNull] IServiceProvider scopedProvider,
            [NotNull] DbContextOptions contextOptions,
            [NotNull] DbContext context,
            ServiceProviderSource serviceProviderSource)
        {
            Check.NotNull(externalProvider, "externalProvider");
            Check.NotNull(scopedProvider, "scopedProvider");
            Check.NotNull(contextOptions, "contextOptions");
            Check.NotNull(context, "context");
            Check.IsDefined(serviceProviderSource, "serviceProviderSource");

            _externalProvider = externalProvider;
            _services = new ContextServices(scopedProvider);
            _serviceProviderSource = serviceProviderSource;
            _contextOptions = contextOptions;
            _context = context;
            _dataStoreServices = new LazyRef<DataStoreServices>(() => _services.DataStoreSelector.SelectDataStore(this));
            _modelFromSource = new LazyRef<IModel>(() => _services.ModelSource.GetModel(_context, _dataStoreServices.Value.ModelBuilderFactory));
            _dataStore = new LazyRef<DataStore>(() => _dataStoreServices.Value.Store);
            _connection = new LazyRef<DataStoreConnection>(() => _dataStoreServices.Value.Connection);
            _loggerFactory = new LazyRef<ILoggerFactory>(() => _externalProvider.TryGetService<ILoggerFactory>() ?? new NullLoggerFactory());
            _database = new LazyRef<Database>(() => _dataStoreServices.Value.Database);
            _stateManager = new LazyRef<StateManager>(() => _services.StateManager);

            return this;
        }
        public InheritanceSqliteFixture()
        {
            _serviceProvider
                = new ServiceCollection()
                    .AddEntityFramework()
                    .AddSqlite()
                    .ServiceCollection()
                    .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                    .AddInstance<ILoggerFactory>(new TestSqlLoggerFactory())
                    .BuildServiceProvider();

            var testStore = SqliteTestStore.CreateScratch();

            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseSqlite(testStore.Connection);
            _options = optionsBuilder.Options;

            // TODO: Do this via migrations & update pipeline

            testStore.ExecuteNonQuery(@"
                DROP TABLE IF EXISTS Country;
                DROP TABLE IF EXISTS Animal;

                CREATE TABLE Country (
                    Id int NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL
                );

                CREATE TABLE Animal (
                    Species nvarchar(100) NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL,
                    CountryId int NOT NULL ,
                    IsFlightless bit NOT NULL,
                    EagleId nvarchar(100),
                    'Group' int,
                    FoundOn tinyint,
                    Discriminator nvarchar(255),

                    FOREIGN KEY(countryId) REFERENCES Country(Id),
                    FOREIGN KEY(EagleId) REFERENCES Animal(Species)
                );

                CREATE TABLE Plant (
                    Genus int NOT NULL,
                    Species nvarchar(100) NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL,
                    CountryId int,
                    HasThorns bit,

                    FOREIGN KEY(countryId) REFERENCES Country(Id)
                );
            ");

            using (var context = CreateContext())
            {
                SeedData(context);
            }
            TestSqlLoggerFactory.Reset();
        }
Exemplo n.º 10
0
        public MainForm()
        {
            InitializeComponent();

            var builder = new DbContextOptionsBuilder();
            builder.UseSqlServer(ConfigurationManager.ConnectionStrings["RemoteDatabase"].ConnectionString);
            _remoteDatabaseOptions = builder.Options;
        }
Exemplo n.º 11
0
        public void Model_can_be_set_explicitly_in_options()
        {
            var model = Mock.Of<IModel>();

            var options = new DbContextOptions().UseModel(model);

            Assert.Same(model, options.Model);
        }
        public void It_disallows_empty_account_creds(string name, string key, string paramName)
        {
            var options = new DbContextOptions();

            Assert.Equal(
                Strings.FormatArgumentIsEmpty(paramName),
                Assert.Throws<ArgumentException>(() => AtsDbContextExtensions.UseAzureTableStorage(options, name, key)).Message
                );
        }
Exemplo n.º 13
0
        public void Can_update_an_existing_extension()
        {
            IDbContextOptionsExtensions options = new DbContextOptions();

            options.AddOrUpdateExtension<FakeDbContextOptionsExtension1>(e => e.Something += "One");
            options.AddOrUpdateExtension<FakeDbContextOptionsExtension1>(e => e.Something += "Two");

            Assert.Equal("OneTwo", options.Extensions.OfType<FakeDbContextOptionsExtension1>().Single().Something);
        }
        public void Is_not_available_when_not_configured()
        {
            var options = new DbContextOptions();

            var configurationMock = new Mock<DbContextConfiguration>();
            configurationMock.Setup(m => m.ContextOptions).Returns(options);

            Assert.False(new SqlServerDataStoreSource(configurationMock.Object).IsAvailable);
        }
        public void Is_not_configured_when_configuration_does_not_contain_associated_extension()
        {
            var options = new DbContextOptions();

            var configurationMock = new Mock<DbContextConfiguration>();
            configurationMock.Setup(m => m.ContextOptions).Returns(options);

            Assert.False(new SqlServerDataStoreSource(configurationMock.Object).IsConfigured);
        }
        public void UseInMemoryStore_throws_if_options_are_locked()
        {
            var options = new DbContextOptions<DbContext>();
            options.Lock();

            Assert.Equal(
                GetString("FormatEntityConfigurationLocked", "UseInMemoryStore"),
                Assert.Throws<InvalidOperationException>(() => options.UseInMemoryStore()).Message);
        }
        public void It_disallows_empty_connection_strings()
        {
            var options = new DbContextOptions();

            Assert.Equal(
                Strings.FormatArgumentIsEmpty("connectionString"),
                Assert.Throws<ArgumentException>(() => AtsDbContextExtensions.UseAzureTableStorage(options, "")).Message
                );
        }
        public void UseSQLite_throws_if_options_are_locked()
        {
            var options = new DbContextOptions<DbContext>();
            options.Lock();

            Assert.Equal(
                GetString("FormatEntityConfigurationLocked", "UseSQLite"),
                Assert.Throws<InvalidOperationException>(() => options.UseSQLite("Database=DoubleDecker")).Message);
        }
        public void Can_add_extension_with_connection_string()
        {
            var options = new DbContextOptions();

            options = options.UseSQLite("Database=Crunchie");

            var extension = ((IDbContextOptionsExtensions)options).Extensions.OfType<SQLiteOptionsExtension>().Single();

            Assert.Equal("Database=Crunchie", extension.ConnectionString);
        }
Exemplo n.º 20
0
 protected override void OnConfiguring(DbContextOptions options)
 {
     // TODO: This check is so that we can pass in external options from tests
     //       Need to come up with a better way to handle this scenario
     if (!((IDbContextOptionsExtensions)options).Extensions.Any())
     {
         // TODO: Connection string in code rather than config file because of temporary limitation with Migrations
         options.UseSqlServer(@"Server=(localdb)\v11.0;Database=CycleSales;integrated security=True;");
     }
 }
        public void It_sets_batching_options()
        {
            var options = new DbContextOptions();

            AtsDbContextExtensions.UseAzureTableStorage(options, "not empty", true);

            var result = GetAtsExtension(options);
            Assert.NotNull(result);
            Assert.True(result.UseBatching);
        }
        public void Can_add_extension_with_connection_string_using_generic_options()
        {
            var options = new DbContextOptions<DbContext>();

            options = options.UseSQLite("Database=Whisper");

            var extension = ((IDbContextOptionsExtensions)options).Extensions.OfType<SQLiteOptionsExtension>().Single();

            Assert.Equal("Database=Whisper", extension.ConnectionString);
        }
        public void Can_add_extension_with_connection_string_using_generic_options()
        {
            var options = new DbContextOptions<DbContext>();

            options = options.UseInMemoryStore(persist: false);

            var extension = ((IDbContextOptionsExtensions)options).Extensions.OfType<InMemoryOptionsExtension>().Single();

            Assert.False(extension.Persist);
        }
        public void Is_available_when_configured()
        {
            var options = new DbContextOptions();
            ((IDbContextOptionsExtensions)options).AddOrUpdateExtension<SqlServerOptionsExtension>(e => { });

            var configurationMock = new Mock<DbContextConfiguration>();
            configurationMock.Setup(m => m.ContextOptions).Returns(options);

            Assert.True(new SqlServerDataStoreSource(configurationMock.Object).IsAvailable);
        }
        public void Is_configured_when_configuration_contains_associated_extension()
        {
            IDbContextOptionsExtensions options = new DbContextOptions();
            options.AddOrUpdateExtension<InMemoryOptionsExtension>(e => { });

            var configurationMock = new Mock<DbContextConfiguration>();
            configurationMock.Setup(m => m.ContextOptions).Returns(options);

            Assert.True(new InMemoryDataStoreSource(configurationMock.Object).IsConfigured);
        }
        public MigrationsSqliteFixture()
        {
            var serviceProvider = new ServiceCollection()
                .AddEntityFrameworkSqlite()
                .BuildServiceProvider();

            _options = new DbContextOptionsBuilder()
                .UseInternalServiceProvider(serviceProvider)
                .UseSqlite("Data Source=" + nameof(MigrationsSqliteTest) + ".db").Options;
        }
        public void It_constructs_connection_string()
        {
            var options = new DbContextOptions();

            AtsDbContextExtensions.UseAzureTableStorage(options, "Moria", "mellon");

            var result = GetAtsExtension(options);
            Assert.NotNull(result);
            Assert.Equal("DefaultEndpointsProtocol=https;AccountName=Moria;AccountKey=mellon;", result.ConnectionString);
        }
        public void Can_add_extension_using_persist_true()
        {
            var options = new DbContextOptions();

            options = options.UseInMemoryStore(persist: true);

            var extension = ((IDbContextOptionsExtensions)options).Extensions.OfType<InMemoryOptionsExtension>().Single();

            Assert.True(extension.Persist);
        }
 protected override void OnConfiguring(DbContextOptions options)
 {
     if (_useInMemory)
     {
         options.UseInMemoryStore();
     }
     else
     {
         options.UseSqlServer(ConfigurationManager.ConnectionStrings["CycleSalesConnection"].ConnectionString);
     }
 }
Exemplo n.º 30
0
 public AppIdentityDbContext(DbContextOptions <AppIdentityDbContext> options) : base(options)
 {
 }
Exemplo n.º 31
0
 public Fit4LifeDbContext(DbContextOptions <Fit4LifeDbContext> options)
     : base(options)
 {
 }
Exemplo n.º 32
0
 public Context(DbContextOptions <Context> options) : base(options)
 {
 }
Exemplo n.º 33
0
 public HsDbFirstRealAspNetProjectContext(DbContextOptions <HsDbFirstRealAspNetProjectContext> options)
     : base(options)
 {
 }
Exemplo n.º 34
0
 public scoreContext(DbContextOptions <scoreContext> options) : base(options)
 {
 }
Exemplo n.º 35
0
 public WarriorContext(DbContextOptions <WarriorContext> options) : base(options)
 {
 }
Exemplo n.º 36
0
 public ApplicationDbContext(DbContextOptions <ApplicationDbContext> options)
     : base(options)
 {
 }
Exemplo n.º 37
0
 public ShopContext(DbContextOptions <ShopContext> options)
     : base(options)
 {
 }
Exemplo n.º 38
0
 public DataContext(DbContextOptions <DataContext> options) : base(options)
 {
 }
Exemplo n.º 39
0
 public TravelBlogContext(DbContextOptions <TravelBlogContext> options) : base(options)
 {
 }
Exemplo n.º 40
0
 public AccountContext(DbContextOptions <AccountContext> options) : base(options)
 {
 }
Exemplo n.º 41
0
 public StudentDBContext(DbContextOptions options) : base(options)
 {
 }
Exemplo n.º 42
0
 public QuickBuyContexto(DbContextOptions options) : base(options)
 {
 }
Exemplo n.º 43
0
 public BriefContext(DbContextOptions <BriefContext> options)
     : base(options)
 {
 }
Exemplo n.º 44
0
 public TodoContext(DbContextOptions <TodoContext> dbOptions) : base(dbOptions)
 {
 }
Exemplo n.º 45
0
 public VegaDbContext(DbContextOptions <VegaDbContext> options) : base(options)
 {
     //System.configuration.ConfigurationManager
 }
Exemplo n.º 46
0
 public CityInfoContext(DbContextOptions <CityInfoContext> options) : base(options)
 {
     Database.Migrate();
     Database.Migrate();
 }
 static CustomerTestController()
 {
     dbContextOptions = new DbContextOptionsBuilder<Book_Store_DbContext>().UseSqlServer(connectionString).Options;
 }
Exemplo n.º 48
0
 public DbFirstDemoContext(DbContextOptions <DbFirstDemoContext> options)
     : base(options)
 {
 }
Exemplo n.º 49
0
 public restaurantMP31Context(DbContextOptions <restaurantMP31Context> options)
     : base(options)
 {
 }
Exemplo n.º 50
0
 public HackermanContext(DbContextOptions <HackermanContext> options) : base(options)
 {
 }
Exemplo n.º 51
0
 public LotteryDbContext(DbContextOptions options) : base(options) { }
Exemplo n.º 52
0
 public InvoiceGeneratorAuthorizationContext(DbContextOptions <InvoiceGeneratorAuthorizationContext> options)
     : base(options)
 {
 }
Exemplo n.º 53
0
 public SchoolContext(DbContextOptions <SchoolContext> options)
     : base(options)
 {
 }
Exemplo n.º 54
0
 /// <inheritdoc />
 public DbContextBase(DbContextOptions options) : base(options)
 {
 }
Exemplo n.º 55
0
 public ReviewContext(DbContextOptions <ReviewContext> options) : base(options)
 {
 }
Exemplo n.º 56
0
        public EmpDBContext(DbContextOptions<EmpDBContext> options) : base(options)
        {

        }
Exemplo n.º 57
0
 public CartContext(DbContextOptions <CartContext> options)
     : base(options)
 {
     Database.EnsureCreated();
 }
Exemplo n.º 58
0
 public SimpleDbContext(DbContextOptions <SimpleDbContext> options) : base(options)
 {
 }
Exemplo n.º 59
0
 public MyshopContext(DbContextOptions<MyshopContext> options)
     : base(options)
 {
 }
Exemplo n.º 60
-1
 private static void SeedDatabase(DbContextOptions options)
 {
     using (var db = new GreetingDbContext(options))
     {
         db.Greetings.Add(new Greeting{Name = "First Greeting", TimestampUtc = DateTime.Now.ToUniversalTime()});
         db.Greetings.Add(new Greeting{Name = "Second Greeting", TimestampUtc = DateTime.Now.ToUniversalTime()});
         db.SaveChanges();
     }
 }