public async Task AddLikeShoutAddItInDB() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var postRepository = new EfDeletableEntityRepository <Post>(dbContext); var likeRepository = new EfRepository <Like>(dbContext); dbContext.Posts.Add(new Post { Id = "postId", Text = "text", CreatedOn = DateTime.UtcNow, UserId = "userId", UserName = "******", }); await dbContext.SaveChangesAsync(); var service = new LikeService(postRepository, likeRepository); await service.CreateLike("userId", "postId", "david"); Assert.Equal(1, dbContext.Likes.Count()); }
//POST public IHttpActionResult Post(AddLike model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } LikeService service = CreateLikeService(); if (!service.CreateLike(model)) { return(InternalServerError()); } return(Ok()); }
public async Task <IActionResult> NewLike(Like like) { var settings = ConnectionSettings.CreateBasicAuth(Neo4JClient.uri, Neo4JClient.user, Neo4JClient.password); using (var client = new Neo4JClient(settings)) { LikeService myService = new LikeService(client); myService.addLike(like); string aux = await myService.CreateLike(myService.likes); Response ans = new Response() { Ans = aux }; return(Created(Neo4JClient.uri, ans)); } }