public async Task <AnimalDto> CreateAnimal(AnimalForCreationDto animal) { var model = new Animal(); _mapper.Map(animal, model); using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { model.BreedId = await _breedService.CreateAnimalWithBreed(animal, model); await _repository.AddAsync(model); await _descriptionService.CreateAnimalWithDescription(animal, model); await _locationHistoryService.WriteAnimalLocationHistory(model); await _isNewService.CreateCheckNewOld(animal, model); await _keepingService.CreateAnimalWithKeepings(animal, model); await _needsService.CreateAnimalWithNeeds(animal, model); await _vaccinationService.CreateAnimalWithVaccination(animal, model); await _processingService.CreateAnimalWithProcessing(animal, model); await _attitudesToService.CreateAnimalWithAttitudes(animal, model); await _defectService.CreateAnimalWithDefects(animal, model); scope.Complete(); } var returnModel = GetById(model.Id); return(returnModel); }
public async Task CreateAnimalWithKeepings_Success() { var animal = new AnimalForCreationDto() { Keepings = new HashSet <KeepingDto>() { new KeepingDto() { Id = 1 } } }; var animalKeeping = new HashSet <AnimalKeeping>() { new AnimalKeeping() { Animal = new Animal() { Id = 1 }, AnimalId = 1, KeepingId = 1, Keeping = new Keeping() { Id = 1 } } }; var model = new Animal() { Id = 1 }; _animalKeepingRepositoryMock.Setup(x => x.TryCreateManyToMany(animalKeeping)); _animalKeepingRepositoryMock.Setup(x => x.SaveAsync()); await _service.CreateAnimalWithKeepings(animal, model); _animalKeepingRepositoryMock.Verify(x => x.TryCreateManyToMany(It.IsAny <IEnumerable <AnimalKeeping> >()), Times.Once()); _animalKeepingRepositoryMock.Verify(x => x.SaveAsync(), Times.Once()); }