コード例 #1
0
        private async Task <OperationResult <int> > Delete(CreateQuestion item)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var question = await questionRepo.GetByIdAsync(item.id);

                if (question == null)
                {
                    return new OperationResult <int>()
                           {
                               Success = false, Message = Messages.QUESTION_NOT_EXIST
                           }
                }
                ;
                if (question.authorId != item.authorId)
                {
                    return new OperationResult <int>()
                           {
                               Success = false, Message = Messages.USER_NO_QUESTION
                           }
                }
                ;

                try
                {
                    var id = await questionRepo.DeleteAsync(question);

                    scope.Complete();
                    return(new OperationResult <int>()
                    {
                        Success = true, Message = Messages.QUESTION_DELETED, Result = id
                    });
                }
                catch (Exception ex)
                {
                    return(new OperationResult <int>()
                    {
                        Success = false, Message = ex.Message
                    });
                }
            }
        }
    }
}
コード例 #2
0
        public void CreateQuestion()
        {
            int newQuestionID = 0;

            try
            {
                newQuestionID = questionRepo.PostAsync(new CreateQuestion()
                {
                    authorId = "1", sessionId = 1, message = "entao?"
                }).Result;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentException));
            }
            var res = questionRepo.GetByIdAsync(newQuestionID).Result;

            Assert.AreEqual(res.message, "entao?");
            var id = questionRepo.DeleteAsync(res).Result;
        }