Ejemplo n.º 1
0
 public ProviderMappingGroup(string key,
     WildcardUriMatch singleMatch,
     ReadonlyProviderSetup singleReader,
     ProviderSetup singleWriter,
     IFrameworkContext frameworkContext)
     : this(key, Enumerable.Repeat(singleMatch, 1), Enumerable.Repeat(singleReader, 1), Enumerable.Repeat(singleWriter, 1), frameworkContext)
 {
     Mandate.ParameterNotNull(singleReader, "singleReader");
     Mandate.ParameterNotNull(singleWriter, "singleWriter");
 }
        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.º 3
0
        protected override TypedEntity CreateEntityForTest(Guid newGuid, Guid newGuidRedHerring, ProviderSetup providerSetup)
        {
            var entity = new Member()
            {
                Id         = new HiveId(newGuid),
                Email      = Guid.NewGuid().ToString("N") + "*****@*****.**",
                IsApproved = true,
                Name       = "Test",
                Password   = "******",
                Username   = "******" + Guid.NewGuid().ToString("N")   //must be unique
            };

            entity.Username = "******";
            entity.Name     = "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())
            {
                uow.EntityRepository.AddOrUpdate(entity);
                //uow.EntityRepository.AddOrUpdate(redHerringEntity);
                uow.Complete();
            }

            return(entity);
        }
        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);

            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())
            {
                uow.EntityRepository.AddOrUpdate(entity);
                // Only add extra entity if caller wants it
                if (newGuidRedHerring != Guid.Empty)
                {
                    uow.EntityRepository.AddOrUpdate(redHerringEntity);
                }
                uow.Complete();
            }

            return(entity);
        }