public void Built_In_Member_Type_Properties_Are_Automatically_Added_When_Creating()
    {
        var stubs = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper);

        var provider = ScopeProvider;

        using (provider.CreateScope())
        {
            var repository = CreateRepository(provider);

            IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();

            // created without the stub properties
            Assert.AreEqual(1, memberType.PropertyGroups.Count);
            Assert.AreEqual(3, memberType.PropertyTypes.Count());

            // saving *new* member type adds the stub properties
            repository.Save(memberType);

            // saving has added (and saved) the stub properties
            Assert.AreEqual(2, memberType.PropertyGroups.Count);
            Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count());

            // getting with stub properties
            memberType = repository.Get(memberType.Id);

            Assert.AreEqual(2, memberType.PropertyGroups.Count);
            Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count());
        }
    }
Exemplo n.º 2
0
    public void SavingPreservesPassword()
    {
        IMember sut;
        var     provider = ScopeProvider;

        using (var scope = provider.CreateScope())
        {
            var repository = CreateRepository(provider);

            var memberType = MemberTypeBuilder.CreateSimpleMemberType();
            MemberTypeRepository.Save(memberType);

            var member =
                MemberBuilder.CreateSimpleMember(memberType, "Johnny Hefty", "*****@*****.**", "123", "hefty");
            repository.Save(member);

            sut = repository.Get(member.Id);

            // When the password is null it will not overwrite what is already there.
            sut.RawPasswordValue = null;
            repository.Save(sut);

            sut = repository.Get(member.Id);

            Assert.That(sut.RawPasswordValue, Is.EqualTo("123"));
        }
    }
        public void Can_Persist_Member_Type()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                var memberType = (IMemberType)MemberTypeBuilder.CreateSimpleMemberType();
                repository.Save(memberType);

                IMemberType sut = repository.Get(memberType.Id);

                Dictionary <string, PropertyType> standardProps = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper);

                Assert.That(sut, Is.Not.Null);
                Assert.That(sut.PropertyGroups.Count, Is.EqualTo(2));
                Assert.That(sut.PropertyTypes.Count(), Is.EqualTo(3 + standardProps.Count));

                Assert.That(sut.PropertyGroups.Any(x => x.HasIdentity == false || x.Id == 0), Is.False);
                Assert.That(sut.PropertyTypes.Any(x => x.HasIdentity == false || x.Id == 0), Is.False);

                TestHelper.AssertPropertyValuesAreEqual(sut, memberType);
            }
        }
Exemplo n.º 4
0
    public void SavingUpdatesNameAndEmail()
    {
        IMember sut;
        var     provider = ScopeProvider;

        using (var scope = provider.CreateScope())
        {
            var repository = CreateRepository(provider);

            var memberType = MemberTypeBuilder.CreateSimpleMemberType();
            MemberTypeRepository.Save(memberType);

            var member =
                MemberBuilder.CreateSimpleMember(memberType, "Johnny Hefty", "*****@*****.**", "123", "hefty");
            repository.Save(member);

            sut          = repository.Get(member.Id);
            sut.Username = "******";
            sut.Email    = "*****@*****.**";
            repository.Save(sut);

            sut = repository.Get(member.Id);

            Assert.That(sut.Email, Is.EqualTo("*****@*****.**"));
            Assert.That(sut.Username, Is.EqualTo("This is new"));
        }
    }
        public void Built_In_Member_Type_Properties_Missing_Are_Automatically_Added_When_Creating()
        {
            Dictionary <string, PropertyType> stubs = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper);

            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();

                // created without the stub properties
                Assert.AreEqual(1, memberType.PropertyGroups.Count);
                Assert.AreEqual(3, memberType.PropertyTypes.Count());

                // add one stub property, others are still missing
                memberType.AddPropertyType(stubs.First().Value, Constants.Conventions.Member.StandardPropertiesGroupAlias, Constants.Conventions.Member.StandardPropertiesGroupName);

                // saving *new* member type adds the (missing) stub properties
                repository.Save(memberType);

                // saving has added (and saved) the (missing) stub properties
                Assert.AreEqual(2, memberType.PropertyGroups.Count);
                Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count());

                // getting with stub properties
                memberType = repository.Get(memberType.Id);

                Assert.AreEqual(2, memberType.PropertyGroups.Count);
                Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count());
            }
        }
Exemplo n.º 6
0
    public void MemberHasBuiltinProperties()
    {
        var provider = ScopeProvider;

        using (var scope = provider.CreateScope())
        {
            var repository = CreateRepository(provider);

            var memberType = MemberTypeBuilder.CreateSimpleMemberType();
            MemberTypeRepository.Save(memberType);

            var member =
                MemberBuilder.CreateSimpleMember(memberType, "Johnny Hefty", "*****@*****.**", "123", "hefty");
            repository.Save(member);

            var sut = repository.Get(member.Id);

            Assert.That(memberType.CompositionPropertyGroups.Count(), Is.EqualTo(2));
            Assert.That(memberType.CompositionPropertyTypes.Count(), Is.EqualTo(3 + ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper).Count));
            Assert.That(sut.Properties.Count(), Is.EqualTo(3 + ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper).Count));
            var grp = memberType.CompositionPropertyGroups.FirstOrDefault(x =>
                                                                          x.Name == Constants.Conventions.Member.StandardPropertiesGroupName);
            Assert.IsNotNull(grp);
            var aliases = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper).Select(x => x.Key)
                          .ToArray();
            foreach (var p in memberType.CompositionPropertyTypes.Where(x => aliases.Contains(x.Alias)))
            {
                Assert.AreEqual(grp.Id, p.PropertyGroupId.Value);
            }
        }
    }
Exemplo n.º 7
0
    public void Cannot_Save_MemberType_With_Empty_Name()
    {
        // Arrange
        IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType("memberTypeAlias", string.Empty);

        // Act & Assert
        Assert.Throws <ArgumentException>(() => MemberTypeService.Save(memberType));
    }
Exemplo n.º 8
0
        private void CreateTestDataForPagingTests(out List <IContent> createdContent, out List <IMember> createdMembers, out List <IMedia> createdMedia)
        {
            // Create content
            createdContent = new List <IContent>();
            ContentType contentType = ContentTypeBuilder.CreateBasicContentType("blah");

            ContentTypeService.Save(contentType);
            for (int i = 0; i < 3; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                ContentService.Save(c1);
                createdContent.Add(c1);
            }

            // Create media
            createdMedia = new List <IMedia>();
            MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage");

            MediaTypeService.Save(imageType);
            for (int i = 0; i < 3; i++)
            {
                Media c1 = MediaBuilder.CreateMediaImage(imageType, -1);
                MediaService.Save(c1);
                createdMedia.Add(c1);
            }

            // Create members
            MemberType memberType = MemberTypeBuilder.CreateSimpleMemberType("simple");

            MemberTypeService.Save(memberType);
            createdMembers = MemberBuilder.CreateSimpleMembers(memberType, 3).ToList();
            GetMemberService().Save(createdMembers);

            IRelationType relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);

            // Relate content to media
            foreach (IContent content in createdContent)
            {
                foreach (IMedia media in createdMedia)
                {
                    RelationService.Relate(content.Id, media.Id, relType);
                }
            }

            // Relate members to media
            foreach (IMember member in createdMembers)
            {
                foreach (IMedia media in createdMedia)
                {
                    RelationService.Relate(member.Id, media.Id, relType);
                }
            }
        }
Exemplo n.º 9
0
    public void Member_Cannot_View_Property()
    {
        IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();

        MemberTypeService.Save(memberType);

        // re-get
        memberType = MemberTypeService.Get(memberType.Id);
        foreach (var p in memberType.PropertyTypes)
        {
            Assert.IsFalse(memberType.MemberCanViewProperty(p.Alias));
        }
    }
    public void IMemberType_To_MemberTypeDisplay()
    {
        // Arrange
        var memberType = MemberTypeBuilder.CreateSimpleMemberType();
        var alias      = memberType.PropertyTypes.Last().Alias;

        memberType.SetIsSensitiveProperty(alias, true);
        memberType.SetMemberCanEditProperty(alias, true);
        memberType.SetMemberCanViewProperty(alias, true);
        MemberTypeBuilder.EnsureAllIds(memberType, 8888);

        // Act
        var result = _sut.Map <MemberTypeDisplay>(memberType);

        // Assert
        Assert.AreEqual(memberType.Alias, result.Alias);
        Assert.AreEqual(memberType.Description, result.Description);
        Assert.AreEqual(memberType.Icon, result.Icon);
        Assert.AreEqual(memberType.Id, result.Id);
        Assert.AreEqual(memberType.Name, result.Name);
        Assert.AreEqual(memberType.ParentId, result.ParentId);
        Assert.AreEqual(memberType.Path, result.Path);
        Assert.AreEqual(memberType.Thumbnail, result.Thumbnail);
        Assert.AreEqual(memberType.IsContainer, result.IsContainer);
        Assert.AreEqual(memberType.CreateDate, result.CreateDate);
        Assert.AreEqual(memberType.UpdateDate, result.UpdateDate);

        Assert.AreEqual(memberType.PropertyGroups.Count(), result.Groups.Count());
        for (var i = 0; i < memberType.PropertyGroups.Count(); i++)
        {
            Assert.AreEqual(memberType.PropertyGroups.ElementAt(i).Id, result.Groups.ElementAt(i).Id);
            Assert.AreEqual(memberType.PropertyGroups.ElementAt(i).Name, result.Groups.ElementAt(i).Name);
            var propTypes = memberType.PropertyGroups.ElementAt(i).PropertyTypes;

            Assert.AreEqual(propTypes.Count(), result.Groups.ElementAt(i).Properties.Count());
            for (var j = 0; j < propTypes.Count(); j++)
            {
                Assert.AreEqual(propTypes.ElementAt(j).Id, result.Groups.ElementAt(i).Properties.ElementAt(j).Id);
                Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.Groups.ElementAt(i).Properties.ElementAt(j).DataTypeId);

                Assert.AreEqual(memberType.MemberCanViewProperty(propTypes.ElementAt(j).Alias), result.Groups.ElementAt(i).Properties.ElementAt(j).MemberCanViewProperty);
                Assert.AreEqual(memberType.MemberCanEditProperty(propTypes.ElementAt(j).Alias), result.Groups.ElementAt(i).Properties.ElementAt(j).MemberCanEditProperty);
            }
        }

        Assert.AreEqual(memberType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count());
        for (var i = 0; i < memberType.AllowedContentTypes.Count(); i++)
        {
            Assert.AreEqual(memberType.AllowedContentTypes.ElementAt(i).Id.Value, result.AllowedContentTypes.ElementAt(i));
        }
    }
        public void Cannot_Persist_Member_Type_Without_Alias()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                MemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
                memberType.Alias = null;

                Assert.Throws <InvalidOperationException>(() => repository.Save(memberType));
            }
        }
Exemplo n.º 12
0
    private IMemberType CreateTestMemberType(string alias = null)
    {
        var provider = ScopeProvider;

        using (var scope = provider.CreateScope())
        {
            var repository = CreateRepository(provider);

            var memberType = MemberTypeBuilder.CreateSimpleMemberType(alias);
            MemberTypeRepository.Save(memberType);
            scope.Complete();
            return(memberType);
        }
    }
        public void Can_Get_Member_Type_By_Guid_Id()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
                repository.Save(memberType);

                memberType = repository.Get(memberType.Key);
                Assert.That(memberType, Is.Not.Null);
            }
        }
Exemplo n.º 14
0
    public void Empty_Description_Is_Always_Null_After_Saving_Member_Type()
    {
        var service    = MemberTypeService;
        var memberType = MemberTypeBuilder.CreateSimpleMemberType();

        memberType.Description = null;
        service.Save(memberType);

        var memberType2 = MemberTypeBuilder.CreateSimpleMemberType("memberType2", "Member Type 2");

        memberType2.Description = string.Empty;
        service.Save(memberType2);

        Assert.IsNull(memberType.Description);
        Assert.IsNull(memberType2.Description);
    }
        public void Bug_Changing_Built_In_Member_Type_Property_Type_Aliases_Results_In_Exception()
        {
            Dictionary <string, PropertyType> stubs = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper);

            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType("mtype");

                // created without the stub properties
                Assert.AreEqual(1, memberType.PropertyGroups.Count);
                Assert.AreEqual(3, memberType.PropertyTypes.Count());

                // saving *new* member type adds the stub properties
                repository.Save(memberType);

                // saving has added (and saved) the stub properties
                Assert.AreEqual(2, memberType.PropertyGroups.Count);
                Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count());

                foreach (KeyValuePair <string, PropertyType> stub in stubs)
                {
                    IPropertyType prop = memberType.PropertyTypes.First(x => x.Alias == stub.Key);
                    prop.Alias += "__0000";
                }

                // saving *existing* member type does *not* ensure stub properties
                repository.Save(memberType);

                // therefore, nothing has changed
                Assert.AreEqual(2, memberType.PropertyGroups.Count);
                Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count());

                // fetching ensures that the stub properties are there
                memberType = repository.Get("mtype");
                Assert.IsNotNull(memberType);

                Assert.AreEqual(2, memberType.PropertyGroups.Count);
                Assert.AreEqual(3 + (stubs.Count * 2), memberType.PropertyTypes.Count());
            }
        }
        public void Built_In_Member_Type_Properties_Are_Not_Reused_For_Different_Member_Types()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                IMemberType memberType1 = MemberTypeBuilder.CreateSimpleMemberType();
                IMemberType memberType2 = MemberTypeBuilder.CreateSimpleMemberType("test2");
                repository.Save(memberType1);
                repository.Save(memberType2);

                int[] m1Ids = memberType1.PropertyTypes.Select(x => x.Id).ToArray();
                int[] m2Ids = memberType2.PropertyTypes.Select(x => x.Id).ToArray();

                Assert.IsFalse(m1Ids.Any(m2Ids.Contains));
            }
        }
Exemplo n.º 17
0
    public void Member_Can_View_Property()
    {
        IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();

        MemberTypeService.Save(memberType);
        var prop = memberType.PropertyTypes.First().Alias;

        memberType.SetMemberCanViewProperty(prop, true);
        MemberTypeService.Save(memberType);

        // re-get
        memberType = MemberTypeService.Get(memberType.Id);
        foreach (var p in memberType.PropertyTypes.Where(x => x.Alias != prop))
        {
            Assert.IsFalse(memberType.MemberCanViewProperty(p.Alias));
        }

        Assert.IsTrue(memberType.MemberCanViewProperty(prop));
    }
        public void Deleting_PropertyType_Removes_The_Property_From_Member()
        {
            IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();

            MemberTypeService.Save(memberType);
            IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "*****@*****.**", "pass", "test");

            MemberService.Save(member);
            int initProps = member.Properties.Count;

            // remove a property (NOT ONE OF THE DEFAULTS)
            Dictionary <string, PropertyType> standardProps = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper);

            memberType.RemovePropertyType(memberType.PropertyTypes.First(x => standardProps.ContainsKey(x.Alias) == false).Alias);
            MemberTypeService.Save(memberType);

            // re-load it from the db
            member = MemberService.GetById(member.Id);

            Assert.AreEqual(initProps - 1, member.Properties.Count);
        }
Exemplo n.º 19
0
    private IMember CreateTestMember(IMemberType memberType = null, string name = null, string email = null, string password = null, string username = null, Guid?key = null)
    {
        var provider = ScopeProvider;

        using (var scope = provider.CreateScope())
        {
            var repository = CreateRepository(provider);

            if (memberType == null)
            {
                memberType = MemberTypeBuilder.CreateSimpleMemberType();
                MemberTypeRepository.Save(memberType);
            }

            var member = MemberBuilder.CreateSimpleMember(memberType, name ?? "Johnny Hefty", email ?? "*****@*****.**", password ?? "123", username ?? "hefty", key);
            repository.Save(member);
            scope.Complete();

            return(member);
        }
    }
        public void Can_Delete_MemberType()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                // Act
                IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
                repository.Save(memberType);

                IMemberType contentType2 = repository.Get(memberType.Id);
                repository.Delete(contentType2);

                bool exists = repository.Exists(memberType.Id);

                // Assert
                Assert.That(exists, Is.False);
            }
        }
    public void Can_Get_All_Member_Types()
    {
        var provider = ScopeProvider;

        using (var scope = provider.CreateScope())
        {
            var repository = CreateRepository(provider);

            var memberType1 = MemberTypeBuilder.CreateSimpleMemberType();
            repository.Save(memberType1);

            var memberType2 = MemberTypeBuilder.CreateSimpleMemberType();
            memberType2.Name  = "AnotherType";
            memberType2.Alias = "anotherType";
            repository.Save(memberType2);

            var result = repository.GetMany();

            // there are 3 because of the Member type created for init data
            Assert.AreEqual(3, result.Count());
        }
    }
        public void Can_Get_All_Member_Types_By_Guid_Ids()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                MemberType memberType1 = MemberTypeBuilder.CreateSimpleMemberType();
                repository.Save(memberType1);

                MemberType memberType2 = MemberTypeBuilder.CreateSimpleMemberType();
                memberType2.Name  = "AnotherType";
                memberType2.Alias = "anotherType";
                repository.Save(memberType2);

                IEnumerable <IMemberType> result = ((IReadRepository <Guid, IMemberType>)repository).GetMany(memberType1.Key, memberType2.Key);

                // there are 3 because of the Member type created for init data
                Assert.AreEqual(2, result.Count());
            }
        }
        public void Can_Get_Member_Types_By_Guid_Id()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                MemberType memberType1 = MemberTypeBuilder.CreateSimpleMemberType();
                repository.Save(memberType1);

                MemberType memberType2 = MemberTypeBuilder.CreateSimpleMemberType();
                memberType2.Name  = "AnotherType";
                memberType2.Alias = "anotherType";
                repository.Save(memberType2);

                IMemberType result = repository.Get(memberType1.Key);

                // there are 3 because of the Member type created for init data
                Assert.IsNotNull(result);
                Assert.AreEqual(memberType1.Key, result.Key);
            }
        }
        public void Can_Persist_Member_Type_Same_Property_Keys()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                var memberType = (IMemberType)MemberTypeBuilder.CreateSimpleMemberType();

                repository.Save(memberType);
                scope.Complete();

                Guid[] propertyKeys = memberType.PropertyTypes.Select(x => x.Key).OrderBy(x => x).ToArray();
                Guid[] groupKeys    = memberType.PropertyGroups.Select(x => x.Key).OrderBy(x => x).ToArray();

                memberType = repository.Get(memberType.Id);
                Guid[] propertyKeys2 = memberType.PropertyTypes.Select(x => x.Key).OrderBy(x => x).ToArray();
                Guid[] groupKeys2    = memberType.PropertyGroups.Select(x => x.Key).OrderBy(x => x).ToArray();

                Assert.IsTrue(propertyKeys.SequenceEqual(propertyKeys2));
                Assert.IsTrue(groupKeys.SequenceEqual(groupKeys2));
            }
        }
        public void Can_Get_All_Members_When_No_Properties_Assigned()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MemberTypeRepository repository = CreateRepository(provider);

                MemberType memberType1 = MemberTypeBuilder.CreateSimpleMemberType();
                memberType1.PropertyTypeCollection.Clear();
                repository.Save(memberType1);

                MemberType memberType2 = MemberTypeBuilder.CreateSimpleMemberType();
                memberType2.PropertyTypeCollection.Clear();
                memberType2.Name  = "AnotherType";
                memberType2.Alias = "anotherType";
                repository.Save(memberType2);

                IEnumerable <IMemberType> result = repository.GetMany();

                // there are 3 because of the Member type created for init data
                Assert.AreEqual(3, result.Count());
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Setup all standard member data for test
        /// </summary>
        private Member SetupMemberTestData(
            out MemberSave fakeMemberData,
            out MemberDisplay memberDisplay,
            ContentSaveAction contentAction)
        {
            // arrange
            MemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
            Member     member     = MemberBuilder.CreateSimpleMember(memberType, "Test Member", "*****@*****.**", "123", "test");
            var        memberId   = 123;

            member.Id = memberId;

            // TODO: replace with builder for MemberSave and MemberDisplay
            fakeMemberData = new MemberSave()
            {
                Id            = memberId,
                SortOrder     = member.SortOrder,
                ContentTypeId = memberType.Id,
                Key           = member.Key,
                Password      = new ChangingPasswordModel()
                {
                    Id          = 456,
                    NewPassword = member.RawPasswordValue,
                    OldPassword = null
                },
                Name                  = member.Name,
                Email                 = member.Email,
                Username              = member.Username,
                PersistedContent      = member,
                PropertyCollectionDto = new ContentPropertyCollectionDto()
                {
                },
                Groups = new List <string>(),
                //Alias = "fakeAlias",
                ContentTypeAlias = member.ContentTypeAlias,
                Action           = contentAction,
                Icon             = "icon-document",
                Path             = member.Path
            };

            memberDisplay = new MemberDisplay()
            {
                Id            = memberId,
                SortOrder     = member.SortOrder,
                ContentTypeId = memberType.Id,
                Key           = member.Key,
                Name          = member.Name,
                Email         = member.Email,
                Username      = member.Username,
                //Alias = "fakeAlias",
                ContentTypeAlias = member.ContentTypeAlias,
                ContentType      = new ContentTypeBasic(),
                ContentTypeName  = member.ContentType.Name,
                Icon             = fakeMemberData.Icon,
                Path             = member.Path,
                Tabs             = new List <Tab <ContentPropertyDisplay> >()
                {
                    new Tab <ContentPropertyDisplay>()
                    {
                        Alias      = "test",
                        Id         = 77,
                        Properties = new List <ContentPropertyDisplay>()
                        {
                            new ContentPropertyDisplay()
                            {
                                Alias = "_umb_id",
                                View  = "idwithguid",
                                Value = new []
                                {
                                    "123",
                                    "guid"
                                }
                            },
                            new ContentPropertyDisplay()
                            {
                                Alias = "_umb_doctype"
                            },
                            new ContentPropertyDisplay()
                            {
                                Alias = "_umb_login"
                            },
                            new ContentPropertyDisplay()
                            {
                                Alias = "_umb_email"
                            },
                            new ContentPropertyDisplay()
                            {
                                Alias = "_umb_password"
                            },
                            new ContentPropertyDisplay()
                            {
                                Alias = "_umb_membergroup"
                            }
                        }
                    }
                }
            };

            return(member);
        }
Exemplo n.º 27
0
    /// <summary>
    ///     Setup all standard member data for test
    /// </summary>
    private Member SetupMemberTestData(
        out MemberSave fakeMemberData,
        out MemberDisplay memberDisplay,
        ContentSaveAction contentAction)
    {
        // arrange
        var memberType = MemberTypeBuilder.CreateSimpleMemberType();
        var member     = MemberBuilder.CreateSimpleMember(memberType, "Test Member", "*****@*****.**", "123", "test");
        var memberId   = 123;

        member.Id = memberId;

        // TODO: replace with builder for MemberSave and MemberDisplay
        fakeMemberData = new MemberSave
        {
            Id            = memberId,
            SortOrder     = member.SortOrder,
            ContentTypeId = memberType.Id,
            Key           = member.Key,
            Password      = new ChangingPasswordModel {
                Id = 456, NewPassword = member.RawPasswordValue, OldPassword = null
            },
            Name                  = member.Name,
            Email                 = member.Email,
            Username              = member.Username,
            PersistedContent      = member,
            PropertyCollectionDto = new ContentPropertyCollectionDto(),
            Groups                = new List <string>(),

            // Alias = "fakeAlias",
            ContentTypeAlias = member.ContentTypeAlias,
            Action           = contentAction,
            Icon             = "icon-document",
            Path             = member.Path,
        };

        memberDisplay = new MemberDisplay
        {
            Id            = memberId,
            SortOrder     = member.SortOrder,
            ContentTypeId = memberType.Id,
            Key           = member.Key,
            Name          = member.Name,
            Email         = member.Email,
            Username      = member.Username,

            // Alias = "fakeAlias",
            ContentTypeAlias = member.ContentTypeAlias,
            ContentType      = new ContentTypeBasic(),
            ContentTypeName  = member.ContentType.Name,
            Icon             = fakeMemberData.Icon,
            Path             = member.Path,
            Tabs             = new List <Tab <ContentPropertyDisplay> >
            {
                new()
                {
                    Alias      = "test",
                    Id         = 77,
                    Properties = new List <ContentPropertyDisplay>
                    {
                        new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}login" },
                        new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}email" },
                        new()
                        {
                            Alias =
                                $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}password",
                        },
                        new()
                        {
                            Alias =
                                $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}membergroup",
                        },
                        new()
                        {
                            Alias =
                                $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}failedPasswordAttempts",
                        },
                        new()
                        {
                            Alias =
                                $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}approved",
                        },
                        new()
                        {
                            Alias =
                                $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lockedOut",
                        },
                        new()
                        {
                            Alias =
                                $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastLockoutDate",
                        },
                        new()
                        {
                            Alias =
                                $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastLoginDate",
                        },
                        new()
                        {
                            Alias =
                                $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastPasswordChangeDate",
                        },
                    },
                },
            },
        };

        return(member);
    }
Exemplo n.º 28
0
        private void CreateTestDataForPagingTests(out List <IContent> createdContent, out List <IMember> createdMembers, out List <IMedia> createdMedia)
        {
            // Create content
            createdContent = new List <IContent>();
            ContentType contentType = ContentTypeBuilder.CreateBasicContentType("blah");

            ContentTypeService.Save(contentType);
            for (int i = 0; i < 3; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                ContentService.Save(c1);
                createdContent.Add(c1);
            }

            // Create related content
            var relatedContent = new List <IContent>();

            for (int i = 0; i < 3; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                ContentService.Save(c1);
                relatedContent.Add(c1);
            }

            // Create media
            createdMedia = new List <IMedia>();
            MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage");

            MediaTypeService.Save(imageType);
            for (int i = 0; i < 3; i++)
            {
                Media c1 = MediaBuilder.CreateMediaImage(imageType, -1);
                MediaService.Save(c1);
                createdMedia.Add(c1);
            }

            // Create members
            MemberType memberType = MemberTypeBuilder.CreateSimpleMemberType("simple");

            MemberTypeService.Save(memberType);
            createdMembers = MemberBuilder.CreateSimpleMembers(memberType, 3).ToList();
            GetMemberService().Save(createdMembers);

            IRelationType relatedMediaRelType   = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);
            IRelationType relatedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedDocumentAlias);

            // Relate content to media
            foreach (IContent content in createdContent)
            {
                foreach (IMedia media in createdMedia)
                {
                    RelationService.Relate(content.Id, media.Id, relatedMediaRelType);
                }
            }

            // Relate content to content
            foreach (IContent relContent in relatedContent)
            {
                foreach (IContent content in createdContent)
                {
                    RelationService.Relate(relContent.Id, content.Id, relatedContentRelType);
                }
            }

            // Relate members to media
            foreach (IMember member in createdMembers)
            {
                foreach (IMedia media in createdMedia)
                {
                    RelationService.Relate(member.Id, media.Id, relatedMediaRelType);
                }
            }

            // Create copied content
            var copiedContent = new List <IContent>();

            for (int i = 0; i < 3; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                ContentService.Save(c1);
                copiedContent.Add(c1);
            }

            IRelationType copiedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias);

            // Relate content to content (mimics copy)
            foreach (IContent content in createdContent)
            {
                foreach (IContent cpContent in copiedContent)
                {
                    RelationService.Relate(content.Id, cpContent.Id, copiedContentRelType);
                }
            }

            // Create trashed content
            var trashedContent = new List <IContent>();

            for (int i = 0; i < 3; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                ContentService.Save(c1);
                trashedContent.Add(c1);
            }

            IRelationType trashedRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias);

            // Relate to trashed content
            foreach (IContent trContent in trashedContent)
            {
                foreach (IContent content in createdContent)
                {
                    RelationService.Relate(trContent.Id, content.Id, trashedRelType);
                }
            }

            // Create trashed media
            var trashedMedia = new List <IMedia>();

            for (int i = 0; i < 3; i++)
            {
                Media m1 = MediaBuilder.CreateMediaImage(imageType, -1);
                MediaService.Save(m1);
                trashedMedia.Add(m1);
            }

            IRelationType trashedMediaRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias);

            // Relate to trashed media
            foreach (IMedia trMedia in trashedMedia)
            {
                foreach (IMedia media in createdMedia)
                {
                    RelationService.Relate(trMedia.Id, media.Id, trashedMediaRelType);
                }
            }
        }
Exemplo n.º 29
0
        public void Get_Paged_Mixed_Entities_By_Ids()
        {
            // Create content
            IContentService     contentService     = GetRequiredService <IContentService>();
            IContentTypeService contentTypeService = GetRequiredService <IContentTypeService>();
            var         createdContent             = new List <IContent>();
            ContentType contentType = ContentTypeBuilder.CreateBasicContentType("blah");

            contentTypeService.Save(contentType);
            for (int i = 0; i < 10; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                contentService.Save(c1);
                createdContent.Add(c1);
            }

            // Create media
            IMediaService     mediaService     = GetRequiredService <IMediaService>();
            IMediaTypeService mediaTypeService = GetRequiredService <IMediaTypeService>();
            var       createdMedia             = new List <IMedia>();
            MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage");

            mediaTypeService.Save(imageType);
            for (int i = 0; i < 10; i++)
            {
                Media c1 = MediaBuilder.CreateMediaImage(imageType, -1);
                mediaService.Save(c1);
                createdMedia.Add(c1);
            }

            // Create members
            IMemberService     memberService     = GetRequiredService <IMemberService>();
            IMemberTypeService memberTypeService = GetRequiredService <IMemberTypeService>();
            MemberType         memberType        = MemberTypeBuilder.CreateSimpleMemberType("simple");

            memberTypeService.Save(memberType);
            var createdMembers = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10).ToList();

            memberService.Save(createdMembers);

            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                EntityRepository repo = CreateRepository((IScopeAccessor)provider);

                IEnumerable <int> ids = createdContent.Select(x => x.Id).Concat(createdMedia.Select(x => x.Id)).Concat(createdMembers.Select(x => x.Id));

                System.Guid[] objectTypes = new[] { Constants.ObjectTypes.Document, Constants.ObjectTypes.Media, Constants.ObjectTypes.Member };

                IQuery <IUmbracoEntity> query = provider.CreateQuery <IUmbracoEntity>()
                                                .WhereIn(e => e.Id, ids);

                var entities = repo.GetPagedResultsByQuery(query, objectTypes, 0, 20, out long totalRecords, null, null).ToList();

                Assert.AreEqual(20, entities.Count);
                Assert.AreEqual(30, totalRecords);

                // add the next page
                entities.AddRange(repo.GetPagedResultsByQuery(query, objectTypes, 1, 20, out totalRecords, null, null));

                Assert.AreEqual(30, entities.Count);
                Assert.AreEqual(30, totalRecords);

                var contentEntities = entities.OfType <IDocumentEntitySlim>().ToList();
                var mediaEntities   = entities.OfType <IMediaEntitySlim>().ToList();
                var memberEntities  = entities.OfType <IMemberEntitySlim>().ToList();

                Assert.AreEqual(10, contentEntities.Count);
                Assert.AreEqual(10, mediaEntities.Count);
                Assert.AreEqual(10, memberEntities.Count);
            }
        }