public async Task <IHttpActionResult> CreateFeedbackAsync
            ([FromBody, CustomizeValidator] FeedbackAdd_DTO feedback)
        {
            if (feedback is null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _feedbackBase.AddFeedbackAsync(feedback);

            return(result.IsError ? BadRequest(result.Message) : (IHttpActionResult)Ok(result.Data));
        }
Esempio n. 2
0
        public async Task AddFeedbackAsync_Test()
        {
            var      add_DTO   = _listFeedbackAdd_DTO.FirstOrDefault();
            var      forAdd    = _mapper.Map <FeedbackDB>(add_DTO);
            Feedback whasAdded = null;

            _mockUnitRepo.Setup(_ => _.Feedbacks.Add(forAdd));

            _mockUnitRepo.Setup(_ => _.SaveAsync())
            .Callback(() => { whasAdded = _mapper.Map <Feedback>(forAdd); });

            var result = await _service.AddFeedbackAsync(add_DTO);

            result.IsError.Should().BeFalse();
            result.Data.Text.Should().BeEquivalentTo(whasAdded.Text);//becouse result and whasAdded are from different mapping add_DTO
        }