Exemplo n.º 1
0
 public PostsController(PostsDbContext dbContext, IConfiguration configuration, ImageLoaderService service)
 {
     this._dbContext  = dbContext;
     _configuration   = configuration;
     _facebookService = new FacebookService(new FacebookClient());
     _imgLoader       = service;
 }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 public List <Post> GetAllPosts()
 {
     _logger.Trace("PostsHandler GetPostsAllPosts was called");
     using (PostsDbContext db = new PostsDbContext())
     {
         return(db.Posts.ToList());
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 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
                       ));
        }
Exemplo n.º 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));
        }
Exemplo n.º 11
0
 public CommentService(PostsDbContext dbContext)
     : base(dbContext)
 {
 }
Exemplo n.º 12
0
 public CommentManager(PostsDbContext context)
 {
     _context = context;
 }
Exemplo n.º 13
0
 public PostsController(PostsDbContext dbContext, IPostRepository repo)
 {
     _repo = repo;
 }
Exemplo n.º 14
0
 public PostsManager(PostsDbContext context)
 {
     _context = context;
 }
Exemplo n.º 15
0
 public PostsService(PostsDbContext db, IMapper mapper)
     : base(db)
 {
     this.mapper = mapper;
 }
Exemplo n.º 16
0
 public PostService(PostsDbContext dbContext,
                    IEventBus eventBus)
 {
     _dbContext = dbContext;
     _eventBus  = eventBus;
 }
Exemplo n.º 17
0
 public HomeController()
 {
     db = new PostsDbContext();
     AutentificationDbContext = new ApplicationDbContext();
     this.UserManager         = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(AutentificationDbContext));
 }
Exemplo n.º 18
0
 protected DataService(PostsDbContext db)
 {
     this.Data = db;
 }
Exemplo n.º 19
0
 public PostsController(PostsDbContext dbContext, TokensStorage tokensStorage)
 {
     this.dbContext     = dbContext;
     this.tokensStorage = tokensStorage;
 }
Exemplo n.º 20
0
 public PostService(PostsDbContext context, IMapper mapper, IData <BlogPostsTags> serviceBlogPostsTags,
                    IData <Tags> serviceTags) : base(context, mapper)
 {
     _serviceBlogPostsTags = serviceBlogPostsTags;
     _serviceTags          = serviceTags;
 }
Exemplo n.º 21
0
 public Data(PostsDbContext context, IMapper mapper)
 {
     _context = context;
     _entity  = context.Set <T>();
     _mapper  = mapper;
 }