public async void UpdatingLostDogSuccessfulForExistingDog() { var lostDog = new LostDog() { Breed = "dogdog", Age = 5, Size = "Large, very large", Color = "Orange but a bit yellow and green dots", SpecialMark = "tattoo of you on the neck", Name = "Cat", Picture = new PictureDog() { FileName = "photo", FileType = "png", Data = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }, HairLength = "Long", EarsType = "Short", TailLength = "None", Behaviors = new List <DogBehavior>() { new DogBehavior() { Behavior = "Angry" } }, Location = new LocationDog() { City = "Biała", District = "Lol ther's none" }, DateLost = new DateTime(2021, 3, 20), OwnerId = 1, Comments = new List <LostDogComment>() }; var result = await lostDogRepository.AddLostDog(lostDog); Assert.True(result.Successful); lostDog = result.Data; lostDog.Age = 6; Assert.True((await lostDogRepository.UpdateLostDog(lostDog)).Successful); }
public async Task <ServiceResponse <GetLostDogDto> > UpdateLostDog(UploadLostDogDto lostDogDto, IFormFile picture, int dogId) { var lostDog = mapper.Map <LostDog>(lostDogDto); lostDog.Id = dogId; 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(); } lostDog.Picture = new PictureDog() { FileName = picture.FileName, FileType = picture.ContentType, Data = data }; } else { return new ServiceResponse <GetLostDogDto>() { Successful = false, StatusCode = StatusCodes.Status400BadRequest, Message = pictureValidationResult.Message, } }; } var repoResponse = await lostDogDataRepository.UpdateLostDog(lostDog); var serviceResponse = mapper.Map <RepositoryResponse <LostDog>, ServiceResponse <GetLostDogDto> >(repoResponse); if (!serviceResponse.Successful) { serviceResponse.StatusCode = StatusCodes.Status400BadRequest; } return(serviceResponse); }