public void ClassInit() { // Installing mock DbSet. var data = new List<MockCatalog> { new MockCatalog(false) { Name = "BBB" }, new MockCatalog(false) { Name = "ZZZ" }, new MockCatalog(false) { Name = "AAA" }, }.AsQueryable(); var mockDbSet = new Mock<DbSet<MockCatalog>>(); mockDbSet.As<IQueryable<MockCatalog>>().Setup(m => m.Provider).Returns(data.Provider); mockDbSet.As<IQueryable<MockCatalog>>().Setup(m => m.Expression).Returns(data.Expression); mockDbSet.As<IQueryable<MockCatalog>>().Setup(m => m.ElementType).Returns(data.ElementType); mockDbSet.As<IQueryable<MockCatalog>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); // Installing mock Context. var mockContext = new Mock<MetadataEFContext>(); mockContext.Setup(m => m.Set<MockCatalog>()).Returns(mockDbSet.Object); // Installing repository. var catalogRepository = new EFCatalogRepository<MockCatalog>(mockContext.Object); // Installing shared tests. SharedTests = new SharedTests<MockCatalog>(mockDbSet, mockContext, catalogRepository, CreateCatalogItem); }
public override void Publish(string dbconnection, string data, bool sample, bool reduced, string strategy = SqlDbConfiguration.SqlAzureExecutionStrategy) { base.Publish(dbconnection, data, sample, reduced, strategy); string connection = dbconnection; SafeWriteDebug("ConnectionString: " + connection); using (var db = new EFCatalogRepository(connection)) { if (!string.IsNullOrEmpty(data) && sample) { if (reduced) { SafeWriteVerbose("Running reduced sample scripts"); new SqlCatalogReducedSampleDatabaseInitializer(data).InitializeDatabase(db); } else { SafeWriteVerbose("Running sample scripts"); new SqlCatalogSampleDatabaseInitializer(data).InitializeDatabase(db); } } else { SafeWriteVerbose("Running minimum scripts"); new SetupMigrateDatabaseToLatestVersion <EFCatalogRepository, Configuration>().InitializeDatabase(db); } } }
private void CreateDefaultPackages(EFCatalogRepository context) { context.AddOrUpdate(CreatePackaging("1", "Small box", "For catalogs, file folders, videotapes and CDs", 12.25m, 10.12m, 1.5m, LengthUnitOfMeasure.Inches)); context.AddOrUpdate(CreatePackaging("2", "Medium box", "For binders, books and heavy documents", 13.25m, 11.5m, 2.3m, LengthUnitOfMeasure.Inches)); context.AddOrUpdate(CreatePackaging("3", "Large box", "For side-by-side paper stacks, small parts and reports", 17.88m, 12.12m, 3m, LengthUnitOfMeasure.Inches)); context.AddOrUpdate(CreatePackaging("4", "10kg box", "Weight limit: 22 lbs. (to qualify for the flat rate, weight cannot exceed 22 lbs.", 15.88m, 12.95m, 10.30m, LengthUnitOfMeasure.Inches)); context.AddOrUpdate(CreatePackaging("5", "25kg box", "Weight limit: 56 lbs. (to qualify for the flat rate, weight cannot exceed 56 lbs.", 21.5m, 16.5m, 13.2m, LengthUnitOfMeasure.Inches)); context.UnitOfWork.Commit(); }
private void CreateDefaultPriceLists(EFCatalogRepository context) { context.AddOrUpdate(new Pricelist() { Currency = "USD", PricelistId = "DefaultUSD", Name = "MSRP USD Price List", Description = "MSRP Price List in USD" }); context.AddOrUpdate(new Pricelist() { Currency = "USD", PricelistId = "SaleUSD", Name = "Sale USD Price List", Description = "Sale Price List in USD" }); context.AddOrUpdate(new Pricelist() { Currency = "EUR", PricelistId = "DefaultEUR", Name = "Sale EUR Price List", Description = "Sale Price List in EUR" }); context.UnitOfWork.Commit(); }
public void Dispose() { try { // Ensure LocalDb databases are deleted after use so that LocalDb doesn't throw if // the temp location in which they are stored is later cleaned. using (var context = new EFCatalogRepository(TestDSCatalogService.DatabaseName)) { context.Database.Delete(); } if (_Service != null) { _Service.Dispose(); } } finally { AppDomain.CurrentDomain.SetData("DataDirectory", _previousDataDirectory); } }
protected override void Seed(EFCatalogRepository context) { // This method will be called after migrating to the latest version. CreateDefaultPackages(context); CreateDefaultPriceLists(context); }
private UnityContainer GetLocalContainer(SearchConnection searchConnection, string connectionString) { var container = new UnityContainer(); container.RegisterType <IKnownSerializationTypes, CatalogEntityFactory>("catalog", new ContainerControlledLifetimeManager()); container.RegisterInstance <IConsumerFactory>(new DomainAssemblyScannerConsumerFactory(container)); container.RegisterType <IKnownSerializationTypes, DomainAssemblyScannerConsumerFactory>("scaned", new ContainerControlledLifetimeManager(), new InjectionConstructor(container)); container.RegisterType <IConsumerFactory, DomainAssemblyScannerConsumerFactory>(); container.RegisterType <IEngineProcess, SingleThreadConsumingProcess>(); container.RegisterType <IMessageSerializer, DataContractMessageSerializer>(); container.RegisterType <IQueueWriter, InMemoryQueueWriter>(); container.RegisterType <IQueueReader, InMemoryQueueReader>(); container.RegisterType <IMessageSender, DefaultMessageSender>(new ContainerControlledLifetimeManager()); container.RegisterType <ICatalogEntityFactory, CatalogEntityFactory>(new ContainerControlledLifetimeManager()); container.RegisterType <IReviewEntityFactory, ReviewEntityFactory>(new ContainerControlledLifetimeManager()); container.RegisterType <ICatalogService, CatalogService>(); container.RegisterType <ISearchIndexBuilder, CatalogItemIndexBuilder>("catalogitem"); container.RegisterType <ILogOperationFactory, LogOperationFactory>(); container.RegisterType <ISearchEntityFactory, SearchEntityFactory>(new ContainerControlledLifetimeManager()); container.RegisterType <ISearchIndexController, SearchIndexController>(); container.RegisterType <ICacheRepository, HttpCacheRepository>(); if (string.Equals(searchConnection.Provider, SearchProviders.Lucene.ToString(), StringComparison.OrdinalIgnoreCase)) { // Lucene Search implementation container.RegisterType <ISearchProvider, LuceneSearchProvider>(); container.RegisterType <ISearchQueryBuilder, LuceneSearchQueryBuilder>(); } else if (string.Equals(searchConnection.Provider, SearchProviders.AzureSearch.ToString(), StringComparison.OrdinalIgnoreCase)) { // Azure Search implementation container.RegisterType <ISearchProvider, AzureSearchProvider>(); container.RegisterType <ISearchQueryBuilder, AzureSearchQueryBuilder>(); } else { container.RegisterType <ISearchProvider, ElasticSearchProvider>(); container.RegisterType <ISearchQueryBuilder, ElasticSearchQueryBuilder>(); } // register instances here container.RegisterInstance <ISearchConnection>(searchConnection); var catalogRepository = new EFCatalogRepository(connectionString); container.RegisterInstance <ICatalogRepository>(catalogRepository); container.RegisterType <ICatalogOutlineBuilder, CatalogOutlineBuilder>(); container.RegisterInstance <IPricelistRepository>(catalogRepository); container.RegisterInstance <IOperationLogRepository>(new OperationLogContext(connectionString)); container.RegisterInstance <IBuildSettingsRepository>(new EFSearchRepository(connectionString)); var reviewRepository = new EFReviewRepository(connectionString); container.RegisterInstance <IReviewRepository>(reviewRepository); var indexingProgress = new ProgressRecord(1, "Indexing Progress", "Progress:"); var observer = new ProgressObserver(this, indexingProgress); container.RegisterInstance <ISystemObserver>(observer); return(container); }