Ejemplo n.º 1
0
        public void TestRestrictionGrouping()
        {
            var r = new Voat.Data.Models.VoteRestriction()
            {
                ID = 1,
                //GroupName = "Default",
                Type = typeof(ContributionCountRestriction).Name,
                Data = (new ContributionCountRestriction()
                {
                    ContentType = (ContentTypeRestriction)(Domain.Models.ContentType.Comment | Domain.Models.ContentType.Submission),
                    Duration = TimeSpan.FromDays(180),
                    Subverse = "unit",
                    MinimumCount = 1,
                    EndDate = DateTime.UtcNow
                }).Serialize(),
                VoteID = 1
            };

            var constructed = (IVoteRestriction)VoteItem.Deserialize <VoteItem>(r.Data);
            var user        = TestHelper.SetPrincipal(USERNAMES.User500CCP);
            var outcome     = constructed.Evaluate(user);

            VoatAssert.IsValid(outcome);


            var restrictionSet = new VoteRestrictionSet();

            restrictionSet.Populate(new Voat.Data.Models.VoteRestriction[] { r });

            var eval = restrictionSet.Evaluate(user);

            Assert.IsTrue(eval.IsValid);
        }
Ejemplo n.º 2
0
        public static Domain.Models.Vote Map(this Data.Models.Vote entity)
        {
            Domain.Models.Vote vote = null;
            if (entity != null)
            {
                vote = new Domain.Models.Vote();

                vote.ID                = entity.ID;
                vote.Title             = entity.Title;
                vote.Content           = entity.Content;
                vote.FormattedContent  = entity.FormattedContent;
                vote.Subverse          = entity.Subverse;
                vote.SubmissionID      = entity.SubmissionID;
                vote.StartDate         = entity.StartDate;
                vote.DisplayStatistics = entity.DisplayStatistics;
                vote.EndDate           = entity.EndDate;
                vote.CreationDate      = entity.CreationDate;
                vote.CreatedBy         = entity.CreatedBy;

                entity.VoteOptions?.ForEach(x =>
                {
                    var newOption = new Domain.Models.VoteOption();

                    newOption.ID               = x.ID;
                    newOption.Title            = x.Title;
                    newOption.Content          = x.Content;
                    newOption.FormattedContent = x.FormattedContent;
                    newOption.SortOrder        = x.SortOrder;

                    x.VoteOutcomes?.ForEach(o =>
                    {
                        var obj = VoteItem.Deserialize <VoteOutcome>(o.Data);
                        obj.ID  = o.ID;
                        newOption.Outcomes.Add(obj);
                    });

                    vote.Options.Add(newOption);
                });

                entity.VoteRestrictions?.ForEach(x =>
                {
                    var obj = VoteItem.Deserialize <VoteRestriction>(x.Data);
                    obj.ID  = x.ID;
                    vote.Restrictions.Add(obj);
                });
            }
            return(vote);
        }
Ejemplo n.º 3
0
        public void Populate(IEnumerable <Data.Models.VoteRestriction> restrictions)
        {
            //throw new NotImplementedException();
            foreach (var restriction in restrictions)
            {
                var item = VoteItem.Deserialize <VoteRestriction>(restriction.Data);

                var groupName = String.IsNullOrEmpty(item.Group.TrimSafe()) ? "" : item.Group.TrimSafe();

                List <IVoteRestriction> groupList = null;
                if (_restrictionSet.ContainsKey(groupName))
                {
                    groupList = _restrictionSet[groupName];
                }
                else
                {
                    groupList = new List <IVoteRestriction>();
                    _restrictionSet[groupName] = groupList;
                }
                groupList.Add(item);
            }
        }