public PostsController(PostsDbContext dbContext, IConfiguration configuration, ImageLoaderService service)
 {
     this._dbContext  = dbContext;
     _configuration   = configuration;
     _facebookService = new FacebookService(new FacebookClient());
     _imgLoader       = service;
 }
        public async void DeletePost()
        {
            DbContextOptions <PostsDbContext> options = new DbContextOptionsBuilder <PostsDbContext>().UseInMemoryDatabase("ChangePosts").Options;

            using (PostsDbContext context = new PostsDbContext(options))
            {
                PostsManager postService = new PostsManager(context);
                Posts        post        = new Posts();
                post.Author   = "Cat";
                post.ImageURL = "test.img";
                post.Title    = "Seattle";
                await postService.SaveAsync(post);

                Posts post2 = new Posts();
                post.Author   = "Cat";
                post.ImageURL = "test.img";
                post.Title    = "Tacoma";
                await postService.SaveAsync(post);


                await postService.Delete(post2.ID);

                var result = await context.Post.FirstOrDefaultAsync(p => p.ID == post2.ID);

                Assert.Null(result);
            }
        }
        public async void GetAllPosts()
        {
            DbContextOptions <PostsDbContext> options = new DbContextOptionsBuilder <PostsDbContext>().UseInMemoryDatabase("GetAllPosts").Options;

            using (PostsDbContext context = new PostsDbContext(options))
            {
                PostsManager postService = new PostsManager(context);
                Posts        post        = new Posts();
                post.Author   = "Cat";
                post.ImageURL = "test.img";
                post.Title    = "Seattle";
                await postService.SaveAsync(post);

                Posts postTwo = new Posts();
                post.Author   = "Cats";
                post.ImageURL = "test.img";
                post.Title    = "Seattle2";
                await postService.SaveAsync(postTwo);

                Posts postThree = new Posts();
                post.Author   = "Cat3";
                post.ImageURL = "test.img";
                post.Title    = "Seattle3";
                await postService.SaveAsync(postThree);

                var result = await postService.GetPosts();

                int count = result.Count;

                Assert.Equal(3, count);
            }
        }
Exemple #4
0
 public List <Post> GetAllPosts()
 {
     _logger.Trace("PostsHandler GetPostsAllPosts was called");
     using (PostsDbContext db = new PostsDbContext())
     {
         return(db.Posts.ToList());
     }
 }
Exemple #5
0
        public List <Post> GetPostsOfCategoryId(int id)
        {
            _logger.Trace("PostsHandler GetPostsOfCategoryId was called with next params: id:" + id);
            List <Post> posts;

            using (PostsDbContext db = new PostsDbContext())
            {
                posts = db.Posts.Where(post => post.Category.Id == id).ToList();
            }
            return(posts);
        }
Exemple #6
0
        private static PostsDbContext CreateDbContextWithData()
        {
            var dbContext = new PostsDbContext(Options);

            dbContext.Insert(new Post {
                Id = Guid.NewGuid(), Author = "XXX", Title = "YYY", Content = "ZZZ"
            });
            dbContext.Insert(new Post {
                Id = Guid.NewGuid(), Author = "XXX", Title = "YYY", Content = "ZZZ"
            });
            return(dbContext);
        }
        public async void CreateEmptyPost()
        {
            DbContextOptions <PostsDbContext> options = new DbContextOptionsBuilder <PostsDbContext>().UseInMemoryDatabase("CreateEmptyPost").Options;

            using (PostsDbContext context = new PostsDbContext(options))
            {
                Posts post = new Posts();

                PostsManager postService = new PostsManager(context);
                await postService.SaveAsync(post);

                Posts result = await context.Post.FirstOrDefaultAsync(h => h.ID == post.ID);

                Assert.Null(result.Author);
            }
        }
        public async void ReadSinglePost()
        {
            DbContextOptions <PostsDbContext> options = new DbContextOptionsBuilder <PostsDbContext>().UseInMemoryDatabase("ReadPost").Options;

            using (PostsDbContext context = new PostsDbContext(options))
            {
                PostsManager postService = new PostsManager(context);
                Posts        post        = new Posts();
                post.Author   = "Cat";
                post.ImageURL = "test.img";
                post.Title    = "Seattle";
                await postService.SaveAsync(post);

                Posts result = await postService.GetSinglePost(post.ID);

                Assert.Equal(post, result);
            }
        }
Exemple #9
0
        public ActionResult Index()
        {
            var db = new PostsDbContext();

            //  var posts = db.Posts
            //      .OrderByDescending(p => p.Id)
            //      .Take(3)
            //      .Select(p => new HomeIndexPostModel
            //      {
            //          Id = p.Id,
            //          Title = p.Title,
            //          ImageUrl = p.ImageUrl
            //      })
            //      .ToList();

            return(View(
                       //posts
                       ));
        }
Exemple #10
0
        public ActionResult Create(CreatePostModel postModel)
        {
            if (postModel != null && this.ModelState.IsValid)
            {
                var ownerId = this.User.Identity.GetUserId();

                var post = new Post
                {
                    Title       = postModel.Title,
                    Description = postModel.Description,
                    ImageUrl    = postModel.ImageUrl,
                    OwnerId     = ownerId
                };

                var db = new PostsDbContext();
                db.Posts.Add(post);
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = post.Id }));
            }

            return(View(postModel));
        }
Exemple #11
0
 public CommentService(PostsDbContext dbContext)
     : base(dbContext)
 {
 }
 public CommentManager(PostsDbContext context)
 {
     _context = context;
 }
Exemple #13
0
 public PostsController(PostsDbContext dbContext, IPostRepository repo)
 {
     _repo = repo;
 }
 public PostsManager(PostsDbContext context)
 {
     _context = context;
 }
Exemple #15
0
 public PostsService(PostsDbContext db, IMapper mapper)
     : base(db)
 {
     this.mapper = mapper;
 }
Exemple #16
0
 public PostService(PostsDbContext dbContext,
                    IEventBus eventBus)
 {
     _dbContext = dbContext;
     _eventBus  = eventBus;
 }
Exemple #17
0
 public HomeController()
 {
     db = new PostsDbContext();
     AutentificationDbContext = new ApplicationDbContext();
     this.UserManager         = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(AutentificationDbContext));
 }
 protected DataService(PostsDbContext db)
 {
     this.Data = db;
 }
Exemple #19
0
 public PostsController(PostsDbContext dbContext, TokensStorage tokensStorage)
 {
     this.dbContext     = dbContext;
     this.tokensStorage = tokensStorage;
 }
 public PostService(PostsDbContext context, IMapper mapper, IData <BlogPostsTags> serviceBlogPostsTags,
                    IData <Tags> serviceTags) : base(context, mapper)
 {
     _serviceBlogPostsTags = serviceBlogPostsTags;
     _serviceTags          = serviceTags;
 }
Exemple #21
0
 public Data(PostsDbContext context, IMapper mapper)
 {
     _context = context;
     _entity  = context.Set <T>();
     _mapper  = mapper;
 }