コード例 #1
0
        public void Return_PostReply_Correctly_By_PostReplyId()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Get_Post_By_Id").Options;

            using (var ctx = new ApplicationDbContext(options))
            {
                ctx.PostReplies.Add(new PostReply
                {
                    Id      = 221,
                    Content = "Test Reply"
                });

                ctx.PostReplies.Add(new PostReply
                {
                    Id      = 111,
                    Content = "Second Reply"
                });

                ctx.SaveChanges();
            }

            //Act
            using (var ctx = new ApplicationDbContext(options))
            {
                var replyService = new ReplyService(ctx);
                var reply        = replyService.GetById(221);

                //Assert
                Assert.AreEqual(reply.Content, "Test Reply");
            }
        }