Inheritance: System.DisposableObject
 public AbstractProviderSetup(ProviderMetadata providerMetadata, IFrameworkContext frameworkContext, AbstractProviderBootstrapper bootstrapper, int priorityOrdinal)
 {
     ProviderMetadata = providerMetadata;
     FrameworkContext = frameworkContext;
     Bootstrapper = bootstrapper;
     PriorityOrdinal = priorityOrdinal;
 }
 internal EntityRepositoryFactory(ProviderMetadata providerMetadata,
     AbstractRevisionRepositoryFactory<TypedEntity> revisionRepositoryFactory,
     AbstractSchemaRepositoryFactory schemaRepositoryFactory, Settings settings,
     IFrameworkContext frameworkContext)
     : base(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext, new DependencyHelper(settings, providerMetadata))
 {
 }
 /// <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))
 {
 }
 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");
 }
        //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)
        {
        }
Example #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;
        }
        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);
        }
 /// <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);
        }
        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 RebelExamineIndexer(
                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);
        }
Example #11
0
 public DependencyHelper(
     IEnumerable<ProviderElement> configuredProviders,
     Lazy<IEnumerable<MembershipProvider>> membershipProviders,             
     ProviderMetadata providerMetadata)
     : base(providerMetadata)
 {
     MembershipProviders = membershipProviders;
     ConfiguredProviders = configuredProviders;
 }
        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);
        }
        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 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());
        }
Example #16
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);
                                }

                                if (getRepositoryFactory.Error != null)
                                {
                                    var inner = getRepositoryFactory.Error.InnerException;
                                    string innerMessage = (inner != null) ? inner.Message : string.Empty;
                                    var message = "Hive group '{0}' has its config pointing at writer key '{1}', but an error occurred trying to create it. Error: {2}";
                                    if (!innerMessage.IsNullOrWhiteSpace()) message = message + " Inner error: " + innerMessage;
                                    LogHelper.Error<HiveDemandBuilder>(message.InvariantFormat(mappingKey, writer.ProviderKey, getRepositoryFactory.Error.Message), getRepositoryFactory.Error);
                                }
                                else
                                {
                                    LogHelper.Warn<HiveDemandBuilder>("Config '{0}' wants read-write provider with key {1} but it's not registered", mappingKey, writer.ProviderKey);
                                }

                                // 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);
                                }

                                if (getRepositoryFactory.Error != null)
                                {
                                    var inner = getRepositoryFactory.Error.InnerException;
                                    string innerMessage = (inner != null) ? inner.Message : string.Empty;
                                    var message = "Hive group '{0}' has its config pointing at reader key '{1}', but an error occurred trying to create it. Error: {2}";
                                    if (!innerMessage.IsNullOrWhiteSpace()) message = message + " Inner error: " + innerMessage;
                                    LogHelper.Error<HiveDemandBuilder>(message.InvariantFormat(mappingKey, reader.ProviderKey, getRepositoryFactory.Error.Message), getRepositoryFactory.Error);
                                }
                                else
                                {
                                    LogHelper.Warn<HiveDemandBuilder>("Config '{0}' wants read provider with key {1} but it's not registered", mappingKey, reader.ProviderKey);
                                }

                                // 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();
        }
Example #17
0
 public DependencyHelper(ExamineHelper helper, ProviderMetadata providerMetadata)
     : base(providerMetadata)
 {
     ExamineHelper = helper;
 }
 public ReadonlyProviderSetup(ReadonlyProviderUnitFactory unitFactory, ProviderMetadata providerMetadata, IFrameworkContext frameworkContext, AbstractProviderBootstrapper bootstrapper, int priorityOrdinal)
     : base(providerMetadata, frameworkContext, bootstrapper, priorityOrdinal)
 {
     ReadonlyUnitFactory = unitFactory;
 }
 public UninstalledReadonlyProviderSetup(ProviderMetadata providerMetadata, IFrameworkContext frameworkContext, AbstractProviderBootstrapper bootstrapper, int priorityOrdinal)
     : base(providerMetadata, frameworkContext, bootstrapper, priorityOrdinal)
 {
 }
Example #20
0
        public void HiveManager_OpensContentWriter_InferredFromRepositoryType()
        {
            // Arrange
            var context = new FakeFrameworkContext();
            var metadata = new ProviderMetadata("test", new Uri("unimportant://"), true, false);
            var groups = new[]
                             {
                                 new ProviderMappingGroup("default-content",
                                                          new WildcardUriMatch("content://*"),
                                                          new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          context),
                                 new ProviderMappingGroup("default-storage",
                                                          new WildcardUriMatch("storage://*"),
                                                          new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          context),
                                 new ProviderMappingGroup("default-assets",
                                                          new WildcardUriMatch("assets://*"),
                                                          new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          context)
                             };
            HiveManager manager = new HiveManager(groups , context);

            // Act
            var writer = manager.OpenWriter<IContentStore>();

            // Assert
            Assert.IsNotNull(writer);
        }
Example #21
0
        public void HiveManagerExtension_GetsProviderMatch_FromCustomRoot(string customRoot)
        {
            // Arrange
            var context = new FakeFrameworkContext();
            var metadata = new ProviderMetadata("test", new Uri("unimportant://"), true, false);
            var groups = new[]
                             {
                                 new ProviderMappingGroup("default-content",
                                                          new WildcardUriMatch("content://*"),
                                                          new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          context),
                                 new ProviderMappingGroup("default-storage",
                                                          new WildcardUriMatch("storage://*"),
                                                          new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          context),
                                 new ProviderMappingGroup("default-assets",
                                                          new WildcardUriMatch("assets://*"),
                                                          new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), 
                                                          context)
                             };
            HiveManager manager = new HiveManager(groups, context);

            // Act
            var work = manager.GetProviderGroup(new Uri(customRoot));

            // Assert
            Assert.NotNull(work);
        }
Example #22
0
        public void ProviderMappingGroup_IsMatchForUri(string assertUri, string[] wildcardMatches, bool shouldMatch)
        {
            // Arrange
            var matches = wildcardMatches.Select(x => new WildcardUriMatch(x)).ToList();
            var context = new FakeFrameworkContext();
            var metadata = new ProviderMetadata("test", new Uri("unimportant://"), true, false);
            var readonlySetup = new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0);
            var setup = new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0);
            var group = new ProviderMappingGroup("default", matches, Enumerable.Repeat(readonlySetup, 1), Enumerable.Repeat(setup, 1), new FakeFrameworkContext());

            // Assert
            Assert.That(shouldMatch, Is.EqualTo(group.IsMatchForUri(new Uri(assertUri)).Success));
        }
        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;
        }
Example #24
0
 public DependencyHelper(ProviderMetadata providerMetadata, CacheHelper cacheHelper)
     : base(providerMetadata)
 {
     Mandate.ParameterNotNull(cacheHelper, "cacheHelper");
     CacheHelper = cacheHelper;
 }
        private void AssignFakeIdsIfPassthrough(ProviderMetadata providerMetadata, params IReferenceByHiveId[] entity)
        {
            if (!providerMetadata.IsPassthroughProvider) 
                return;

            entity.ForEach(
                x =>
                {
                    var allItems = x.GetAllIdentifiableItems();
                    foreach (var referenceByHiveId in allItems)
                    {
                        // Only change / set certain ids otherwise relations are broken e.g. between an attributedefinition and its group
                        if (referenceByHiveId.Id.IsNullValueOrEmpty() && (TypeFinder.IsTypeAssignableFrom<TypedEntity>(referenceByHiveId)
                            || TypeFinder.IsTypeAssignableFrom<EntitySchema>(referenceByHiveId)
                            || TypeFinder.IsTypeAssignableFrom<Revision<TypedEntity>>(referenceByHiveId)))
                            referenceByHiveId.Id = new HiveId(providerMetadata.MappingRoot, providerMetadata.Alias, new HiveIdValue(Guid.NewGuid()));
                    }

                    // If we've specifically been given the item, then set its id irrespective of the rule above
                    if (x.Id.IsNullValueOrEmpty())
                        x.Id = new HiveId(providerMetadata.MappingRoot, providerMetadata.Alias, new HiveIdValue(Guid.NewGuid()));
                });
        }
 public NullProviderSchemaRepositoryFactory(ProviderMetadata providerMetadata, AbstractRevisionRepositoryFactory<EntitySchema> revisionRepositoryFactory, IFrameworkContext frameworkContext) 
     : base(providerMetadata, revisionRepositoryFactory, frameworkContext, new NullProviderDependencyHelper(providerMetadata))
 {
 }
Example #27
0
 public DependencyHelper(Settings settings, ProviderMetadata providerMetadata) : base(providerMetadata)
 {
     Settings = settings;
 }
 protected ProviderDependencyHelper(ProviderMetadata providerMetadata)
 {
     ProviderMetadata = providerMetadata;
 }
 public NullProviderSchemaRepositoryFactory(ProviderMetadata providerMetadata, IFrameworkContext frameworkContext)
     : this(providerMetadata, new NullProviderRevisionRepositoryFactory<EntitySchema>(providerMetadata, frameworkContext), frameworkContext)
 {
     
 }
 public NullProviderDependencyHelper(ProviderMetadata providerMetadata) : base(providerMetadata)
 {
 }