Inheritance: AbstractProviderSetup
        public static Content SetupTestContentData(Guid newGuid, Guid newGuidRedHerring, ProviderSetup providerSetup)
        {
            var baseEntity = HiveModelCreationHelper.MockTypedEntity();
            var entity = new Content(baseEntity); 
            entity.Id = new HiveId(newGuid);
            entity.EntitySchema.Alias = "schema-alias1";

            var existingDef = entity.EntitySchema.AttributeDefinitions[0];
            var newDef = HiveModelCreationHelper.CreateAttributeDefinition("aliasForQuerying", "", "", existingDef.AttributeType, existingDef.AttributeGroup, true);
            entity.EntitySchema.AttributeDefinitions.Add(newDef);
            entity.Attributes.Add(new TypedAttribute(newDef, "my-new-value"));

            entity.Attributes[1].DynamicValue = "not-on-red-herring";
            entity.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "my-test-route";

            var redHerringEntity = HiveModelCreationHelper.MockTypedEntity();
            redHerringEntity.Id = new HiveId(newGuidRedHerring);
            redHerringEntity.EntitySchema.Alias = "redherring-schema";

            using (var uow = providerSetup.UnitFactory.Create())
            {
                var publishedRevision = new Revision<TypedEntity>(entity)
                    { MetaData = { StatusType = FixedStatusTypes.Published } };

                uow.EntityRepository.Revisions.AddOrUpdate(publishedRevision);
                // Only add extra entity if caller wants it
                if (newGuidRedHerring != Guid.Empty) uow.EntityRepository.AddOrUpdate(redHerringEntity);
                uow.Complete();
            }

            return entity;
        }
        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 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);
        }
        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());
        }
        public static TypedEntity SetupTestData(Guid newGuid, Guid newGuidRedHerring, ProviderSetup providerSetup)
        {
            var entity = HiveModelCreationHelper.MockTypedEntity();
            entity.Id = new HiveId(newGuid);
            entity.EntitySchema.Alias = "schema-alias1";

            var existingDef = entity.EntitySchema.AttributeDefinitions[0];
            var newDef = HiveModelCreationHelper.CreateAttributeDefinition("aliasForQuerying", "", "", existingDef.AttributeType, existingDef.AttributeGroup, true);

            var boolType = new AttributeType("boolean", "", "", new BoolSerializationType());
            var newDef_bool = HiveModelCreationHelper.CreateAttributeDefinition(BoolDefAlias, "", "", boolType, existingDef.AttributeGroup, true);

            entity.EntitySchema.AttributeDefinitions.Add(newDef);
            entity.EntitySchema.AttributeDefinitions.Add(newDef_bool);
            entity.Attributes.Add(new TypedAttribute(newDef, "my-new-value"));
            entity.Attributes.Add(new TypedAttribute(newDef_bool, true));

            entity.Attributes[1].DynamicValue = "not-on-red-herring";
            entity.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "my-test-route";

            var redHerringEntity = HiveModelCreationHelper.MockTypedEntity();
            redHerringEntity.Id = new HiveId(newGuidRedHerring);
            redHerringEntity.EntitySchema.Alias = "redherring-schema";
            var newDef_onRedHerring_bool = HiveModelCreationHelper.CreateAttributeDefinition(BoolDefAlias, "", "", boolType, existingDef.AttributeGroup, true);
            redHerringEntity.EntitySchema.AttributeDefinitions.Add(newDef_onRedHerring_bool);
            redHerringEntity.Attributes.Add(new TypedAttribute(newDef_onRedHerring_bool, "false"));

            using (var uow = providerSetup.UnitFactory.Create())
            {
                uow.EntityRepository.AddOrUpdate(entity);
                // Only add extra entity if caller wants it
                if (newGuidRedHerring != Guid.Empty) uow.EntityRepository.AddOrUpdate(redHerringEntity);
                uow.Complete();
            }

            return entity;
        }
示例#7
0
        public void FileProvider_ViaManager_GetRelations_DefaultRelationType()
        {
            // Arrange
            var ioTestSetup = new IoHiveTestSetupHelper();
            var unitFactory = new ProviderUnitFactory(ioTestSetup.EntityRepositoryFactory);
            var readonlyUnitFactory = new ReadonlyProviderUnitFactory(ioTestSetup.EntityRepositoryFactory);
            var provider = new ProviderSetup(unitFactory, ioTestSetup.ProviderMetadata, null, null, 0);
            var readonlyProvider = new ReadonlyProviderSetup(readonlyUnitFactory, ioTestSetup.ProviderMetadata, null, null, 0);

            var providerMappingGroup = new ProviderMappingGroup("default", new WildcardUriMatch("storage://*"), readonlyProvider, provider, ioTestSetup.FrameworkContext);

            var manager = new HiveManager(new[] { providerMappingGroup }, ioTestSetup.FrameworkContext);

            var actualFile = ioTestSetup.TestDirectory.GetFiles(ioTestSetup.Settings.SupportedExtensions, SearchOption.AllDirectories)
                .Where(x => x.FullName.Replace(ioTestSetup.Settings.AbsoluteRootedPath, string.Empty).Contains(@"\"))
                .Last();
            var parentFolder = actualFile.Directory;

            // Act
            using (var store = manager.OpenReader<IFileStore>())
            {
                var file = store.Repositories.Get<File>(new HiveId(actualFile.FullName));
                var parentRelations = store.Repositories.GetParentRelations(file.Id, FixedRelationTypes.DefaultRelationType);
                var parentsViaHandyMethod = store.Repositories.GetParentFileRelations(file);
                var firstParentRelation = store.Repositories.Get<File>(parentRelations.First().SourceId);

                //Assert
                // Check for iterator block mistakes
                Assert.That(parentRelations, Is.EquivalentTo(parentsViaHandyMethod));
                Assert.That(parentRelations.Count(), Is.GreaterThanOrEqualTo(1));
                Assert.AreEqual(parentFolder.FullName.NormaliseDirectoryPath(), firstParentRelation.RootedPath.NormaliseDirectoryPath());
            }
        }
        private static EntitySchema CreateAndSaveCompositeSchema(IAttributeTypeRegistry attributeTypeRegistry, ProviderSetup providerSetup)
        {
            var nameNameType = attributeTypeRegistry.GetAttributeType(NodeNameAttributeType.AliasValue);
            var textstringType = attributeTypeRegistry.GetAttributeType("singleLineTextBox");

            var schema1 = HiveModelCreationHelper.CreateEntitySchema("schema1", "Schema1", true, new[] { new AttributeDefinition(NodeNameAttributeDefinition.AliasValue, "Node Name")
            {
                Id = new HiveId("mi-schema1-name".EncodeAsGuid()),
                AttributeType = nameNameType,
                AttributeGroup = FixedGroupDefinitions.GeneralGroup,
                Ordinal = 0
            }, new AttributeDefinition("alias1", "Alias1")
            {
                Id = new HiveId("mi-schema1-alias1".EncodeAsGuid()),
                AttributeType = textstringType,
                AttributeGroup = new AttributeGroup("group1", "Group 1", 50).FixedDates(),
                Ordinal = 1
            } });
            schema1.AttributeGroups.Add(new AttributeGroup("empty-group", "Empty Group", 100).FixedDates());

            var schema2 = HiveModelCreationHelper.CreateEntitySchema("schema2", "Schema2", true, new[] { new AttributeDefinition(NodeNameAttributeDefinition.AliasValue, "Node Name")
            {
                Id = new HiveId("mi-schema2-name".EncodeAsGuid()),
                AttributeType = nameNameType,
                AttributeGroup = FixedGroupDefinitions.GeneralGroup,
                Ordinal = 0
            }, new AttributeDefinition("alias2", "Alias2")
            {
                Id = new HiveId("mi-schema2-alias2".EncodeAsGuid()),
                AttributeType = textstringType,
                AttributeGroup = new AttributeGroup("group1", "Group 1", 50).FixedDates(),
                Ordinal = 1
            } });

            var schema3 = HiveModelCreationHelper.CreateEntitySchema("schema3", "Schema3", true, new[] { new AttributeDefinition(NodeNameAttributeDefinition.AliasValue, "Node Name")
            {
                Id = new HiveId("mi-schema3-name".EncodeAsGuid()),
                AttributeType = nameNameType,
                AttributeGroup = FixedGroupDefinitions.GeneralGroup,
                Ordinal = 0
            }, new AttributeDefinition("alias3", "Alias3")
            {
                Id = new HiveId("mi-schema3-alias3".EncodeAsGuid()),
                AttributeType = textstringType,
                AttributeGroup = new AttributeGroup("group2", "Group 2", 100).FixedDates(),
                Ordinal = 1
            } });

            schema3.XmlConfiguration = XDocument.Parse("<test />");

            // Act
            using (var uow = providerSetup.UnitFactory.Create())
            {
                // Add schemas
                uow.EntityRepository.Schemas.AddOrUpdate(schema1);
                uow.EntityRepository.Schemas.AddOrUpdate(schema2);
                uow.EntityRepository.Schemas.AddOrUpdate(schema3);

                // Add relations
                uow.EntityRepository.Schemas.AddRelation(new Relation(FixedRelationTypes.DefaultRelationType, schema1.Id, schema2.Id));
                uow.EntityRepository.Schemas.AddRelation(new Relation(FixedRelationTypes.DefaultRelationType, schema2.Id, schema3.Id));

                uow.Complete();
            }

            return schema3;
        }