public async Task <ServiceResponse <GetCommentDto> > AddLostDogComment(UploadCommentDto commentDto, IFormFile picture) { var comment = mapper.Map <LostDogComment>(commentDto); if (picture is not null) { var pictureValidationResult = securityService.IsPictureValid(picture); if (pictureValidationResult.Successful) { byte[] data; using (var ms = new MemoryStream()) { picture.CopyTo(ms); data = ms.ToArray(); } comment.Picture = new PictureComment() { FileName = picture.FileName, FileType = picture.ContentType, Data = data }; } else { return new ServiceResponse <GetCommentDto>() { Successful = false, StatusCode = StatusCodes.Status400BadRequest, Message = pictureValidationResult.Message, } }; } var repoResponse = await lostDogDataRepository.AddLostDogComment(comment); var serviceResponse = mapper.Map <ServiceResponse <GetCommentDto> >(repoResponse); if (!serviceResponse.Successful) { serviceResponse.StatusCode = StatusCodes.Status400BadRequest; } return(serviceResponse); }
public async void AddLostDogCommentSuccessfulForValidCommentAndExistingDog() { var saveDog = GetValidDog(); var result = await lostDogRepository.AddLostDog(saveDog); Assert.True(result.Successful); var comment = GetValidComment(); comment.DogId = result.Data.Id; var commentResult = await lostDogRepository.AddLostDogComment(comment); Assert.True(commentResult.Successful); }