Exemple #1
0
        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);
        }
Exemple #2
0
        public async Task CreateAnimalWithAttitudes_Success()
        {
            var animal = new AnimalForCreationDto()
            {
                Attitudes = new HashSet <AttitudeToDto>()
                {
                    new AttitudeToDto()
                    {
                        Id = 1
                    }
                }
            };
            var animalAttitude = new HashSet <AnimalAttitudeTo>()
            {
                new AnimalAttitudeTo()
                {
                    Animal = new Animal()
                    {
                        Id = 1
                    },
                    AnimalId   = 1,
                    AttitudeId = 1,
                    AttitudeTo = new AttitudeTo()
                    {
                        Id = 1
                    }
                }
            };
            var model = new Animal()
            {
                Id = 1
            };

            _animalAttitudeToRepositoryMock.Setup(x => x.TryCreateManyToMany(animalAttitude));
            _animalAttitudeToRepositoryMock.Setup(x => x.SaveAsync());

            await _service.CreateAnimalWithAttitudes(animal, model);

            _animalAttitudeToRepositoryMock.Verify(x => x.TryCreateManyToMany(It.IsAny <IEnumerable <AnimalAttitudeTo> >()),
                                                   Times.Once());
            _animalAttitudeToRepositoryMock.Verify(x => x.SaveAsync(), Times.Once());
        }