예제 #1
0
        public void TestDeleteCommentAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfDeletableEntityRepository <Comment>(new ApplicationDbContext(options.Options));
            var service    = new CommentsServices(repository);

            var comment = new CommentsInputModel
            {
                GameId  = 1,
                Content = "test",
                UserId  = "2",
            };

            service.CreateAsync(comment).GetAwaiter().GetResult();

            var firstCounter = repository.All().Count();

            service.DeleteCommentAsync("test", "2", 1).GetAwaiter().GetResult();

            var secondCounter = repository.All().Count();

            Assert.True(firstCounter == 1 && secondCounter == 0);
        }
예제 #2
0
 public ActionResult Comments(CommentsViewModel viewModel)
 {
     //Recaptcha驗證欄位是否通過
     if (Common.IsValid())
     {
         //表單驗證欄位是否通過
         if (ModelState.IsValid)
         {
             try
             {
                 var result = new CommentsServices().Add(
                     new CommentsDto()
                 {
                     CUST_NAME      = viewModel.CustName,
                     CUST_TEL       = viewModel.Tel,
                     CUST_EMAIL     = viewModel.Email,
                     CUST_DATA_TYPE = viewModel.QuestionType,
                     CUST_MESSAGE   = viewModel.Content
                 });
                 if (result.ERRCODE == 0)
                 {
                     return(Json(new Result()
                     {
                         ReturnCode = 0, ReturnMsg = Url.Action("CommentsSuccess", "Home")
                     }, JsonRequestBehavior.AllowGet));
                 }
                 else
                 {
                     TempData["errorMsg"] = "發送異常:請稍後再試或聯絡客服。";
                     return(Json(new Result()
                     {
                         ReturnCode = 2, ReturnMsg = Url.Action("Error", "Home")
                     }, JsonRequestBehavior.AllowGet));
                 }
             }
             catch
             {
                 TempData["errorMsg"] = "發送異常:請稍後再試或聯絡客服。";
                 return(Json(new Result()
                 {
                     ReturnCode = 2, ReturnMsg = Url.Action("Error", "Home")
                 }, JsonRequestBehavior.AllowGet));
             }
         }
         return(Json(new Result()
         {
             ReturnCode = 3, ReturnMsg = "Recaptcha valid but modul not valide"
         }, JsonRequestBehavior.AllowGet));
     }
     return(Json(new Result()
     {
         ReturnCode = 1, ReturnMsg = "Failed Validation Error"
     }, JsonRequestBehavior.AllowGet));
 }
예제 #3
0
        public async void CanCreateComments()
        {
            DbContextOptions <CookbookDbContext> options = new DbContextOptionsBuilder <CookbookDbContext>().UseInMemoryDatabase("CanCreateComments").Options;

            using (CookbookDbContext context = new CookbookDbContext(options))
            {
                Comments comments = new Comments();
                comments.ID            = 1;
                comments.APIReference  = 2;
                comments.SavedRecipeID = 3;
                comments.Comment       = "So delish";

                CommentsServices commentsServices = new CommentsServices(context);

                await commentsServices.CreateComment(comments);

                var result = context.Comments.FirstOrDefault(c => c.ID == comments.ID);

                Assert.Equal(comments, result);
            }
        }