public PostBodyViewModel(PostBodyEntity src)
 {
     instance           = new PostBodyViewModel();
     instance.Title     = src.Title;
     instance.Publisher = src.Publisher;
     instance.Time      = src.Time;
     instance.Views     = src.Views;
     if (src.Attachment != null)
     {
         instance.Attachment = new ObservableCollection <Attachments>(src.Attachment);
     }
     instance.Bodys = src.Bodys;
 }
        internal static Post Convert(this PostBodyEntity ent, PostHeaderEntity ent2)
        {
            if (ent == null || ent2 == null)
            {
                return(null);
            }

            return(new Post
            {
                Header = ent2.Convert(),
                Body = ent.Markdown
            });
        }
Exemple #3
0
        public static void Init(TestContext tctx)
        {
            _opts = new DbContextOptionsBuilder()
                    .UseNpgsql($"Server={TestConstants.Server};Port=5432;Database={TestConstants.GuidString};User Id=user1;Password=password1;")
                    .Options;

            _testTag   = TestConstants.GuidString;
            _testTitle = TestConstants.GuidString;
            _testBody  = TestConstants.GuidString;

            using (var ctx = new BlogContext(_opts))
            {
                ctx.Database.EnsureCreated();

                var tag1 = new TagEntity {
                    Text = _testTag
                };

                //Add a tag
                ctx.Tags.Add(tag1);
                ctx.SaveChanges();

                var body = new PostBodyEntity {
                    Markdown = _testBody
                };

                //add body
                ctx.Bodies.Add(body);
                ctx.SaveChanges();

                var header = new PostHeaderEntity
                {
                    BodyId = body.Id,
                    Title  = _testTitle
                };

                //add header
                ctx.Headers.Add(header);
                ctx.SaveChanges();

                var join = new PostTagEntity
                {
                    TagId  = tag1.Id,
                    PostId = header.Id
                };

                ctx.PostTags.Add(join);
                ctx.SaveChanges();
            }
        }
        public async Task GetPostTest()
        {
            //Arrange
            var bodyId   = -1;
            var bodyText = TestConstants.GuidString;

            using (var ctx = new BlogContext(_opts))
            {
                var tags = new []
                {
                    new PostTagEntity {
                        Tag = new TagEntity {
                            Text = TestConstants.GuidString
                        }
                    },
                    new PostTagEntity {
                        Tag = new TagEntity {
                            Text = TestConstants.GuidString
                        }
                    }
                };
                var body = new PostBodyEntity {
                    Markdown = bodyText
                };
                var header = new PostHeaderEntity {
                    Title = TestConstants.GuidString, Body = body
                };
                foreach (var pt in tags)
                {
                    pt.Post = header;
                }

                await ctx.Headers.AddAsync(header);

                await ctx.SaveChangesAsync();

                bodyId = body.Id;
            }

            var accessor = new BlogAccessor(_opts);

            //Act
            var result = await accessor.GetPostById(bodyId);

            //Assert
            Assert.IsTrue(bodyId > 0, "Should be at least 1");
            Assert.IsNotNull(result, "Should never be null");
            Assert.IsInstanceOfType(result, typeof(Post));
            Assert.AreEqual(bodyText, result.Body, "Should contain the test body text");
        }
Exemple #5
0
        private PostBodyEntity GetPostBody(int number, int boardid)
        {
            winhttp.Open("GET", "https://www.koreatech.ac.kr/kor/CMS/NoticeMgr/view.do?post_seq=" + number + "&board_id=" + boardid);
            winhttp.Send();
            winhttp.WaitForResponse();
            PostBodyEntity post = new PostBodyEntity();

            string temp      = Strings.Split(Strings.Split(winhttp.ResponseText, "<div id=\"board-wrap\">")[1], "<div  class=\"board-view-more\">")[0];
            string title     = Strings.Split(Strings.Split(temp, "<span style=\"\" title=\"")[1], "\">")[0];
            string publisher = Strings.Split(Strings.Split(temp, "<span class=\"txt name\">")[1], "</span>")[0];
            string time      = Strings.Split(Strings.Split(temp, "<span class=\"txt\">")[1], "</span>")[0];
            int    views     = Convert.ToInt32(Strings.Split(Strings.Split(temp, "<em>조회수 : </em>")[1], "</span>")[0]);

            List <Attachments> list = new List <Attachments>();

            if (Strings.InStr(temp, "<span class=\"ilbl\">첨부파일</span>") > 0)
            {
                for (int i = 0; i < Strings.Split(temp, "<a href=\"").Length - 1; i++)
                {
                    string save_str = Strings.Split(temp, "<a href=\"")[i + 1];
                    list.Add(new Attachments()
                    {
                        Title = Strings.Split(Strings.Split(save_str, "\">")[1], "</a>")[0],
                        Url   = Strings.Split(save_str, "\">")[0]
                    });
                }
            }
            else
            {
                list = null;
            }
            string body = Strings.Split(Strings.Split(temp, "<div id=\"boardContents\">")[1], "</div>")[0];

            post.Title      = title;
            post.Publisher  = publisher;
            post.Time       = time;
            post.Views      = views;
            post.Attachment = list;
            post.Bodys      = "<html><body>" + body + "</body></html>";
            //post.Bodys = "<img src=\"http://24.media.tumblr.com/7995829378e93457f5dd3c10445ec00e/tumblr_mekn6vBZkI1rf089no1_500.gif\" height=\"100\"/>";
            return(post);
        }