Example #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);
        }
Example #2
0
        public async Task CreateAnimalWithNeeds_Success()
        {
            var animal = new AnimalForCreationDto()
            {
                Needs = new HashSet <NeedsDto>()
                {
                    new NeedsDto()
                    {
                        Id = 1
                    }
                }
            };
            var animalNeeds = new HashSet <AnimalNeeds>()
            {
                new AnimalNeeds()
                {
                    Animal = new Animal()
                    {
                        Id = 1
                    },
                    AnimalId = 1,
                    NeedsId  = 1,
                    Needs    = new Needs()
                    {
                        Id = 1
                    }
                }
            };
            var model = new Animal()
            {
                Id = 1
            };

            _animalNeedsRepositoryMock.Setup(x => x.TryCreateManyToMany(animalNeeds));
            _animalNeedsRepositoryMock.Setup(x => x.SaveAsync());

            await _service.CreateAnimalWithNeeds(animal, model);

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