コード例 #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);
        }
コード例 #2
0
        public static IGroupUnit <TFilter> OpenWriter <TFilter>(this IHiveManager hiveManager, Uri providerMappingRoot)
            where TFilter : class, IProviderTypeFilter
        {
            var factory = hiveManager.GetWriter <TFilter>(providerMappingRoot);

            return(factory.Create <TFilter>());
        }
コード例 #3
0
        public static IGroupUnit <TFilter> OpenWriter <TFilter>(this IHiveManager hiveManager, AbstractScopedCache overrideCacheScope = null)
            where TFilter : class, IProviderTypeFilter
        {
            var factory = hiveManager.GetWriter <TFilter>();

            return(factory.Create <TFilter>(overrideCacheScope));
        }
コード例 #4
0
        public void Setup()
        {
            // Setup languages
            _languages = new List<LanguageElement>
            {
                new LanguageElement
                {
                    IsoCode = "en-GB",
                    Name = "English (United Kingdom)",
                    Fallbacks = new FallbackCollection
                    {
                        new FallbackElement { IsoCode = "en-US" }
                    }
                },
                new LanguageElement
                {
                    IsoCode = "en-US",
                    Name = "English (United States)",
                    Fallbacks = new FallbackCollection()
                }
            };

            // Setup hive
            var context = new FakeFrameworkContext();
            //_hiveManager = FakeHiveCmsManager.NewWithNhibernate(new[] { CreateFakeDictionaryMappingGroup(context) }, context);
            _hiveManager = new HiveManager(CreateFakeDictionaryMappingGroup(context), context);

            var root = new TypedEntity
            {
                Id = FixedHiveIds.DictionaryVirtualRoot,
                EntitySchema = FixedSchemas.DictionaryRootSchema,
                UtcCreated = DateTime.Now,
                UtcModified = DateTime.Now,
                UtcStatusChanged = DateTime.Now
            };

            var item1 = CreateDictionatyItem("test1", new Dictionary<string, string> { { "en-GB", "Hello GB" }, { "en-US", "Hello US" } });
            var item2 = CreateDictionatyItem("test2", new Dictionary<string, string> { { "en-GB", "World GB" }, { "en-US", "World US" } });
            var item3 = CreateDictionatyItem("test3", new Dictionary<string, string> { { "en-GB", "Something GB" }, { "en-US", "Something US" } });

            // Act
            var writer = _hiveManager.GetWriter<IDictionaryStore>();
            using (var uow = writer.Create<IDictionaryStore>())
            {
                // Add entities
                uow.Repositories.AddOrUpdate(root);
                uow.Repositories.Revisions.AddOrUpdate(item1);
                uow.Repositories.Revisions.AddOrUpdate(item2);
                uow.Repositories.Revisions.AddOrUpdate(item3);

                // Add all relations
                uow.Repositories.AddRelation(FixedHiveIds.DictionaryVirtualRoot, item1.Item.Id, FixedRelationTypes.DefaultRelationType, 0);
                uow.Repositories.AddRelation(FixedHiveIds.DictionaryVirtualRoot, item2.Item.Id, FixedRelationTypes.DefaultRelationType, 0);
                uow.Repositories.AddRelation(item2.Item.Id, item3.Item.Id, FixedRelationTypes.DefaultRelationType, 0);
                uow.Complete();
            }
        }
コード例 #5
0
        public TUserType Create(TUserType user, out MembershipCreateStatus status)
        {
            //TODO: Could do with making this transactional somehow?

            // Create the uer
            var membershipUser = MembershipProvider.CreateUser(user.Username,
                                                               user.Password,
                                                               user.Email,
                                                               user.PasswordQuestion,
                                                               user.PasswordAnswer,
                                                               user.IsApproved,
                                                               user.ProviderUserKey,
                                                               out status);

            if (status != MembershipCreateStatus.Success)
            {
                return(user);
            }

            user.ProviderUserKey = membershipUser.ProviderUserKey;

            // Create the profile
            var profile = new TProfileType();

            // Set up the new profile with the same schema as the user so it has any inherited properties
            profile.SetupFromSchema(user.EntitySchema);

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

            // Map the user to the profile now
            _frameworkContext.TypeMappers.Map(user, profile);

            var hive = _hiveManager.GetWriter <ISecurityStore>(new Uri(_profileProviderMappingRoot));

            using (var uow = hive.Create())
            {
                uow.Repositories.AddOrUpdate(profile);

                uow.Repositories.AddRelation(_profileVirtualRootId, profile.Id, FixedRelationTypes.DefaultRelationType, 0);

                uow.Complete();
            }

            // Assign user to groups
            var groupHive = _hiveManager.GetWriter <ISecurityStore>(new Uri(_groupsProviderMappingRoot));

            using (var uow = groupHive.Create())
            {
                if (user.Groups != null)
                {
                    foreach (var groupId in user.Groups)
                    {
                        uow.Repositories.AddRelation(new Relation(FixedRelationTypes.UserGroupRelationType, groupId, profile.Id));
                    }
                }

                uow.Complete();
            }

            //NOTE: This causes another hit to the db but I do it to ensure all profile props are set
            return(ConvertToMergedEntity(membershipUser));
        }
コード例 #6
0
 /// <summary>
 /// Gets a <see cref="GroupUnitFactory{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 GroupUnitFactory <TFilter> GetWriter <TFilter>() where TFilter : class, IProviderTypeFilter
 {
     return(_innerHiveManager.GetWriter <TFilter>());
 }