protected RepositoryOptionsBuilder GetRepositoryOptionsBuilder(ContextProviderType provider)
        {
            var builder = new RepositoryOptionsBuilder();

            switch (provider)
            {
            case ContextProviderType.InMemory:
            {
                builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
                break;
            }

            case ContextProviderType.EntityFrameworkCore:
            {
                builder.UseEntityFrameworkCore <TestEfCoreDbContext>(options =>
                    {
                        options
                        .UseInMemoryDatabase(Guid.NewGuid().ToString())
                        .ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning));
                    });
                break;
            }

#if NETCORE
            case ContextProviderType.AzureStorageBlob:
            {
                builder.UseAzureStorageBlob(
                    connectionString: "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;",
                    createIfNotExists: true);
                break;
            }
#endif
#if NETFULL
            case ContextProviderType.EntityFramework:
            {
                builder.UseEntityFramework <TestEfDbContext>(Helpers.DbConnectionHelper.CreateConnection());
                break;
            }
#endif
            default:
                throw new ArgumentOutOfRangeException(nameof(provider));
            }

            builder.UseLoggerProvider(TestXUnitLoggerProvider);

            return(builder);
        }
        protected IRepositoryOptions BuildOptions(ContextProviderType provider)
        {
            var builder = new RepositoryOptionsBuilder();

            switch (provider)
            {
            case ContextProviderType.InMemory:
            {
                builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
                break;
            }

#if NETFULL
            case ContextProviderType.EntityFramework:
            {
                builder.UseEntityFramework <EfDbContext>(_connection);
                break;
            }
#else
            case ContextProviderType.EntityFrameworkCore:
            {
                builder.UseEntityFrameworkCore <EfCoreDbContext>(x => x.UseSqlServer(ConnectionString));
                break;
            }

            case ContextProviderType.AzureStorageBlob:
            {
                builder.UseAzureStorageBlob(
                    connectionString: "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;",
                    createIfNotExists: true);
                break;
            }
#endif
            default:
                throw new ArgumentOutOfRangeException(nameof(provider));
            }

            return(builder.Options);
        }
Example #3
0
        protected RepositoryOptionsBuilder GetRepositoryOptionsBuilder(ContextProviderType provider)
        {
            var builder = new RepositoryOptionsBuilder();

            switch (provider)
            {
            case ContextProviderType.InMemory:
            {
                builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
                break;
            }

            case ContextProviderType.Json:
            {
                builder.UseJsonDatabase(Path.GetTempPath() + Guid.NewGuid().ToString("N"));
                break;
            }

            case ContextProviderType.Xml:
            {
                builder.UseXmlDatabase(Path.GetTempPath() + Guid.NewGuid().ToString("N"));
                break;
            }

            case ContextProviderType.AdoNet:
            {
                builder.UseAdoNet(DbConnectionHelper.CreateConnection(), ensureDatabaseCreated: true);
                break;
            }

            case ContextProviderType.NHibernate:
            {
                builder.UseNHibernate(cfg =>
                    {
                        var currentFile      = PathHelper.GetTempFileName();
                        var connectionString = $"Data Source={currentFile};Persist Security Info=False";

                        cfg.DataBaseIntegration(x =>
                        {
                            x.Dialect <TestFixedMsSqlCe40Dialect>();
                            x.Driver <SqlServerCeDriver>();
                            x.ConnectionString = connectionString;
                            x.LogSqlInConsole  = true;
                            x.LogFormattedSql  = true;
                        });

                        var mapper = new ModelMapper();

                        mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());

                        var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

                        cfg.AddMapping(mapping);

                        var exporter = new SchemaExport(cfg);

                        exporter.Execute(true, true, false);
                    });

                break;
            }

            case ContextProviderType.EntityFramework:
            {
                builder.UseEntityFramework <TestEfDbContext>(DbConnectionHelper.CreateConnection());
                break;
            }

            case ContextProviderType.EntityFrameworkCore:
            {
                builder.UseEntityFrameworkCore <TestEfCoreDbContext>(options =>
                    {
                        options
                        .UseInMemoryDatabase(Guid.NewGuid().ToString())
                        .ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning));
                    });
                break;
            }

            case ContextProviderType.AzureStorageBlob:
            {
                builder.UseAzureStorageBlob(
                    nameOrConnectionString: "AzureStorageBlobConnection",
                    container: Guid.NewGuid().ToString(),
                    createIfNotExists: true);
                break;
            }

            case ContextProviderType.AzureStorageTable:
            {
                builder.UseAzureStorageTable(
                    nameOrConnectionString: "AzureStorageTableConnection",
                    tableName: "TableName" + Guid.NewGuid().ToString("N").ToUpper(),
                    createIfNotExists: true);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(provider));
            }

            builder.UseLoggerProvider(TestXUnitLoggerProvider);

            return(builder);
        }
        protected IRepositoryOptions BuildOptions(ContextProviderType provider)
        {
            var builder = new RepositoryOptionsBuilder();

            switch (provider)
            {
            case ContextProviderType.InMemory:
            {
                builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
                break;
            }

            case ContextProviderType.Json:
            {
                builder.UseJsonDatabase(Path.GetTempPath() + Guid.NewGuid().ToString("N"));
                break;
            }

            case ContextProviderType.Xml:
            {
                builder.UseJsonDatabase(Path.GetTempPath() + Guid.NewGuid().ToString("N"));
                break;
            }

            case ContextProviderType.AdoNet:
            {
                builder.UseAdoNet(_connection);
                break;
            }

            case ContextProviderType.NHibernate:
            {
                builder.UseNHibernate(cfg =>
                    {
                        cfg.DataBaseIntegration(x =>
                        {
                            x.Dialect <MsSql2012Dialect>();
                            x.Driver <SqlClientDriver>();
                            x.ConnectionString = ConnectionString;
                            x.LogSqlInConsole  = true;
                            x.LogFormattedSql  = true;
                        });

                        var mapper = new ModelMapper();

                        mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());

                        var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

                        cfg.AddMapping(mapping);

                        var exporter = new SchemaExport(cfg);

                        exporter.Execute(true, true, false);
                    });

                break;
            }

            case ContextProviderType.EntityFramework:
            {
                builder.UseEntityFramework <EfDbContext>(_connection);
                break;
            }

            case ContextProviderType.EntityFrameworkCore:
            {
                builder.UseEntityFrameworkCore <EfCoreDbContext>(x => x.UseSqlServer(ConnectionString));
                break;
            }

            case ContextProviderType.AzureStorageBlob:
            {
                builder.UseAzureStorageBlob(
                    nameOrConnectionString: "AzureStorageBlobConnection",
                    container: Guid.NewGuid().ToString(),
                    createIfNotExists: true);
                break;
            }

            case ContextProviderType.AzureStorageTable:
            {
                builder.UseAzureStorageTable(
                    nameOrConnectionString: "AzureStorageTableConnection",
                    tableName: "TableName" + Guid.NewGuid().ToString("N").ToUpper(),
                    createIfNotExists: true);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(provider));
            }

            return(builder.Options);
        }