예제 #1
0
        /// <summary>
        /// Mocks a store on the provided IHiveManager mock
        /// </summary>
        /// <typeparam name="TFilter">The type of the filter.</typeparam>
        /// <param name="hive">The hive.</param>
        /// <param name="uri">The URI.</param>
        /// <param name="readonlyEntitySession">The readonly entity session.</param>
        /// <param name="readonlySchemaSession">The readonly schema session.</param>
        /// <param name="entityRepository">The entity session.</param>
        /// <param name="schemaRepository">The schema session.</param>
        /// <returns></returns>
        public static IHiveManager MockStore <TFilter>(
            this IHiveManager hive,
            string uri,
            out IReadonlyEntityRepositoryGroup <TFilter> readonlyEntitySession,
            out IReadonlySchemaRepositoryGroup <TFilter> readonlySchemaSession,
            out IEntityRepositoryGroup <TFilter> entityRepository,
            out ISchemaRepositoryGroup <TFilter> schemaRepository)
            where TFilter : class, IProviderTypeFilter
        {
            //mock hive
            var hiveReader = Substitute.For <IReadonlyGroupUnit <TFilter> >();
            var hiveWriter = Substitute.For <IGroupUnit <TFilter> >();

            hiveReader.FrameworkContext.Returns(hive.FrameworkContext);
            hiveWriter.FrameworkContext.Returns(hive.FrameworkContext);

            //mock readers
            readonlyEntitySession = Substitute.For <IReadonlyEntityRepositoryGroup <TFilter> >();
            readonlySchemaSession = Substitute.For <IReadonlySchemaRepositoryGroup <TFilter> >();
            readonlyEntitySession.Schemas.Returns(readonlySchemaSession);
            hiveReader.Repositories.Returns(readonlyEntitySession);

            //mock writers
            entityRepository = Substitute.For <IEntityRepositoryGroup <TFilter> >();
            entityRepository.FrameworkContext.Returns(hive.FrameworkContext);

            schemaRepository = Substitute.For <ISchemaRepositoryGroup <TFilter> >();
            entityRepository.Schemas.Returns(schemaRepository);
            hiveWriter.Repositories.Returns(entityRepository);

            RepositoryContext fakeRepositoryContext = FakeHiveCmsManager.CreateFakeRepositoryContext(hive.FrameworkContext);
            var readonlyGroupUnitFactory            = Substitute.For <ReadonlyGroupUnitFactory <TFilter> >(Enumerable.Empty <ReadonlyProviderSetup>(), new Uri(uri), fakeRepositoryContext, hive.FrameworkContext);

            readonlyGroupUnitFactory.CreateReadonly().Returns(hiveReader);
            readonlyGroupUnitFactory.CreateReadonly <TFilter>().Returns(hiveReader);

            var groupUnitFactory = Substitute.For <GroupUnitFactory <TFilter> >(Enumerable.Empty <ProviderSetup>(), new Uri(uri), fakeRepositoryContext, hive.FrameworkContext);

            groupUnitFactory.Create().Returns(hiveWriter);
            groupUnitFactory.Create <TFilter>().Returns(hiveWriter);

            hive.GetReader <TFilter>().Returns(readonlyGroupUnitFactory);
            hive.GetReader <TFilter>(null).ReturnsForAnyArgs(readonlyGroupUnitFactory);

            hive.GetWriter <TFilter>().Returns(groupUnitFactory);
            hive.GetWriter <TFilter>(null).ReturnsForAnyArgs(groupUnitFactory);

            return(hive);
        }
        //private readonly NHibernateInMemoryRepository _repo;

        public FakeUmbracoApplicationContext(bool addSystemRooNode = true)
            : this(FakeHiveCmsManager.New(new FakeFrameworkContext()), addSystemRooNode)
        {
        }