Ejemplo n.º 1
0
 public AbstractProviderSetup(ProviderMetadata providerMetadata, IFrameworkContext frameworkContext, AbstractProviderBootstrapper bootstrapper, int priorityOrdinal)
 {
     ProviderMetadata = providerMetadata;
     FrameworkContext = frameworkContext;
     Bootstrapper = bootstrapper;
     PriorityOrdinal = priorityOrdinal;
 }
        public CacheTestSetupHelper()
        {
            _cacheReference = new MemoryCache("unit-tester");

            var metadata = new ProviderMetadata("cache", new Uri("cache://"), false, true);
            var frameworkContext = new FakeFrameworkContext();

            var schemaRepositoryFactory = new SchemaRepositoryFactory(
                metadata,
                new NullProviderRevisionRepositoryFactory<EntitySchema>(metadata, frameworkContext),
                frameworkContext,
                new DependencyHelper(metadata, new CacheHelper(CacheReference)));

            var revisionRepositoryFactory = new EntityRevisionRepositoryFactory(
                metadata,
                frameworkContext,
                new DependencyHelper(metadata, new CacheHelper(CacheReference)));

            var entityRepositoryFactory = new EntityRepositoryFactory(
                metadata,
                revisionRepositoryFactory,
                schemaRepositoryFactory,
                frameworkContext,
                new DependencyHelper(metadata, new CacheHelper(CacheReference)));
            var unitFactory = new ProviderUnitFactory(entityRepositoryFactory);
            var readonlyUnitFactory = new ReadonlyProviderUnitFactory(entityRepositoryFactory);
            ProviderSetup = new ProviderSetup(unitFactory, metadata, frameworkContext, new NoopProviderBootstrapper(), 0);
            ReadonlyProviderSetup = new ReadonlyProviderSetup(readonlyUnitFactory, metadata, frameworkContext, new NoopProviderBootstrapper(), 0);
        }
        //public EntityRepositoryFactory(ProviderMetadata providerMetadata, 
        //    ProviderRevisionSessionFactory<TypedEntity> revisionRepositoryFactory, 
        //    ProviderSchemaSessionFactory schemaRepositoryFactory,
        //    IFrameworkContext frameworkContext, global::NHibernate.Cfg.Configuration nhConfig)
        //    : base(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext)
        //{
        //    Helper = new NhFactoryHelper(nhConfig, null, false, false, frameworkContext);
        //}

        public EntityRepositoryFactory(ProviderMetadata providerMetadata,
            AbstractRevisionRepositoryFactory<TypedEntity> revisionRepositoryFactory,
            AbstractSchemaRepositoryFactory schemaRepositoryFactory,
            IFrameworkContext frameworkContext, ProviderDependencyHelper dependencyHelper)
            : base(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext, dependencyHelper)
        {
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EntityRepositoryFactory"/> class. This constructor is used internally for unit testing where a single session must be used
 /// irrespective of the NHibernate session factory mechanisms.
 /// </summary>
 /// <param name="providerMetadata">The provider metadata.</param>
 /// <param name="revisionRepositoryFactory">The revision repository factory.</param>
 /// <param name="schemaRepositoryFactory">The schema repository factory.</param>
 /// <param name="frameworkContext">The framework context.</param>
 /// <param name="singleProvidedSession">The single provided session.</param>
 /// <param name="leaveSessionOpenOnDispose">if set to <c>true</c> [leave session open on dispose].</param>
 /// <remarks></remarks>
 internal EntityRepositoryFactory(ProviderMetadata providerMetadata, 
     AbstractRevisionRepositoryFactory<TypedEntity> revisionRepositoryFactory, 
     AbstractSchemaRepositoryFactory schemaRepositoryFactory, 
     IFrameworkContext frameworkContext, ISession singleProvidedSession, bool leaveSessionOpenOnDispose)
     : base(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext, new DependencyHelper(new NhFactoryHelper(null, singleProvidedSession, leaveSessionOpenOnDispose, false, frameworkContext), providerMetadata))
 {
 }
 internal EntityRepositoryFactory(ProviderMetadata providerMetadata,
     AbstractRevisionRepositoryFactory<TypedEntity> revisionRepositoryFactory,
     AbstractSchemaRepositoryFactory schemaRepositoryFactory, Settings settings,
     IFrameworkContext frameworkContext)
     : base(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext, new DependencyHelper(settings, providerMetadata))
 {
 }
Ejemplo n.º 6
0
        public ProviderSetup(ProviderUnitFactory unitFactory, ProviderMetadata providerMetadata, IFrameworkContext frameworkContext, AbstractProviderBootstrapper bootstrapper, int priorityOrdinal)
            : base(providerMetadata, frameworkContext, bootstrapper, priorityOrdinal)
        {
            Mandate.ParameterNotNull(unitFactory, "unitFactory");

            UnitFactory = unitFactory;
        }
Ejemplo n.º 7
0
 protected ReadonlyProviderSetup(ProviderMetadata providerMetadata, IFrameworkContext frameworkContext, AbstractProviderBootstrapper bootstrapper, int priorityOrdinal) 
     : base(providerMetadata, frameworkContext, bootstrapper, priorityOrdinal)
 {
     Mandate.ParameterNotNull(frameworkContext, "frameworkContext");
     Mandate.ParameterNotNull(bootstrapper, "bootstrapper");
     Mandate.ParameterNotNull(providerMetadata, "providerMetadata");
 }
 /// <summary>
 /// Constructor used for testing
 /// </summary>
 /// <param name="providerMetadata"></param>
 /// <param name="revisionRepositoryFactory"></param>
 /// <param name="frameworkContext"></param>
 /// <param name="helper"></param>
 internal SchemaRepositoryFactory(
     ProviderMetadata providerMetadata,
     AbstractRevisionRepositoryFactory<EntitySchema> revisionRepositoryFactory,
     IFrameworkContext frameworkContext,
     ExamineHelper helper)
     : base(providerMetadata, revisionRepositoryFactory, frameworkContext, new DependencyHelper(helper, providerMetadata))
 {
 }
        protected AbstractProviderRepository(ProviderMetadata providerMetadata, IFrameworkContext frameworkContext)
        {
            CanRead = true;
            ProviderMetadata = providerMetadata;
            FrameworkContext = frameworkContext;
            RepositoryScopedCache = new DictionaryScopedCache();

            //HiveContext = new RepositoryContext(RuntimeCacheProvider.Default, PerHttpRequestCacheProvider.Default, frameworkContext);
        }
Ejemplo n.º 10
0
        public ExamineTestSetupHelper(FakeFrameworkContext frameworkContext = null, bool isPassthrough = false)
        {
            var examineWorkingFolder = new DirectoryInfo(Path.Combine(Common.CurrentAssemblyDirectory, "Examine", Guid.NewGuid().ToString() + Thread.CurrentThread.ManagedThreadId));
            if (!examineWorkingFolder.Exists)
                Directory.CreateDirectory(examineWorkingFolder.FullName);

            //clear out old folders
            var parentFolder = examineWorkingFolder.Parent;
            foreach(var f in parentFolder.GetDirectories().Where(x => x.CreationTimeUtc < DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5))))
            {
                try
                {
                    Directory.Delete(f.FullName, true);
                }
                catch (IOException)
                {
                    //ignore
                }
            }

            LogHelper.TraceIfEnabled<ExamineTestSetupHelper>("Index setup in folder {0}", () => examineWorkingFolder.FullName);

            //var disk = new Lucene.Net.Store.RAMDirectory();
            var disk = new Lucene.Net.Store.SimpleFSDirectory(examineWorkingFolder);

            Indexer = new UmbracoExamineIndexer(
                new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29),
                SynchronizationType.Synchronized,
                disk);

            _fakeFrameworkContext = frameworkContext ?? new FakeFrameworkContext();
            

            Searcher = new LuceneSearcher(new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), disk);
            ExamineManager = new ExamineManager(new[] { Searcher }, new[] { Indexer }, Searcher);
            ExamineHelper = new ExamineHelper(ExamineManager, _fakeFrameworkContext, false); //false to not use cache

            var examineMapper = new ExamineModelMapper(ExamineHelper, _fakeFrameworkContext);
            _fakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { examineMapper, new FrameworkModelMapper(_fakeFrameworkContext) }));

            var providerMetadata = new ProviderMetadata("r-examine-unit-tester", new Uri("tester://"), true, isPassthrough);
 
            var revisionSchemaSessionFactory = new NullProviderRevisionRepositoryFactory<EntitySchema>(providerMetadata, FrameworkContext);
            var revisionRepositoryFactory = new RevisionRepositoryFactory(providerMetadata, FrameworkContext, ExamineHelper);
            //var revisionRepositoryFactory = new NullProviderRevisionSessionFactory<TypedEntity>(providerMetadata, FrameworkContext);
            var schemaRepositoryFactory = new SchemaRepositoryFactory(providerMetadata, revisionSchemaSessionFactory, FrameworkContext, ExamineHelper);
            var entityRepositoryFactory = new EntityRepositoryFactory(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, FrameworkContext, ExamineHelper);

            var readUnitFactory = new ReadonlyProviderUnitFactory(entityRepositoryFactory);
            var unitFactory = new ProviderUnitFactory(entityRepositoryFactory);

            ProviderSetup = new ProviderSetup(unitFactory, providerMetadata, FrameworkContext, null, 0);
            ReadonlyProviderSetup = new ReadonlyProviderSetup(readUnitFactory, providerMetadata, FrameworkContext, null, 0);

            //ensure that the index exists
            Indexer.CreateIndex(true);
        }
Ejemplo n.º 11
0
 public DependencyHelper(
     IEnumerable<ProviderElement> configuredProviders,
     Lazy<IEnumerable<MembershipProvider>> membershipProviders,             
     ProviderMetadata providerMetadata)
     : base(providerMetadata)
 {
     MembershipProviders = membershipProviders;
     ConfiguredProviders = configuredProviders;
 }
        //public SchemaRepositoryFactory MembershipSchemaRepositoryFactory { get { return base.SchemaRepositoryFactory as SchemaRepositoryFactory; } }

        /// <summary>
        /// Internal constructor for testing
        /// </summary>
        /// <param name="providerMetadata"></param>
        /// <param name="revisionRepositoryFactory"></param>
        /// <param name="schemaRepositoryFactory"></param>
        /// <param name="frameworkContext"></param>
        /// <param name="membershipProviders"></param>
        /// <param name="configuredProviders"></param>
        internal EntityRepositoryFactory(
            ProviderMetadata providerMetadata,
            AbstractRevisionRepositoryFactory<TypedEntity> revisionRepositoryFactory,
            AbstractSchemaRepositoryFactory schemaRepositoryFactory,
            IFrameworkContext frameworkContext,
            Lazy<IEnumerable<MembershipProvider>> membershipProviders,
            IEnumerable<ProviderElement> configuredProviders)
            : base(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext, new DependencyHelper(configuredProviders, membershipProviders, providerMetadata))
        {
        }
        public NhibernateTestSetupHelper(string dataSource, SupportedNHDrivers supportedNhDrivers, string sessionContext, bool executeSchema, FakeFrameworkContext frameworkContext = null, bool useNhProf = false, bool outputMappings = false, bool leaveSessionOpenOnRepositoryDispose = true, bool useSingleSessionForTest = true)
        {
            _useNhProfiler = useNhProf;
            var builder = new NHibernateConfigBuilder(dataSource, "unit-tester", supportedNhDrivers, sessionContext, outputMappings, _useNhProfiler);
            NhConfigurationCacheKey cacheKey;
            Config = builder.BuildConfiguration(false, out cacheKey, "on_close");
            SessionFactory = SessionFactoryCache.GetOrAdd(cacheKey, key => Config.BuildSessionFactory());
            SessionForTest = SessionFactory.OpenSession();
            var schemaWriter = new StringWriter(new StringBuilder());
            if (executeSchema) new SchemaExport(Config).Execute(false, true, false, SessionForTest.Connection, schemaWriter);

            FakeFrameworkContext = frameworkContext ?? new FakeFrameworkContext();
            
            //var dataContextFactory = new DataContextFactory(fakeFrameworkContext, SessionForTest, true);

            //var readWriteRepositoryUnitOfWorkFactory = new ReadWriteUnitOfWorkFactory();
            //var writer = new HiveReadWriteProvider(new HiveProviderSetup(fakeFrameworkContext, "r-unit-tester", new FakeHiveProviderBootstrapper(), null, readWriteRepositoryUnitOfWorkFactory, dataContextFactory));

            var providerMetadata = new ProviderMetadata("r-unit-tester", new Uri("tester://"), true, false);
            //var schemaRepositoryFactory = new NullProviderSchemaRepositoryFactory(providerMetadata, fakeFrameworkContext);
            //var revisionRepositoryFactory = new NullProviderRevisionRepositoryFactory<TypedEntity>(providerMetadata, fakeFrameworkContext);

            var revisionSchemaSessionFactory = new NullProviderRevisionRepositoryFactory<EntitySchema>(providerMetadata,
                                                                                                    FakeFrameworkContext);

            ProviderDependencyHelper helper = null;
            if (!useSingleSessionForTest)
            {
                helper = new DependencyHelper(new NhFactoryHelper(Config, null, leaveSessionOpenOnRepositoryDispose, false, FakeFrameworkContext), providerMetadata);
            }
            else
            {
                helper = new DependencyHelper(new NhFactoryHelper(null, SessionForTest, leaveSessionOpenOnRepositoryDispose, false, FakeFrameworkContext), providerMetadata);
            }

            var revisionRepositoryFactory = new RevisionRepositoryFactory(providerMetadata, FakeFrameworkContext, helper);

            var schemaRepositoryFactory = new SchemaRepositoryFactory(providerMetadata, revisionSchemaSessionFactory,
                                                                FakeFrameworkContext, helper);

            var entityRepositoryFactory = new EntityRepositoryFactory(providerMetadata, revisionRepositoryFactory,
                                                                schemaRepositoryFactory, FakeFrameworkContext,
                                                                helper);

            var readUnitFactory = new ReadonlyProviderUnitFactory(entityRepositoryFactory);
            var unitFactory = new ProviderUnitFactory(entityRepositoryFactory);
            ProviderSetup = new ProviderSetup(unitFactory, providerMetadata, FakeFrameworkContext, null, 0);
            ReadonlyProviderSetup = new ReadonlyProviderSetup(readUnitFactory, providerMetadata, FakeFrameworkContext, null, 0);

            Func<AbstractMappingEngine> addTypemapper = () => new ManualMapperv2(new NhLookupHelper(entityRepositoryFactory), providerMetadata);
            FakeFrameworkContext.TypeMappers.Add(new Lazy<AbstractMappingEngine, TypeMapperMetadata>(addTypemapper, new TypeMapperMetadata(true)));
        }
        public void WhenProviderMetadataIsPassthrough_ProviderId_IsNotSet_OnHiveId()
        {
            // Arrange
            var metadata = new ProviderMetadata("test", new Uri("mappingroot://"), false, true);
            var originalId = new HiveId(1);

            // Act
            var newId = ProviderRepositoryHelper.CreateMappedProviderId(metadata, originalId);

            // Assert
            Assert.IsNull(newId.ProviderId);
            Assert.AreNotEqual(metadata.Alias, newId.ProviderId);
        }
        public void WhenProviderMetadataIsNotPassthrough_ButProviderIdIsAlreadySet_ProviderId_IsNotOverriden_OnHiveId()
        {
            // Arrange
            var metadata = new ProviderMetadata("test", new Uri("mappingroot://"), false, false);
            var originalId = new HiveId(new Uri("myroot://"), "myprovider", new HiveIdValue(1));

            // Act
            var newId = ProviderRepositoryHelper.CreateMappedProviderId(metadata, originalId);

            // Assert
            Assert.NotNull(newId.ProviderId);
            Assert.AreNotEqual(metadata.Alias, newId.ProviderId);
            Assert.AreEqual(originalId.ProviderId, newId.ProviderId);
        }
Ejemplo n.º 16
0
        public IoHiveTestSetupHelper(string supportedExtensions, FakeFrameworkContext frameworkContext = null)
        {
            FrameworkContext = frameworkContext ?? new FakeFrameworkContext();
            TestDirectory = GetTestDirectory();
            ProviderMetadata = new ProviderMetadata("test-provider", new Uri("storage://"), true, false);
            Settings = new Settings(supportedExtensions, TestDirectory.FullName, TestDirectory.FullName, String.Empty, String.Empty, "~/");
            EntityRepositoryFactory = new EntityRepositoryFactory(ProviderMetadata, null, null, Settings, FrameworkContext);
            EntityRepository = EntityRepositoryFactory.GetRepository() as EntityRepository;

            var readonlyFactory = new ReadonlyProviderUnitFactory(EntityRepositoryFactory);
            var factory = new ProviderUnitFactory(EntityRepositoryFactory);

            ReadonlyProviderSetup = new ReadonlyProviderSetup(readonlyFactory, ProviderMetadata, FrameworkContext, new NoopProviderBootstrapper(), 0);
            ProviderSetup = new ProviderSetup(factory, ProviderMetadata, FrameworkContext, new NoopProviderBootstrapper(), 0);
        }
        public IHiveManager GetHiveManager()
        {
            IFrameworkContext frameworkContext = GetFrameworkContext();

            var providerMetadata = new ProviderMetadata("p__nhibernate", new Uri("content://"), true, false);

            var builder =
                new NHibernateConfigBuilder(
                    ConfigurationManager.ConnectionStrings["DatabaseConnString"].ConnectionString,
                    "unit-tester", SupportedNHDrivers.MsSql2008, "call", false, false);

            NhConfigurationCacheKey cacheKey;
            Configuration config = builder.BuildConfiguration(false, out cacheKey);

            var nhHelper = new NhFactoryHelper(config, null, false, false, frameworkContext);

            ProviderDependencyHelper dependencyHelper = new DependencyHelper(nhHelper, providerMetadata);
            var revisionRepositoryFactory = new RevisionRepositoryFactory(providerMetadata, frameworkContext,
                                                                          dependencyHelper);

            var revisionSchemaSessionFactory = new NullProviderRevisionRepositoryFactory<EntitySchema>(providerMetadata,
                                                                                                       frameworkContext);
            var schemaRepositoryFactory = new SchemaRepositoryFactory(providerMetadata, revisionSchemaSessionFactory,
                                                                      frameworkContext, dependencyHelper);

            var entityRepositoryFactory = new EntityRepositoryFactory(providerMetadata, revisionRepositoryFactory,
                                                          schemaRepositoryFactory, frameworkContext,
                                                          dependencyHelper);

            ProviderSetup singleWriter = GetWriterProvider(providerMetadata, frameworkContext, entityRepositoryFactory);

            ReadonlyProviderSetup singleReader = GetReaderProvider(providerMetadata, revisionRepositoryFactory,
                                                                   schemaRepositoryFactory, frameworkContext,
                                                                   dependencyHelper, config);

            Func<AbstractMappingEngine> addTypemapper = () => new ManualMapperv2(new NhLookupHelper(entityRepositoryFactory), providerMetadata);
            frameworkContext.TypeMappers.Add(new Lazy<AbstractMappingEngine, TypeMapperMetadata>(addTypemapper, new TypeMapperMetadata(true)));
            IHiveManager hive = new HiveManager(new[]
                                                    {
                                                        new ProviderMappingGroup(
                                                            "test",
                                                            new WildcardUriMatch("content://"),
                                                            singleReader,
                                                            singleWriter,
                                                            frameworkContext)
                                                    }, frameworkContext);
            return hive;
        }
        public MembershipWrapperTestSetupHelper(FakeFrameworkContext frameworkContext = null)
        {
            //clear out the Roles/Users xml files for the test membership provider
            var current = new DirectoryInfo(Common.CurrentAssemblyDirectory);
            while (current.Parent.GetDirectories("App_Data").SingleOrDefault() == null)
            {
                current = current.Parent;
            }
            var appData = current.Parent.GetDirectories("App_Data").Single();
            foreach (var f in appData.GetFiles("*.xml"))
            {
                f.Delete();
            }
            foreach (var f in appData.GetFiles("*.orig"))
            {
                f.CopyTo(Path.Combine(f.Directory.FullName, Path.GetFileNameWithoutExtension(f.Name) + ".xml"));
            }

            _fakeFrameworkContext = frameworkContext ?? new FakeFrameworkContext();
            var attributeTypeRegistry = new CmsAttributeTypeRegistry();
            var mapper = new MembershipWrapperModelMapper(attributeTypeRegistry, _fakeFrameworkContext);
            _fakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { mapper, new FrameworkModelMapper(_fakeFrameworkContext) }));

            var providerMetadata = new ProviderMetadata("r-unit-tester", new Uri("tester://"), true, false);

            //need to reset our custom membership provider before each test
            var membershipProvider = global::System.Web.Security.Membership.Providers.Cast<MembershipProvider>().OfType<CustomXmlMembershipProvider>().Single();
            membershipProvider.Reset();

            var configuredProviders = new List<ProviderElement>(new[] {new ProviderElement() {Name = "test", WildcardCharacter = "*"}});

            var revisionSchemaFactory = new NullProviderRevisionRepositoryFactory<EntitySchema>(providerMetadata, _fakeFrameworkContext);
            var revisionRepositoryFactory = new NullProviderRevisionRepositoryFactory<TypedEntity>(providerMetadata, _fakeFrameworkContext);
            var schemaRepositoryFactory = new NullProviderSchemaRepositoryFactory(providerMetadata, _fakeFrameworkContext);
            var entityRepositoryFactory = new EntityRepositoryFactory(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, _fakeFrameworkContext,
                                                                      new Lazy<IEnumerable<MembershipProvider>>(() => global::System.Web.Security.Membership.Providers.Cast<MembershipProvider>()),
                                                                      configuredProviders);

            var readUnitFactory = new ReadonlyProviderUnitFactory(entityRepositoryFactory);
            var unitFactory = new ProviderUnitFactory(entityRepositoryFactory);

            ProviderSetup = new ProviderSetup(unitFactory, providerMetadata, _fakeFrameworkContext, null, 0);
            ReadonlyProviderSetup = new ReadonlyProviderSetup(readUnitFactory, providerMetadata, _fakeFrameworkContext, null, 0);
        }
        public static ProviderMappingGroup GenerateProviderGroup(int numberOfProviders, int numberOfPassthroughProviders, int numberOfMockedEntities, IFrameworkContext frameworkContext)
        {
            Func<int, bool, IEnumerable<Tuple<ProviderSetup, ReadonlyProviderSetup>>> generate = (count, isPassthrough) =>
                {
                    var generateProviders = new List<Tuple<ProviderSetup, ReadonlyProviderSetup>>();
                    for (int i = 0; i < count; i++)
                    {
                        var mockKey = "test" + (isPassthrough ? "_passthrough" : String.Empty) + i;
                        var metadata = new ProviderMetadata(mockKey, new Uri("content://"), true, isPassthrough);
                        var factory = MockEntityRepositoryFactory(numberOfMockedEntities, metadata, frameworkContext);
                        var setup = new ProviderSetup(new ProviderUnitFactory(factory), metadata, frameworkContext, null, 0);
                        var readonlySetup = new ReadonlyProviderSetup(new ReadonlyProviderUnitFactory(factory), metadata, frameworkContext, null, 0);
                        generateProviders.Add(new Tuple<ProviderSetup, ReadonlyProviderSetup>(setup, readonlySetup));
                    }
                    return generateProviders;
                };

            var uris = new[] { "content://boots/", "content://bags/", "content://shoes/" };
            var uriMatches = EnumerableExtensions.Range(count => new WildcardUriMatch(new Uri(uris[count])), 3);
            var injectMockedProviders = generate.Invoke(numberOfProviders, false)
                .Concat(generate.Invoke(numberOfPassthroughProviders, true));
            return new ProviderMappingGroup("test", uriMatches, injectMockedProviders.Select(x => x.Item2), injectMockedProviders.Select(x => x.Item1), new FakeFrameworkContext());
        }
Ejemplo n.º 20
0
 public ReadonlyProviderSetup(ReadonlyProviderUnitFactory unitFactory, ProviderMetadata providerMetadata, IFrameworkContext frameworkContext, AbstractProviderBootstrapper bootstrapper, int priorityOrdinal)
     : base(providerMetadata, frameworkContext, bootstrapper, priorityOrdinal)
 {
     ReadonlyUnitFactory = unitFactory;
 }
 public NullProviderDependencyHelper(ProviderMetadata providerMetadata) : base(providerMetadata)
 {
 }
Ejemplo n.º 22
0
 public UninstalledReadonlyProviderSetup(ProviderMetadata providerMetadata, IFrameworkContext frameworkContext, AbstractProviderBootstrapper bootstrapper, int priorityOrdinal)
     : base(providerMetadata, frameworkContext, bootstrapper, priorityOrdinal)
 {
 }
Ejemplo n.º 23
0
 public DependencyHelper(NhFactoryHelper nhFactoryHelper, ProviderMetadata providerMetadata)
     : base(providerMetadata)
 {
     FactoryHelper = nhFactoryHelper;
 }
Ejemplo n.º 24
0
 public DependencyHelper(Settings settings, ProviderMetadata providerMetadata) : base(providerMetadata)
 {
     Settings = settings;
 }
 private ProviderSetup GetWriterProvider(ProviderMetadata providerMetadata,
                                         IFrameworkContext frameworkContext, EntityRepositoryFactory entityRepositoryFactory)
 {
     var unitFactory = new ProviderUnitFactory(entityRepositoryFactory);
     var singleWriter = new ProviderSetup(unitFactory, providerMetadata, frameworkContext, null, 0);
     return singleWriter;
 }
        public static AbstractEntityRepositoryFactory MockEntityRepositoryFactory(int allItemCount, ProviderMetadata metadata, IFrameworkContext frameworkContext)
        {
            var entitySession = Substitute.For<AbstractEntityRepository>(metadata, new TransactionMock(), frameworkContext);

            entitySession.CanReadRelations.Returns(true);
            entitySession.CanWriteRelations.Returns(true);

            entitySession
                .PerformGet<TypedEntity>(Arg.Any<bool>(), Arg.Any<HiveId[]>())
                .Returns(x => EnumerableExtensions.Range(count => HiveModelCreationHelper.MockTypedEntity(HiveId.ConvertIntToGuid(count + 1)), 3));

            entitySession
                .PerformGetAll<TypedEntity>()
                .Returns(x => EnumerableExtensions.Range(count => HiveModelCreationHelper.MockTypedEntity(HiveId.ConvertIntToGuid(count + 5)), allItemCount));

            entitySession
                .PerformGetAncestorRelations(Arg.Any<HiveId>(), Arg.Any<RelationType>())
                .Returns(MockRelations(MockRelationCount));

            entitySession
                .PerformGetDescendentRelations(Arg.Any<HiveId>(), Arg.Any<RelationType>())
                .Returns(MockRelations(MockRelationCount));

            entitySession
                .PerformGetParentRelations(Arg.Any<HiveId>(), Arg.Any<RelationType>())
                .Returns(MockRelations(MockRelationCount));

            entitySession
                .PerformGetChildRelations(Arg.Any<HiveId>(), Arg.Any<RelationType>())
                .Returns(MockRelations(MockRelationCount));

            var factory = Substitute.For<AbstractEntityRepositoryFactory>(null, null, null, frameworkContext, null);
            factory.GetRepository().Returns(entitySession);
            return factory;
        }
 protected ProviderDependencyHelper(ProviderMetadata providerMetadata)
 {
     ProviderMetadata = providerMetadata;
 }
Ejemplo n.º 28
0
        public void Build(IContainerBuilder containerBuilder, IBuilderContext context)
        {
            var config2 = context.ConfigurationResolver.GetConfigSection(HiveConfigSection.ConfigXmlKey) as HiveConfigSection;

            if (config2 == null)
                throw new ConfigurationErrorsException(string.Format("Cannot find {0} section in application configuration.", HiveConfigSection.ConfigXmlKey));

            var providerMapElements = DeepConfigManager.Default.GetPluginSettings<HiveConfigSection, ProviderMappingElementCollection>(HiveConfigSection.ConfigXmlKey, x => x.ProviderMappings).SelectMany(x => x);
            var mappings = providerMapElements.Distinct().ToArray();

            var mergedMappings = mappings.Select(x => new
                {
                    MappingName = x.Key,
                    Original = x,
                    ReadWriters = mappings.Where(y => y.Key == x.Key).SelectMany(y => y.ReadWriters).Distinct().ToArray(),
                    Readers = mappings.Where(y => y.Key == x.Key).SelectMany(y => y.Readers).Distinct().ToArray(),
                    UriMatches = mappings.Where(y => y.Key == x.Key).SelectMany(y => y.UriMatches).Distinct().ToArray(),
                    TotalOriginalsWithSameKey = mappings.Count(y => y.Key == x.Key)
                }).ToArray();

            foreach (var providerMapping in mergedMappings.DistinctBy(x => x.MappingName))
            {
                // Check for duplicates in config
                var mappingName = providerMapping.MappingName;

                if (providerMapping.TotalOriginalsWithSameKey > 1)
                    LogHelper.TraceIfEnabled<HiveDemandBuilder>("Warning: more than one provider group has been specified in Hive configuration with key '{0}', possibly as a result of a plugin's config. {1} sets of configuration have been merged.".InvariantFormat(mappingName, providerMapping.TotalOriginalsWithSameKey));

                var mappedReaderKeys = providerMapping.Readers.OrderBy(x => x.Ordinal).Select(x => x.ProviderKey).ToArray();
                var mappedReadWriterKeys = providerMapping.ReadWriters.OrderBy(x => x.Ordinal).Select(x => x.ProviderKey).ToArray();

                foreach (ReadWriterTypeReferenceElement readWriter in providerMapping.ReadWriters)
                {
                    // Register ProviderSetups for each read-writer
                    ReadWriterTypeReferenceElement writer = readWriter;
                    var mappingKey = mappingName;
                    containerBuilder.ForFactory(x =>
                            {
                                var metadata = new ProviderMetadata(writer.ProviderKey, null, false, writer.IsPassthrough);

                                var getBootstrapper = x.TryResolve<AbstractProviderBootstrapper>(writer.ProviderKey);
                                if (!getBootstrapper.Success)
                                    LogHelper.Warn<HiveDemandBuilder>("No bootstrapper was registered for Hive provider {0}", writer.ProviderKey);

                                var getRepositoryFactory = x.TryResolve<AbstractEntityRepositoryFactory>(writer.ProviderKey);
                                if (getRepositoryFactory.Success)
                                {
                                    var unitFactory = new ProviderUnitFactory(getRepositoryFactory.Value);
                                    return new ProviderSetup(unitFactory, metadata, x.Resolve<IFrameworkContext>(),
                                                             getBootstrapper.Value, 0);
                                }

                                LogHelper.Warn<HiveDemandBuilder>(
                                    "Config '{0}' wants read-write provider with key {1} but it's not registered - check the available providers section. Error: {2}",
                                    mappingKey, writer.ProviderKey, getRepositoryFactory.Error.Message);

                                // We couldn't get a session factory, so register an "UninstalledProviderSetup" instead
                                return new UninstalledProviderSetup(metadata, x.Resolve<IFrameworkContext>(), getBootstrapper.Value, 0);
                            })
                        //.KnownAsSelf()
                        .Named<ProviderSetup>(writer.ProviderKey)
                        .ScopedAs.Singleton();
                }

                foreach (ReaderTypeReferenceElement reader in providerMapping.Readers)
                {
                    // Register ReadonlyProviderSetups for each reader
                    ReaderTypeReferenceElement readerLocalCopy = reader;
                    var mappingKey = mappingName;
                    containerBuilder.ForFactory(x =>
                            {
                                var metadata = new ProviderMetadata(readerLocalCopy.ProviderKey, null, false, readerLocalCopy.IsPassthrough);

                                var getBootstrapper = x.TryResolve<AbstractProviderBootstrapper>(readerLocalCopy.ProviderKey);
                                if (!getBootstrapper.Success)
                                    LogHelper.Warn<HiveDemandBuilder>("No bootstrapper was registered for Hive provider {0}", readerLocalCopy.ProviderKey);

                                var getRepositoryFactory = x.TryResolve<AbstractEntityRepositoryFactory>(readerLocalCopy.ProviderKey);
                                if (getRepositoryFactory.Success)
                                {
                                    var unitFactory = new ReadonlyProviderUnitFactory(getRepositoryFactory.Value);
                                    return new ReadonlyProviderSetup(unitFactory, metadata,
                                                                     x.Resolve<IFrameworkContext>(),
                                                                     getBootstrapper.Value, 0);
                                }

                                LogHelper.Warn<HiveDemandBuilder>(
                                    "Config '{0}' wants reader provider with key {1} but it's not registered or can't be instantiated - check the available providers section. Error: {2}",
                                    mappingKey, readerLocalCopy.ProviderKey, getRepositoryFactory.Error.Message);

                                // We couldn't get a session factory, so register an "UninstalledReadonlyProviderSetup" instead
                                return new UninstalledReadonlyProviderSetup(metadata, x.Resolve<IFrameworkContext>(), getBootstrapper.Value, 0);
                            })
                        //.KnownAsSelf()
                        .Named<ReadonlyProviderSetup>(readerLocalCopy.ProviderKey)
                        .ScopedAs.Singleton();
                }


                // Register IUriMatches for each mapping group
                foreach (UriMatchElement uriMatch in providerMapping.UriMatches)
                {
                    // Copy to a locally-scoped instance since the variable usage is wrapped in an anon delegate for later use
                    var match = uriMatch;

                    containerBuilder.ForFactory(x =>
                                                    {
                                                        if (!Uri.IsWellFormedUriString(match.UriPattern, UriKind.Absolute))
                                                            throw new InvalidOperationException("Hive config is invalid: '{0}' needs to be changed to a valid absolute Uri".InvariantFormat(match.UriPattern));

                                                        return new WildcardUriMatch(new Uri(match.UriPattern));
                                                    })
                        .Named<WildcardUriMatch>(mappingName)
                        .ScopedAs.Singleton();
                }

                // For every mapping group in config, register a DefaultHiveMappingGroup
                // with a constructor which accepts the map key, and all the available readers and writers which
                // map the keys selected in this group
                containerBuilder.ForFactory(
                    x => GenerateMappingGroup(mappingName, x, mappedReadWriterKeys, mappedReaderKeys))
                    .KnownAsSelf() // Register unnamed as well as named services to aid passing all registered groups into ctor params of type IEnumerable<ProviderMappingGroup>
                    .Named<ProviderMappingGroup>(mappingName)
                    .ScopedAs.Singleton();

            }

            //TODO: Remove magic strings for perf counter declarations
            containerBuilder
                .ForInstanceOfType(new HiveCounterManager("Hive 5.0", "TBD", "DEV"))
                .ScopedAs.Singleton();

            containerBuilder.ForFactory(x =>
                {
                    var groups = x.ResolveAll<ProviderMappingGroup>().DistinctBy(y => y.Key);
                    var framework = x.Resolve<IFrameworkContext>();
                    var perf = x.TryResolve<HiveCounterManager>();
                    return new HiveManager(groups, perf.Success ? perf.Value : null, framework);
                })
                .KnownAs<IHiveManager>()
                .KnownAsSelf()
                .ScopedAs.Singleton();

            containerBuilder.ForFactory(x => GetCacheWatcherTaskFactory(x, TaskTriggers.Hive.PostAddOrUpdateOnUnitComplete))
                .KnownAs<Lazy<AbstractTask, TaskMetadata>>()
                .ScopedAs.Singleton();

            containerBuilder.ForFactory(x => GetCacheWatcherTaskFactory(x, TaskTriggers.Hive.PostReadEntity))
                .KnownAs<Lazy<AbstractTask, TaskMetadata>>()
                .ScopedAs.Singleton();
        }
Ejemplo n.º 29
0
 public ManualMapperv2(AbstractLookupHelper lookupHelper, ProviderMetadata hiveProvider)
 {
     _lookupHelper = lookupHelper;
     _hiveProvider = hiveProvider;
     _rdbmsToModelMapper = new RdbmsToModelMapper(_hiveProvider);
 }
        private ReadonlyProviderSetup GetReaderProvider(ProviderMetadata providerMetadata,
                                                        RevisionRepositoryFactory revisionRepositoryFactory,
                                                        SchemaRepositoryFactory schemaRepositoryFactory,
                                                        IFrameworkContext frameworkContext,
                                                        ProviderDependencyHelper dependencyHelper, Configuration config)
        {
            AbstractReadonlyEntityRepositoryFactory readonlyEntityRepositoryFactory =
                new EntityRepositoryFactory(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory,
                                            frameworkContext, dependencyHelper);

            var readonlyUnitFactory = new ReadonlyProviderUnitFactory(readonlyEntityRepositoryFactory);
            AbstractProviderBootstrapper bootstrapper = new ProviderBootstrapper(config, null);
            var singleReader = new ReadonlyProviderSetup(readonlyUnitFactory, providerMetadata, frameworkContext,
                                                         bootstrapper, 0);
            return singleReader;
        }