Beispiel #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);
        }
Beispiel #2
0
        public static IReadonlyGroupUnit <TFilter> OpenReader <TFilter>(this IHiveManager hiveManager, AbstractScopedCache overrideCacheScope = null)
            where TFilter : class, IProviderTypeFilter
        {
            var factory = hiveManager.GetReader <TFilter>();

            return(factory.CreateReadonly <TFilter>(overrideCacheScope));
        }
Beispiel #3
0
        public static IReadonlyGroupUnit <TFilter> OpenReader <TFilter>(this IHiveManager hiveManager, Uri providerMappingRoot)
            where TFilter : class, IProviderTypeFilter
        {
            var factory = hiveManager.GetReader <TFilter>(providerMappingRoot);

            return(factory.CreateReadonly());
        }
        public TUserType GetByProfileId(HiveId profileId, bool userIsOnline = false)
        {
            var hive = _hiveManager.GetReader <ISecurityStore>(new Uri(_profileProviderMappingRoot));

            using (var uow = hive.CreateReadonly())
            {
                var profile = uow.Repositories.Get <TProfileType>(profileId);
                if (profile == null)
                {
                    return(null);
                }

                if (MembershipProviderConfig != null)
                {
                    profile.SetProviderUserKeyType(MembershipProviderConfig.ProviderUserKeyType);
                }

                return(GetByProviderUserKey(profile.ProviderUserKey, userIsOnline));
            }
        }
        /// <summary>
        /// Gets a dictionary item.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="language">The language.</param>
        /// <returns></returns>
        public DictionaryResult GetDictionaryItem(string key, string language)
        {
            var languageConfig = _installedLanguages.SingleOrDefault(x => x.IsoCode == language);

            if (languageConfig == null)
            {
                return(new DictionaryResult(false, key));
            }

            var hive = _hiveManager.GetReader <IDictionaryStore>();

            using (var uow = hive.CreateReadonly())
            {
                var item = uow.Repositories.GetEntityByPath <TypedEntity>(FixedHiveIds.DictionaryVirtualRoot, key);
                if (item == null)
                {
                    return(new DictionaryResult(false, key));
                }

                var val = item.InnerAttribute <string>(DictionaryItemSchema.TranslationsAlias, languageConfig.IsoCode);
                if (!string.IsNullOrWhiteSpace(val))
                {
                    return(new DictionaryResult(true, key, val, languageConfig.IsoCode));
                }

                foreach (var fallback in languageConfig.Fallbacks)
                {
                    val = item.InnerAttribute <string>(DictionaryItemSchema.TranslationsAlias, fallback.IsoCode);
                    if (!string.IsNullOrWhiteSpace(val))
                    {
                        return(new DictionaryResult(true, key, val, fallback.IsoCode));
                    }
                }
            }
            return(new DictionaryResult(false, key));
        }
 /// <summary>
 /// Gets a <see cref="ReadonlyGroupUnitFactory{TFilter}"/> for a group of providers, by finding a matching group in the <see cref="IHiveManager.ProviderGroups"/> collection where the
 /// provider's mapping group root Uri matches the value with which <typeparamref name="TFilter"/> has been decorated. <typeparamref name="TFilter"/> must be decorated
 /// with a <see cref="RepositoryTypeAttribute"/> containing the provider group root Uri.
 /// </summary>
 /// <typeparam name="TFilter">The <see cref="IProviderTypeFilter"/> used to create extension methods against this provider group.</typeparam>
 /// <returns></returns>
 public ReadonlyGroupUnitFactory <TFilter> GetReader <TFilter>() where TFilter : class, IProviderTypeFilter
 {
     return(_innerHiveManager.GetReader <TFilter>());
 }