public static IEnumerable <TestCaseData> Build(RepositoryType[] includeType)
        {
            if (includeType.Contains(RepositoryType.InMemory))
            {
                yield return(new TestCaseData(new InMemoryRepository <User, string, int>()).SetName("InMemoryRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Ef))
            {
                var dbPath = EfDataDirectoryFactory.Build();
                yield return(new TestCaseData(new EfRepository <User, string, int>(new TestObjectContext("Data Source=" + dbPath))).SetName("EfRepository Test"));
            }

            if (includeType.Contains(RepositoryType.EfCore))
            {
                var connection = new SqliteConnection("DataSource=:memory:");
                connection.Open();

                var options = new DbContextOptionsBuilder <TestObjectContextCore>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                var context = new TestObjectContextCore(options);
                context.Database.EnsureCreated();
                yield return(new TestCaseData(new EfCoreRepository <User, string, int>(context)).SetName("EfCoreRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Cache))
            {
                var cachingProvider = new InMemoryCachingProvider(new MemoryCache(new MemoryCacheOptions()));
                yield return(new TestCaseData(new CacheRepository <User, string, int>(CachePrefixFactory.Build(), cachingProvider)).SetName("CacheRepository Test"));
            }
        }
        public static IEnumerable <TestCaseData> Build(RepositoryType[] includeType)
        {
            if (includeType.Contains(RepositoryType.InMemory))
            {
                yield return(new TestCaseData(new InMemoryRepository <User, string, int>()).SetName("InMemoryRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Ef))
            {
                var dbPath = EfDataDirectoryFactory.Build();
                yield return(new TestCaseData(new EfRepository <User, string, int>(new TestObjectEntities("Data Source=" + dbPath))).SetName("EfRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Cache))
            {
                yield return(new TestCaseData(new CacheRepository <User, string, int>(CachePrefixFactory.Build())).SetName("CacheRepository Test"));
            }
        }
        public static IEnumerable <TestCaseData> Build(RepositoryType[] includeType)
        {
            if (includeType.Contains(RepositoryType.InMemory))
            {
                yield return(new TestCaseData(new InMemoryRepository <User, string, int>()).SetName("InMemoryRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Ef5))
            {
                var dbPath = EfDataDirectoryFactory.Build();
                Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
                yield return(new TestCaseData(new EfRepository <User, string, int>(new TestObjectEntities("Data Source=" + dbPath))).SetName("EfRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Cache))
            {
                yield return(new TestCaseData(new CacheRepository <User, string, int>(CachePrefixFactory.Build())).SetName("CacheRepository Test"));
            }
        }
        public static IEnumerable <TestCaseData> Build(RepositoryType[] includeType)
        {
            if (includeType.Contains(RepositoryType.InMemory))
            {
                yield return(new TestCaseData(new InMemoryRepository <Contact, string>()).SetName("InMemoryRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Xml))
            {
                var xmlDataDirectoryPath = XmlDataDirectoryFactory.Build("Contact");
                yield return
                    (new TestCaseData(new XmlRepository <Contact, string>(xmlDataDirectoryPath)).SetName("XmlRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Ef5) || includeType.Contains(RepositoryType.Ef))
            {
                var dbPath = EfDataDirectoryFactory.Build();
                Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
                yield return
                    (new TestCaseData(new EfRepository <Contact, string>(new TestObjectEntities("Data Source=" + dbPath))).SetName("EfRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Dbo4))
            {
                var dbPath = Db4oDataDirectoryFactory.Build("Contact");
                yield return(new TestCaseData(new Db4oRepository <Contact, string>(dbPath)).SetName("Db4oRepository Test"));
            }

            if (includeType.Contains(RepositoryType.MongoDb))
            {
                string connectionString = MongoDbConnectionStringFactory.Build("Contact");

                if (MongoDbRepositoryManager.ServerIsRunning(connectionString))
                {
                    MongoDbRepositoryManager.DropDatabase(connectionString); // Pre-test cleanup
                    yield return(new TestCaseData(new MongoDbRepository <Contact, string>(connectionString)).SetName("MongoDb Test"));
                }
            }

            if (includeType.Contains(RepositoryType.RavenDb))
            {
                var documentStore = new EmbeddableDocumentStore
                {
                    RunInMemory = true,
                    Conventions = { DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites }
                };
                yield return(new TestCaseData(new RavenDbRepository <Contact, string>(documentStore)).SetName("RavenDbRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Cache))
            {
                yield return(new TestCaseData(new CacheRepository <Contact, string>(CachePrefixFactory.Build())).SetName("CacheRepository Test"));
            }

            if (includeType.Contains(RepositoryType.CouchDb))
            {
                if (CouchDbRepositoryManager.ServerIsRunning(CouchDbUrl.Host, CouchDbUrl.Port))
                {
                    var databaseName = CouchDbDatabaseNameFactory.Build("Contact");
                    CouchDbRepositoryManager.DropDatabase(CouchDbUrl.Host, CouchDbUrl.Port, databaseName);
                    CouchDbRepositoryManager.CreateDatabase(CouchDbUrl.Host, CouchDbUrl.Port, databaseName);

                    yield return(new TestCaseData(new CouchDbRepository <Contact>(CouchDbUrl.Host, CouchDbUrl.Port, databaseName)).SetName("CouchDbRepository Test"));
                }
            }
        }
        public static IEnumerable <TestCaseData> Build(RepositoryType[] includeType)
        {
            if (includeType.Contains(RepositoryType.InMemory))
            {
                yield return(new TestCaseData(new InMemoryRepository <Contact, string>()).SetName("InMemoryRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Xml))
            {
                var xmlDataDirectoryPath = XmlDataDirectoryFactory.Build("Contact");
                yield return
                    (new TestCaseData(new XmlRepository <Contact, string>(xmlDataDirectoryPath)).SetName("XmlRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Ef))
            {
                var dbPath = EfDataDirectoryFactory.Build();
                yield return
                    (new TestCaseData(new EfRepository <Contact, string>(new TestObjectEntities("Data Source=" + dbPath))).SetName("EfRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Dbo4))
            {
                var dbPath = Db4oDataDirectoryFactory.Build("Contact");
                yield return(new TestCaseData(new Db4oRepository <Contact, string>(dbPath)).SetName("Db4oRepository Test"));
            }

            if (includeType.Contains(RepositoryType.MongoDb))
            {
                string connectionString = MongoDbConnectionStringFactory.Build("Contact");

                if (MongoDbRepositoryManager.ServerIsRunning(connectionString))
                {
                    MongoDbRepositoryManager.DropDatabase(connectionString); // Pre-test cleanup
                    yield return(new TestCaseData(new MongoDbRepository <Contact, string>(connectionString)).SetName("MongoDb Test"));
                }
            }

            if (includeType.Contains(RepositoryType.RavenDb))
            {
                var documentStore = new EmbeddableDocumentStore
                {
                    RunInMemory   = true,
                    DataDirectory = "~\\Data\\RavenDb"
                };
                if (IntPtr.Size == 4)
                {
                    documentStore.Configuration.Storage.Voron.AllowOn32Bits = true;
                }

                yield return(new TestCaseData(new RavenDbRepository <Contact, string>(documentStore)).SetName("RavenDbRepository Test"));
            }

            if (includeType.Contains(RepositoryType.Cache))
            {
                yield return(new TestCaseData(new CacheRepository <Contact, string>(CachePrefixFactory.Build())).SetName("CacheRepository Test"));
            }

            if (includeType.Contains(RepositoryType.CouchDb))
            {
                if (CouchDbRepositoryManager.ServerIsRunning(CouchDbUrl.Host, CouchDbUrl.Port))
                {
                    var databaseName = CouchDbDatabaseNameFactory.Build("Contact");
                    CouchDbRepositoryManager.DropDatabase(CouchDbUrl.Host, CouchDbUrl.Port, databaseName);
                    CouchDbRepositoryManager.CreateDatabase(CouchDbUrl.Host, CouchDbUrl.Port, databaseName);

                    yield return(new TestCaseData(new CouchDbRepository <Contact>(CouchDbUrl.Host, CouchDbUrl.Port, databaseName)).SetName("CouchDbRepository Test"));
                }
            }
        }
Ejemplo n.º 6
0
        public static IEnumerable <TestCaseData> Build(RepositoryType[] includeType, string testName = "Test")
        {
            if (includeType.Contains(RepositoryType.InMemory))
            {
                yield return(new TestCaseData(new InMemoryRepository <Contact, string>()).SetName("InMemoryRepository " + testName));
            }

            if (includeType.Contains(RepositoryType.Xml))
            {
                var xmlDataDirectoryPath = XmlDataDirectoryFactory.Build("Contact");
                yield return
                    (new TestCaseData(new XmlRepository <Contact, string>(xmlDataDirectoryPath)).SetName("XmlRepository" + testName));
            }

            if (includeType.Contains(RepositoryType.Ef))
            {
                var dbPath = EfDataDirectoryFactory.Build();
                yield return
                    (new TestCaseData(new EfRepository <Contact, string>(new TestObjectContext("Data Source=" + dbPath))).SetName("EfRepository" + testName));
            }

            if (includeType.Contains(RepositoryType.EfCore))
            {
                var connection = new SqliteConnection("DataSource=:memory:");
                connection.Open();

                var options = new DbContextOptionsBuilder <TestObjectContextCore>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                var context = new TestObjectContextCore(options);
                context.Database.EnsureCreated();
                yield return(new TestCaseData(new EfCoreRepository <Contact, string>(context)).SetName("EfCoreRepository " + testName));
            }

            if (includeType.Contains(RepositoryType.Dbo4))
            {
                var dbPath = Db4oDataDirectoryFactory.Build("Contact");
                yield return(new TestCaseData(new Db4oRepository <Contact, string>(dbPath)).SetName("Db4oRepository " + testName));
            }

            if (includeType.Contains(RepositoryType.MongoDb))
            {
                string connectionString = MongoDbConnectionStringFactory.Build("Contact");

                if (MongoDbRepositoryManager.ServerIsRunning(connectionString))
                {
                    MongoDbRepositoryManager.DropDatabase(connectionString); // Pre-test cleanup
                    yield return(new TestCaseData(new MongoDbRepository <Contact, string>(connectionString)).SetName("MongoDb " + testName));
                }
            }

            if (includeType.Contains(RepositoryType.RavenDb))
            {
                var documentStore = new EmbeddableDocumentStore
                {
                    RunInMemory   = true,
                    DataDirectory = "~\\Data\\RavenDb"
                };
                if (IntPtr.Size == 4)
                {
                    documentStore.Configuration.Storage.Voron.AllowOn32Bits = true;
                }

                IDocumentStore x = new EmbeddableDocumentStore();
                yield return(new TestCaseData(new RavenDbRepository <Contact, string>(documentStore: documentStore)).SetName("RavenDbRepository " + testName));
            }

            if (includeType.Contains(RepositoryType.Cache))
            {
                var cachingProvider = new InMemoryCachingProvider(new MemoryCache(new MemoryCacheOptions()));
                yield return(new TestCaseData(new CacheRepository <Contact, string>(CachePrefixFactory.Build(), cachingProvider)).SetName("CacheRepository " + testName));
            }

            if (includeType.Contains(RepositoryType.CouchDb))
            {
                if (CouchDbRepositoryManager.ServerIsRunning(CouchDbUrl.Host, CouchDbUrl.Port))
                {
                    var databaseName = CouchDbDatabaseNameFactory.Build("Contact");
                    CouchDbRepositoryManager.DropDatabase(CouchDbUrl.Host, CouchDbUrl.Port, databaseName);
                    CouchDbRepositoryManager.CreateDatabase(CouchDbUrl.Host, CouchDbUrl.Port, databaseName);

                    yield return(new TestCaseData(new CouchDbRepository <Contact, string>(CouchDbUrl.Host, CouchDbUrl.Port, databaseName)).SetName("CouchDbRepository " + testName));
                }
            }
        }