コード例 #1
0
ファイル: QueryUserInformation.cs プロジェクト: nevergofull/A
        protected override async Task <UserInformation> GetData()
        {
            using (var db = new Repository())
            {
                var data = await db.GetUserInformation(_userToRetrieve);

                if (data != null)
                {
                    if (data.Badges != null)
                    {
                        data.Badges.ToList().ForEach(x => x.Graphic = VoatPathHelper.BadgePath(x.Graphic, true, true));
                    }
                    var moderates = db.GetSubversesUserModerates(_userToRetrieve);
                    if (moderates != null)
                    {
                        data.Moderates = moderates.Select(x => new SubverseModerator()
                        {
                            Subverse = x.Subverse, Level = (ModeratorLevel)Enum.Parse(typeof(ModeratorLevel), x.Power.ToString())
                        }).ToList();
                    }
                }

                //TODO: Need to ensure this condition doesn't happen often, throwing exception to test.
                else
                {
                    throw new VoatNotFoundException(String.Format("Can not find UserInformation for {0}", _userToRetrieve));
                }

                return(data);
            }
        }
コード例 #2
0
ファイル: VoatPathHelperTests.cs プロジェクト: nevergofull/A
        public void ThumbnailPath()
        {
            string filename = Guid.NewGuid().ToString() + ".jpg";
            string result   = "";

            result = VoatPathHelper.ThumbnailPath(filename);
            if (Settings.UseContentDeliveryNetwork)
            {
                Assert.AreEqual(String.Format("~/thumbs/{0}", filename), result, "Condition:1");
            }
            else
            {
                Assert.AreEqual(String.Format("~/thumbs/{0}", filename), result, "Condition:1");
            }

            result = VoatPathHelper.ThumbnailPath(filename, true);
            if (Settings.UseContentDeliveryNetwork)
            {
                Assert.AreEqual(String.Format("//cdn.voat.co/thumbs/{0}", filename), result, "Condition:2");
            }
            else
            {
                Assert.AreEqual(String.Format("//voat.co/thumbs/{0}", filename), result, "Condition:2");
            }

            result = VoatPathHelper.ThumbnailPath(filename, true, true);
            if (Settings.UseContentDeliveryNetwork)
            {
                Assert.AreEqual(String.Format("https://cdn.voat.co/thumbs/{0}", filename), result, "Condition:3");
            }
            else
            {
                Assert.AreEqual(String.Format("https://voat.co/thumbs/{0}", filename), result, "Condition:3");
            }
        }
コード例 #3
0
        public static Domain.Models.Submission Map(this Data.Models.Submission submission)
        {
            Domain.Models.Submission result = null;
            if (submission != null)
            {
                result = new Domain.Models.Submission()
                {
                    ID       = submission.ID,
                    UserName = (submission.IsAnonymized ? submission.ID.ToString() : submission.UserName),

                    Title   = submission.Title,
                    Url     = submission.Url,
                    Content = (submission.Type == 1 ? submission.Content : (string)null),

                    //Support For Backwards compat, if FormattedContent is empty, do it here.
                    FormattedContent = (submission.Type == 1 && String.IsNullOrEmpty(submission.FormattedContent) ? Formatting.FormatMessage(submission.Content, true) : submission.FormattedContent),

                    LastEditDate = submission.LastEditDate,
                    ThumbnailUrl = VoatPathHelper.ThumbnailPath(submission.Thumbnail, true, true),
                    CommentCount = CommentCounter.CommentCount(submission.ID),
                    CreationDate = submission.CreationDate,
                    UpCount      = (int)submission.UpCount,
                    Views        = (int)submission.Views,
                    DownCount    = (int)submission.DownCount,
                    Type         = submission.Type == 1 ? SubmissionType.Text : SubmissionType.Link,
                    Subverse     = submission.Subverse,
                    IsAnonymized = submission.IsAnonymized,
                    IsDeleted    = submission.IsDeleted,
                    Rank         = submission.Rank,
                    RelativeRank = submission.RelativeRank
                };
            }
            return(result);
        }
コード例 #4
0
ファイル: VoatPathHelperTests.cs プロジェクト: nevergofull/A
        public void BadgePath()
        {
            //Badges don't use the CDN right now, only the UI
            string filename = "developer.jpg";
            string result   = "";
            string domain   = ConfigurationManager.AppSettings["ui.domain"];

            domain = (String.IsNullOrEmpty(domain) ? "voat.co" : domain);

            result = VoatPathHelper.BadgePath(filename, false);
            Assert.AreEqual(String.Format("~/Graphics/Badges/{0}", filename), result, "Condition:1");

            result = VoatPathHelper.BadgePath(filename, true, true);
            Assert.AreEqual(String.Format("https://{1}/Graphics/Badges/{0}", filename, domain), result, "Condition:2");

            result = VoatPathHelper.BadgePath(filename, true, true);
            Assert.AreEqual(String.Format("https://{1}/Graphics/Badges/{0}", filename, domain), result, "Condition:3");

            //Assert.Inconclusive();
        }
コード例 #5
0
ファイル: VoatPathHelperTests.cs プロジェクト: nevergofull/A
        public void AvatarPath()
        {
            string username       = "******";
            string avatarFileName = "username.jpg";
            string result         = "";

            result = VoatPathHelper.AvatarPath(username, avatarFileName, false, true, true);

            if (Settings.UseContentDeliveryNetwork)
            {
                Assert.AreEqual(String.Format("~/avatars/{0}.jpg", username), result, "Condition:1");
            }
            else
            {
                Assert.AreEqual(String.Format("~/Storage/Avatars/{0}.jpg", username), result, "Condition:1.2");
            }

            result = VoatPathHelper.AvatarPath(username, avatarFileName, true, false, true);
            if (Settings.UseContentDeliveryNetwork)
            {
                Assert.AreEqual(String.Format("//cdn.voat.co/avatars/{0}.jpg", username), result, "Condition:2");
            }
            else
            {
                Assert.AreEqual(String.Format("//voat.co/Storage/Avatars/{0}.jpg", username), result, "Condition:2.2");
            }

            result = VoatPathHelper.AvatarPath(username, avatarFileName, true, true, true);
            if (Settings.UseContentDeliveryNetwork)
            {
                Assert.AreEqual(String.Format("https://cdn.voat.co/avatars/{0}.jpg", username), result, "Condition:3");
            }
            else
            {
                Assert.AreEqual(String.Format("https://voat.co/Storage/Avatars/{0}.jpg", username), result, "Condition:3.2");
            }

            //Assert.Inconclusive();
        }