Exemplo n.º 1
0
        public JsonResult Create(BlogPostsV2 blogpost)
        {
            //int number = 0;
            //if (ModelState.IsValid)
            //{
            //    switch (blogPostsV2.Status)
            //    {
            //        case BlogPostStatus.Live:
            //            number = 1;
            //            break;

            //        case BlogPostStatus.Archived:
            //            number = 2;
            //            break;

            //        case BlogPostStatus.Scheduled:
            //            number = 3;
            //            break;

            //        case BlogPostStatus.Draft:
            //            number = 4;
            //            break;
            //    }
            var result = bService.AddBlog(blogpost, out int blogId);

            return(Json(new
            {
                isSuccess = result,
                blogId
            }));
            //return RedirectToAction("Index");
            //}
            //return View();
        }
        public void CreateBlog_saves_a_blog_via_context()
        {
            var context = new TestContext();

            var service = new BlogService(context);
            service.AddBlog("ADO.NET Blog", "http://blogs.msdn.com/adonet");

            Assert.AreEqual(1, context.Blogs.Count());
            Assert.AreEqual("ADO.NET Blog", context.Blogs.Single().Name);
            Assert.AreEqual("http://blogs.msdn.com/adonet", context.Blogs.Single().Url);
            Assert.AreEqual(1, context.SaveChangesCount);
        }
Exemplo n.º 3
0
        public void CreateBlog_saves_a_blog_via_context()
        {
            var mockSet     = new Mock <DbSet <Blog> >();
            var mockContext = new Mock <BloggingEntities>();

            mockContext.Setup(m => m.Blog).Returns(mockSet.Object);

            var service = new BlogService(mockContext.Object);

            service.AddBlog("http://blogs.msdn.com/adonet");
            mockSet.Verify(m => m.Add(It.IsAny <Blog>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
        public void Test_EntityContext_SavesAddress()
        {
            var mockSet = new Mock<DbSet<Blog>>();

            var mockContext = new Mock<BloggingContext>();
            mockContext.Setup(m => m.Blogs).Returns(mockSet.Object);

            var service = new BlogService(mockContext.Object);
            service.AddBlog("ADO.NET Blog", "http://blogs.msdn.com/adonet");

            mockSet.Verify(m => m.Add(It.IsAny<Blog>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Exemplo n.º 5
0
        public void CreateBlog_saves_a_blog_via_context()
        {
            var context = new TestContext();

            var service = new BlogService(context);

            service.AddBlog("ADO.NET Blog", "http://blogs.msdn.com/adonet");

            Assert.AreEqual(1, context.Blogs.Count());
            Assert.AreEqual("ADO.NET Blog", context.Blogs.Single().Name);
            Assert.AreEqual("http://blogs.msdn.com/adonet", context.Blogs.Single().Url);
            Assert.AreEqual(1, context.SaveChangesCount);
        }
Exemplo n.º 6
0
        public void TestMethod1()
        {
            var mockSet = new Mock <DbSet <Blog> >();

            var mockContext = new Mock <BloggingContext>();

            mockContext.Setup(m => m.Blogs).Returns(mockSet.Object);

            var service = new BlogService(mockContext.Object);

            service.AddBlog("ADO.NET Blog", "http://blogs.msdn.com/adonet");

            mockSet.Verify(m => m.Add(It.IsAny <Blog>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Exemplo n.º 7
0
    protected void ButtonPostBlog_Click(object sender, EventArgs e)
    {
        IITCourse.Blog.Blog blog = new Blog();
        TextBox             Mood = ((TextBox)LoginViewPostBlog.FindControl("TextBoxMood"));

        TextBox Description = ((TextBox)LoginViewPostBlog.FindControl("TextBoxDescription"));

        blog.Mood        = Mood.Text;
        blog.Description = Description.Text;
        BlogService.AddBlog(blog);
        _blogs.Clear();
        _blogs = BlogService.GetBlogs();
        ListViewBlogs.DataSource = _blogs;
        ListViewBlogs.DataBind();
        Mood.Text        = string.Empty;
        Description.Text = string.Empty;
    }
Exemplo n.º 8
0
        public IActionResult AddBlog()
        {
            var newBlog =
                blogService.AddBlog("New Blog", int.Parse(blogService.CurrentUser.Id));

            var sections = blogService.SectionsOfBlog(newBlog.Id);
            var owner    = userInfoService.GetUserWithIdSafe(newBlog.UserId);

            return(EditBlog(
                       new DetailedBlogVm()
            {
                BlogId = newBlog.Id,
                Title = newBlog.Title,
                SectionsIds = sections,
                OwnerUsername = owner.Username,
                OwnerEmail = owner.Email,
                OwnerId = owner.Id
            }));
        }
Exemplo n.º 9
0
        public IActionResult AddBlog(Blog blog)
        {
            ViewBag.Me = userService.GetPersonBasedOnId(User.Identity.GetPersonId());
            if (User.Identity.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    blog.DatePosted = DateTime.Now;
                    blog.PosterId   = User.Identity.GetPersonId();
                    blogService.AddBlog(blog);
                    return(RedirectToAction(nameof(Index)));
                }

                return(View(blog));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Blog(AddBlog blog)
        {
            var result = await _BlogService.AddBlog(blog);

            return(Json(result));
        }