public async Task ShouldAddThreePosts() { var converterMock = new Mock <IBlogConverter>(); converterMock .Setup(x => x.ConvertToPost(It.IsAny <AddPostDto>())) .Returns(new Post()); var repositoryMock = new Mock <IBlogRepository>(); repositoryMock .Setup(x => x.Add(It.IsAny <Post>())) .ReturnsAsync(1); var service = new BlogService(converterMock.Object, repositoryMock.Object); await service.AddPost(new AddPostDto()); await service.AddPost(new AddPostDto()); await service.AddPost(new AddPostDto()); converterMock.Verify(x => x.ConvertToPost(It.IsAny <AddPostDto>()), Times.Exactly(3)); repositoryMock.Verify(x => x.Add(It.IsAny <Post>()), Times.Exactly(3)); }
public void Delete_ByUser() { var controller = new PostController(database); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); LiteDatabase db = database; var col = db.GetCollection <User>(); col.Delete(123); col.Insert(new User { username = "******", password = "******", id = 123, status = "user" }); IBlogService bs = new BlogService(); bs.AddPost(new BlogService.PostWCF { User = "******", Date = "01.01.2001", Content = "some content 100g chicken", Title = "" }); var response = controller.Delete(JObject.Parse("{ \"id\":\"123\",\"delete\":\"125\"}")); Assert.AreNotEqual(null, response); var tmp = response as BadRequestErrorMessageResult; Assert.AreEqual("You don't have sufficient rights to delete posts!", tmp.Message); }
public string Post([FromBody] BlogData data) { var blog = data; blogService.AddPost(data); return(Newtonsoft.Json.JsonConvert.SerializeObject(data)); }
public void PostPostTest() { var responseUser = _userController.Register(JObject.Parse("{\"username\": \"Test\", \"password\": \"test\", \"status\": \"user\"}")); Assert.AreNotEqual(null, responseUser["id"]); var count1 = _blogContext.Posts.Count(); _blogService.AddPost(new BlogService.PostWCF() { User = "******", Content = "for breakfast i ate 2 eggs", Date = "01.02.2015", Title = "Tytul" }); var count2 = _blogContext.Posts.Count(); Assert.AreEqual(count1 + 1, count2); var itemToDelete = _blogContext.Posts.ToList().FindAll(c => c.User.Equals("Test")); _blogContext.Posts.RemoveRange(itemToDelete); }
public void BlogServiceShouldAddThrougthWriteRepository() { var readRepoMock = new Mock<IBlogRepository>(); IBlogService service = new BlogService(null, readRepoMock.Object); service.AddPost(new BlogPost()); readRepoMock.Verify(x => x.AddPost(It.IsAny<BlogPost>()), Times.Once()); service.AddComment(new Comment()); readRepoMock.Verify(x => x.AddComment(It.IsAny<Comment>()), Times.Once()); }
public ActionResult Edit(EditPostViewModel viewModel) { if (viewModel.Content.Id.HasValue) { BlogService.EditPost(viewModel.Content, viewModel.Tags); } else { viewModel.Content.AuthorId = User.UserId; BlogService.AddPost(User.Blogs.First().Id, viewModel.Content, viewModel.Tags); } return(Json(new ProcessResult(new { ContentId = viewModel.Content.Id }))); }
public async Task ShouldAddPost() { var converterMock = new Mock <IBlogConverter>(); converterMock .Setup(x => x.ConvertToPost(It.IsAny <AddPostDto>())) .Returns(new Post()); var repositoryMock = new Mock <IBlogRepository>(); repositoryMock .Setup(x => x.Add(It.IsAny <Post>())) .ReturnsAsync(1); var service = new BlogService(converterMock.Object, repositoryMock.Object); var id = await service.AddPost(new AddPostDto()); Assert.Equal(1, id); }