Esempio n. 1
0
        public async Task Create_Async_Test()
        {
            var options = new DbContextOptionsBuilder <FriendyContext>()
                          .UseInMemoryDatabase(databaseName: "Create_Async_Test")
                          .Options;
            int    postId  = 1;
            string content = new Guid().ToString();

            using (var context = new FriendyContext(options))
            {
                var repo       = new RepositoryWrapper(context);
                var service    = new PostCommentService(repo, null);
                var controller = new PostCommentController(service);
                var res        = await controller.CreateAsync(_userId, new NewCommentDto()
                {
                    PostId  = postId,
                    Content = content
                }, null);

                var value = res.Value;
                Assert.NotNull(value);
                Assert.IsType <object>(value);
                Assert.Equal(value.Content, content);
            }
        }
Esempio n. 2
0
        //[InlineData(2,7)]
        public async Task Get_All_By_Post_Id_Tests(int postId, int userId)
        {
            var options = new DbContextOptionsBuilder <FriendyContext>()
                          .UseInMemoryDatabase(databaseName: "Get_All_By_Post_Id_Tests")
                          .Options;

            using (var context = new FriendyContext(options))
            {
                var data = GetData(20).ToList();
                context.MainComment.AddRange(data);
                context.SaveChanges();
            }

            using (var context = new FriendyContext(options))
            {
                var repo       = new RepositoryWrapper(context);
                var service    = new PostCommentService(repo, null);
                var controller = new PostCommentController(service);
                var res        = await controller.GetAllByPostIdAsync(postId, userId);

                Assert.NotNull(res);
            }
        }