예제 #1
0
        public async Task GetFeedbackByIdAsync_Test()
        {
            var    feedbackDB = _listFeedbackDB.FirstOrDefault();
            string id         = feedbackDB.Id;

            _mockUnitRepo.Setup(_ => _.Feedbacks.GetByIdAsync(id))
            .Returns(Task.FromResult(feedbackDB));

            var expectedResult = _mapper.Map <Feedback>(feedbackDB);

            var result = await _service.GetFeedbackByIdAsync(id) as Feedback;

            expectedResult.Should().BeEquivalentTo(result);
        }
예제 #2
0
        public async Task <IHttpActionResult> GetFeedbackByIdAsync(string id)
        {
            if (string.IsNullOrEmpty(id) || !Guid.TryParse(id, out var _))
            {
                return(BadRequest());
            }

            try
            {
                var result = await _feedbackBase.GetFeedbackByIdAsync(id);

                return(result == null?NotFound() : (IHttpActionResult)Ok(result));
            }
            catch (InvalidOperationException ex)
            {
                return(InternalServerError(ex));
            }
        }