public BlogTest(ITestOutputHelper outputHelper)
        {
            //for consistency:
            //gcloud beta emulators firestore start --host-port=localhost:8888 --
            Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", "localhost:8888");
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "/raid/repos/epsweb-firestore/EPSWeb.Common.Firestore/epsweb-217515-5631b4260996.json");
            //Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS","/your/credential/key.json");
            output = outputHelper;
            log    = output.BuildLoggerFor <BlogRepo>();

            blog = new BlogRepo(new FirestoreConfig
            {
                Root         = "blogtest",
                Emulator     = true,
                EmulatorUrl  = "http://localhost:8888",
                EmulatorPort = 8888,
                ProjectId    = "epsweb-217515"
            }, log);

            posts = new List <BlogPost>();

            for (int i = 0; i < 20; i++)
            {
                posts.Add(new BlogPost
                {
                    body     = Lorem.Paragraphs(500, 250, 3).ToCombinedString(),
                    overview = Lorem.Sentence(10),
                    tags     = Lorem.Words(5).Split(',').ToCombinedString(),
                    title    = $"blog post {i}",
                    slug     = $"blog-post-{i}"
                });
            }
        }
        public ViewResult Edit(Blog b, int blogid)
        {
            string      name    = HttpContext.Session.GetString("Name");
            int         id      = PublicUserRepo.GetId(name);
            List <Blog> myBlogs = BlogRepo.getMyBlogs(id);

            if (ModelState.IsValid)
            {
                foreach (Blog bl in myBlogs)
                {
                    if (bl.blog_Id == b.blog_Id)
                    {
                        bl.Title   = b.Title;
                        bl.Content = b.Content;
                        bl.Date    = b.Date;
                        BlogRepo.RemoveBlog(bl.blog_Id);
                        BlogRepo.AddBlog(b, id); //Sath hi database ma b update kr dia h
                        break;
                    }
                }

                return(View("ViewMyBlogs", myBlogs));
            }
            else
            {
                ModelState.AddModelError(String.Empty, "Please enter correct data");
                return(View());
            }
        }
Пример #3
0
        public void testBlogRepo()
        {
            var data = new List <Blog>
            {
                new Blog {
                    Name = "ABBB"
                },
                new Blog {
                    Name = "ZZZ"
                },
                new Blog {
                    Name = "AAA"
                },
            }.AsQueryable();
            var post = new List <MVC.Models.Post>
            {
                new Post {
                }
            }.AsQueryable();

            MockBlogs.As <IQueryable <Blog> >().Setup(e => e.Provider).Returns(data.Provider);
            MockBlogs.As <IQueryable <Blog> >().Setup(e => e.Expression).Returns(data.Expression);
            MockBlogs.As <IQueryable <Blog> >().Setup(e => e.ElementType).Returns(data.ElementType);
            MockBlogs.As <IQueryable <Blog> >().Setup(e => e.GetEnumerator()).Returns(data.GetEnumerator());
            mockContext.Setup(e => e.Blogs).Returns(MockBlogs.Object);
            BlogRepo blog = new BlogRepo(mockContext.Object);

            Assert.AreEqual(blog.GetBlogsByName(e => e.Name.StartsWith("A")).Count, 2);
        }
Пример #4
0
        public ActionResult Index()
        {
            var bRepo = new BlogRepo();
            var list  = bRepo.GetAllBlogPosts();

            return(View(list));
        }
        public ViewResult ViewMyBlogs()
        {
            string      name  = HttpContext.Session.GetString("Name");
            int         id    = PublicUserRepo.GetId(name);
            List <Blog> blogs = BlogRepo.getMyBlogs(id);

            return(View(blogs));
        }
        public ViewResult Remove(int id)
        {
            BlogRepo.RemoveBlog(id);
            PublicUserRepo.RemoveById(id);
            List <PublicUser> users = PublicUserRepo.GetAllUsers();

            return(View("AdminDash", users));
        }
Пример #7
0
        static void Main(string[] args)
        {
            var repo = new BlogRepo(new BloggingContext());

            repo.Add(new Blog {
                Name = "Foo"
            }, false);
            Console.WriteLine("Hello World!");
        }
        public ViewResult Remove(int id)
        {
            BlogRepo.RemoveBlog(id);
            string      name  = HttpContext.Session.GetString("Name");
            int         myid  = PublicUserRepo.GetId(name);
            List <Blog> blogs = BlogRepo.getMyBlogs(myid);

            return(View("ViewMyBlogs", blogs));
        }
Пример #9
0
        public IActionResult Index([FromRoute] string postTitle)
        {
            BlogRepo blogRepo = new BlogRepo();

            return(View(
                       blogRepo.Posts.Find(
                           p => p.Title == postTitle.Replace("-", " ")
                           ).FirstOrDefault()
                       ));
        }
Пример #10
0
        public IActionResult Index()
        {
            BlogRepo blogRepo = new BlogRepo();

            blogRepo.CreateExamplePosts();
            return(View(blogRepo.Posts.Find(
                            p => p.Public == true &&
                            p.Created <= DateTime.Now &&
                            p.Deleted == false)
                        ));
        }
Пример #11
0
        public void CreateBlog_saves_a_blog_via_context()
        {
            var mockSet = new Mock <DbSet <Blog> >();

            var mockContext = new Mock <BloggingContext>();

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

            var service = new BlogRepo(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());
        }
 public ViewResult CreateBlog(string nam, Blog b)
 {
     b.Date = DateTime.Today.ToString();
     if (ModelState.IsValid)
     {
         string name = HttpContext.Session.GetString("Name");
         int    id   = PublicUserRepo.GetId(name);
         BlogRepo.AddBlog(b, id);
         PublicUser usr = PublicUserRepo.getUserbyId(id);
         return(View("HomePage", usr));
     }
     else
     {
         ModelState.AddModelError(String.Empty, "Please enter correct data");
         return(View());
     }
 }
Пример #13
0
 public AdminController()
 {
     blogData = new BlogRepo(new BlogDbContext());
 }
        public ViewResult Edit(int id)
        {
            Blog b = BlogRepo.getBlogById(id);

            return(View("Edit", b));
        }
 // The Controller constructor will be auto called everytime we
 // navigate to one of the routes/methods in the controller
 public AdminController()
 {
     BlogRepo = new BlogRepo();
 }
Пример #16
0
 public BlogController() //ctor Tab Tab (this will create the default constructor)
 {
     blogrepo = new BlogRepo();
 }
 public BlogBusinessRules(BlogRepo blogRepo, PostBusinessRules postBll)
 {
     _blogRepo = blogRepo;
     _postBll  = postBll;
 }
Пример #18
0
 public BlogManager()
 {
     _blogRepo = new BlogRepo();
 }
Пример #19
0
 public HomeController()
 {
     blogData = new BlogRepo(new BlogDbContext());
 }
Пример #20
0
 public BlogPostsController()
 {
     _usersRepo = new UsersRepo();
     _blogRepo  = new BlogRepo();
 }