Ejemplo n.º 1
0
        public async Task EditPostShouldEditTitle()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new ApplicationDbContext(options.Options);
            await context.Users.AddAsync(new ApplicationUser()
            {
                Id = "2"
            });

            var repository = new EfDeletableEntityRepository <Post>(context);
            var service    = new PostService(repository);
            var model      = new CreatePostInputModel()
            {
                Title    = "new",
                Category = "Action",
                Content  = "test",
                ImageUrl = "google",
            };

            var postId = await service.CreateAsync(model, "2");

            var oldPost = await service.GetPostByIdAsync <EditPostViewModel>(postId);

            var titleOldValue = oldPost.Title;

            await service.EditPostAsync(oldPost.Id, "NewValue", oldPost.Content);

            var newPost = await service.GetPostByIdAsync <EditPostViewModel>(postId);

            Assert.NotEqual(titleOldValue, newPost.Title);
        }
Ejemplo n.º 2
0
        public async Task DoesPostBelongToUserShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new ApplicationDbContext(options.Options);
            await context.Users.AddAsync(new ApplicationUser()
            {
                Id = "1"
            });

            await context.Users.AddAsync(new ApplicationUser()
            {
                Id = "2"
            });

            var repository = new EfDeletableEntityRepository <Post>(context);
            var service    = new PostService(repository);
            var model      = new CreatePostInputModel()
            {
                Title    = "new",
                Category = "Action",
                Content  = "test",
                ImageUrl = "google",
            };

            var postId = await service.CreateAsync(model, "2");

            var actual = await service.DoesPostBelongToUserAsync("1", postId);

            Assert.False(actual);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(CreatePostInputModel input)
        {
            string userId = User.Claims.First(x => x.Type == ClaimTypes.NameIdentifier).Value;

            var user = await _httpSender.SendGetAsync <GetUserResponse>(UsersController.UsersRoot + "?id=" + userId);

            PostInput post = new PostInput
            {
                Title       = input.Title,
                Description = input.Description,
                AuthorId    = userId,
                AuthorName  = user.Name
            };

            SimpleRequestResponse result;

            try
            {
                result = await _httpSender.SendPostAsync <SimpleRequestResponse, PostInput>(post, PostsRoot);
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }

            if (result.Succeeded)
            {
                return(Ok());
            }
            else
            {
                return(StatusCode(500, result.Error));
            }
        }
        public void CreatePost_ShouldWorkFine()
        {
            var user = new SimpleSocialUser
            {
                Id       = "test",
                UserName = "******"
            };

            var wall = new Wall()
            {
                Id = "Test"
            };

            var createPostViewModel = new CreatePostInputModel
            {
                Content = "test, test, test",
                UserId  = user.Id,
                WallId  = wall.Id,
            };

            this.PostServices.CreatePost(new MyProfileViewModel
            {
                CreatePost = createPostViewModel
            });

            var postsCount = PostsRepository.All().Count();

            postsCount.ShouldBe(1);
        }
Ejemplo n.º 5
0
        public ActionResult CreatePost(CreatePostInputModel inputPost)
        {
            if (ModelState.IsValid)
            {
                var currentUserId = this.User.Identity.GetUserId();
                string content = HttpUtility.HtmlDecode(inputPost.Content);

                var post = new Post
                {
                    Title = inputPost.Title,
                    Content = this.sanitizer.Sanitize(content),
                    AuthorId = currentUserId
                };

                if (inputPost.CoverPhoto != null)
                {
                    string picturesPath = "/Content/UserFiles/Images/";

                    var cover = inputPost.CoverPhoto.FirstOrDefault();
                    string path = Path.Combine(Server.MapPath(picturesPath), Path.GetFileName(cover.FileName));
                    cover.SaveAs(path);
                    post.CoverPhotoPath = picturesPath + cover.FileName;
                }

                this.posts.Add(post);
                this.posts.SaveChanges();
                this.TempData["SuccessfullNewPost"] = "Well done! Your post was successfully created.";
                return this.RedirectToAction("ShowPost", new { id = post.Id });
            }

            ViewBag.ModelState = "Invalid";
            return this.View(inputPost);
        }
Ejemplo n.º 6
0
        public async Task SearchPostShouldFindOneByTitle()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new ApplicationDbContext(options.Options);
            await context.Users.AddAsync(new ApplicationUser()
            {
                Id = "1"
            });

            var postRepository   = new EfDeletableEntityRepository <Post>(context);
            var guideRepository  = new EfDeletableEntityRepository <Guide>(context);
            var searchBarService = new SearchBarService(postRepository, guideRepository);

            var postService = new PostService(postRepository);
            var postModel   = new CreatePostInputModel()
            {
                Title    = "testings",
                Category = "Action",
                Content  = "new",
                ImageUrl = "google",
            };

            await postService.CreateAsync(postModel, "1");

            var actual = await searchBarService.SearchPost <PostViewModel>("test", 5, 0);

            Assert.Single(actual);
        }
Ejemplo n.º 7
0
        public async Task <int> CreatePost(string userId, CreatePostInputModel input)
        {
            var postImages = new List <PostImage>();

            if (input.Images != null)
            {
                var postImagesUrls = await CloudinaryExtension.UploadAsync(this.cloudinary, input.Images);

                foreach (var url in postImagesUrls)
                {
                    postImages.Add(new PostImage()
                    {
                        ImageUrl = url
                    });
                }
            }

            var newPost = new Post()
            {
                Images      = postImages,
                UserId      = userId,
                Description = input.Description,
            };

            await this.posts.AddAsync(newPost);

            await this.posts.SaveChangesAsync();

            return(newPost.Id);
        }
Ejemplo n.º 8
0
        public async Task GetPostByIdShouldNotReturnModel()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new ApplicationDbContext(options.Options);
            await context.Users.AddAsync(new ApplicationUser()
            {
                Id = "1"
            });

            var repository = new EfDeletableEntityRepository <Post>(context);
            var service    = new PostService(repository);
            var model      = new CreatePostInputModel()
            {
                Title    = "new",
                Category = "Action",
                Content  = "test",
                ImageUrl = "google",
            };

            await service.CreateAsync(model, "1");

            var actual = await service.GetPostByIdAsync <PostViewModel>("1234");

            Assert.Null(actual);
        }
Ejemplo n.º 9
0
        public IActionResult CreatePost(string id)
        {
            var model = new CreatePostInputModel {
                GroupId = id
            };

            return(this.View(model));
        }
Ejemplo n.º 10
0
        public IActionResult Create()
        {
            CreatePostInputModel input = new CreatePostInputModel
            {
                Subjects = this.subjectsService.GetAll(),
            };

            return(this.View(input));
        }
Ejemplo n.º 11
0
        public IActionResult Create()
        {
            var viewModel = new CreatePostInputModel
            {
                Categories = this.categoriesService.GetAllAsKeyValuePairs(),
            };

            return(this.View(viewModel));
        }
        public IActionResult Create()
        {
            CreatePostInputModel inputModel = new CreatePostInputModel
            {
                CourseItems = this.coursesService.GetAllAsSelectListItems(),
            };

            return(this.View(inputModel));
        }
Ejemplo n.º 13
0
        public IActionResult Create()
        {
            var viewModel = new CreatePostInputModel
            {
                Categories = this.categoriesService.GetAll <CategoryDropdownViewModel>(),
            };

            return(this.View(viewModel));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Create(CreatePostInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var userId = this.userManager.GetUserId(this.User);
            var postId = await this.postsService.CreatePost(userId, input);

            return(this.Redirect("/"));
        }
Ejemplo n.º 15
0
        public IActionResult CreateForProfile()
        {
            var userId    = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var profileId = this.profilesService.GetId(userId);

            var viewModel = new CreatePostInputModel();

            viewModel.ReturnId  = profileId;
            viewModel.IsProfile = true;

            return(this.View("Create", viewModel));
        }
        public async Task Create(CreatePostInputModel input)
        {
            var post = new Post
            {
                Content         = input.Content,
                CreatedByUserId = input.CreatedByUserId,
            };

            await this.postsRepository.AddAsync(post);

            await this.postsRepository.SaveChangesAsync();
        }
Ejemplo n.º 17
0
        public async Task <ActionResult> Create(CreatePostInputModel inputModel)
        {
            var post = new Post
            {
                AuthorId = inputModel.AuthorId,
                Title    = inputModel.Title,
                Content  = inputModel.Content,
            };

            await this.posts.Save(post);

            return(this.Ok());
        }
        public async Task CreateAsync(CreatePostInputModel input)
        {
            Post post = new Post
            {
                Content   = input.Content,
                SubjectId = input.SubjectId,
                CreatorId = input.CreatorId,
            };

            await this.postsRepository.AddAsync(post);

            await this.postsRepository.SaveChangesAsync();
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Create([FromBody] CreatePostInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var channelId = this.channelService.GetChannelIdByName(input.ChannelName);
            var userId    = this.userManager.GetUserAsync(User).GetAwaiter().GetResult().Id;
            var post      = await this.postService.CreateAsync(channelId, userId, input.Content);

            return(Json(post));
        }
Ejemplo n.º 20
0
        public async Task CreateForProfileAsyncWorksCorrectly()
        {
            var input = new CreatePostInputModel
            {
                Text  = "test",
                Tags  = null,
                Image = null,
            };

            await this.postsService.CreateForProfileAsync(1, input, "test");

            Assert.Equal(1, await this.postsRepository.All().CountAsync());
        }
Ejemplo n.º 21
0
        public async Task CreatePostAsync(CreatePostInputModel model, string submitterId)
        {
            var poster = await this.userManager.FindByIdAsync(submitterId);

            var group = this.groupRepo.AllAsNoTracking().Where(x => x.Id == model.GroupId).FirstOrDefault();
            var post  = new Post {
                Poster = poster, Title = model.Title, Content = model.Content, GroupId = group.Id, PosterDisplayName = poster.DisplayName
            };

            await this.postRepo.AddAsync(post);

            await this.postRepo.SaveChangesAsync();
        }
Ejemplo n.º 22
0
        public void Setup()
        {
            this.testPost = new CreatePostInputModel()
            {
                Title      = "test",
                CategoryId = 1,
                Content    =
                    "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
            };

            this.postsList = new List <ForumPost>();
            AutoMapperConfig.RegisterMappings(typeof(PostViewModel).Assembly, typeof(ForumPost).Assembly);
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Create(CreatePostInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var id = await this.postsService.CreateAsync(input.Title, input.Content, input.CategoryId, user.Id);

            return(this.RedirectToAction("ById", "Posts", new { Id = id }));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> CreatePost(CreatePostInputModel model, string id)
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            model.GroupId = id;
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }
            await this.groupService.CreatePostAsync(model, userId);

            return(this.RedirectToAction("Group", new { Id = id }));
        }
Ejemplo n.º 25
0
        public async Task CreateAsync(CreatePostInputModel inputModel)
        {
            Post post = new Post
            {
                Content  = inputModel.Content,
                Title    = inputModel.Title,
                CourseId = inputModel.CourseId,
                AuthorId = inputModel.AuthorId,
            };

            await this.postRepository.AddAsync(post);

            await this.postRepository.SaveChangesAsync();
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> CreateForProfile(CreatePostInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var userId    = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var profileId = this.profilesService.GetId(userId);

            await this.postsService.CreateForProfileAsync(profileId, input, $"{this.webHost.WebRootPath}/img/posts");

            return(this.RedirectToAction("ById", "Profiles", new { id = profileId }));
        }
Ejemplo n.º 27
0
        public IActionResult Create(int id)
        {
            var forum = this.forumsService.GetById(id);

            var model = new CreatePostInputModel
            {
                ForumName     = forum.Title,
                AuthorName    = this.User.Identity.Name,
                ForumId       = forum.Id,
                ForumImageUrl = forum.ImageUrl,
            };

            return(this.View(model));
        }
        public async Task <IActionResult> Create(CreatePostInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            string userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            input.CreatedByUserId = userId;

            await this.postsService.Create(input);

            return(this.Redirect("/"));
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> Create(CreatePostInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.Subjects = this.subjectsService.GetAll();
                return(this.View(input));
            }

            ApplicationUser user = await this.userManager.GetUserAsync(this.User);

            input.CreatorId = user.Id;
            await this.postsService.CreateAsync(input);

            return(this.Redirect("/"));
        }
Ejemplo n.º 30
0
        public async Task <IActionResult> Create(CreatePostInputModel inputModel)
        {
            if (this.ModelState.IsValid)
            {
                await this.postsService.AddProduct(
                    inputModel.Title,
                    inputModel.Content,
                    inputModel.PreviewImagePath,
                    inputModel.Tags);

                return(this.RedirectToAction(nameof(this.Index)));
            }

            return(this.View());
        }
Ejemplo n.º 31
0
        public async Task GetByUserShouldTakeTwo()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new ApplicationDbContext(options.Options);
            await context.Users.AddAsync(new ApplicationUser()
            {
                Id = "1"
            });

            var repository = new EfDeletableEntityRepository <Post>(context);
            var service    = new PostService(repository);
            var models     = new List <CreatePostInputModel>()
            {
                new CreatePostInputModel()
                {
                    Title    = "new",
                    Category = "Action",
                    Content  = "test",
                    ImageUrl = "google",
                },
                new CreatePostInputModel()
                {
                    Title    = "new2",
                    Category = "Action",
                    Content  = "test2",
                    ImageUrl = "google2",
                },
            };

            foreach (var model in models)
            {
                await service.CreateAsync(model, "1");
            }

            var lastModel = new CreatePostInputModel()
            {
                Title    = "new3",
                Category = "Rpg",
                Content  = "test3",
                ImageUrl = "google3",
            };
            await service.CreateAsync(lastModel, "2");

            var actual = await service.GetByUserAsync <PostViewModel>("1", 5, 0);

            Assert.Equal(2, actual.Count());
        }