Esempio n. 1
0
        public void ConfigureLoggingProvider()
        {
            var optionsBuilder = new RepositoryOptionsBuilder();

            Assert.False(optionsBuilder.IsConfigured);

            optionsBuilder.UseLoggerProvider(new ConsoleLoggerProvider(LogLevel.Debug));

            Assert.True(optionsBuilder.IsConfigured);

            Assert.NotNull(optionsBuilder.Options.LoggerProvider);
        }
        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);
        }
Esempio n. 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(TestDbConnectionHelper.CreateConnection(), ensureDatabaseCreated: true);
                break;
            }

            case ContextProviderType.NHibernate:
            {
                builder.UseNHibernate(cfg =>
                    {
                        var currentFile      = TestPathHelper.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>(TestDbConnectionHelper.CreateConnection());
                break;
            }

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

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

            builder.UseLoggerProvider(TestXUnitLoggerProvider);

            return(builder);
        }