Ejemplo n.º 1
0
        public async Task <int> CreateAsync(CreateFishInListInputModel input, int tripId)
        {
            var fishToAdd = new Fish
            {
                TripId        = tripId,
                Weight        = input.WeightInKilos,
                Length        = input.LengthInCentimeters,
                FishSpeciesId = input.FishSpeciesId,
            };

            await this.fishRepository.AddAsync(fishToAdd);

            await this.fishRepository.SaveChangesAsync();

            return(fishToAdd.Id);
        }
Ejemplo n.º 2
0
        public async Task CreatingFishShouldIncreaseFishRepoCount()
        {
            var fishList     = new List <Fish>();
            var mockFishRepo = new Mock <IDeletableEntityRepository <Fish> >();

            mockFishRepo.Setup(x => x.AddAsync(It.IsAny <Fish>()))
            .Callback((Fish fish) => fishList.Add(fish));
            var fishService = new FishServices(mockFishRepo.Object);

            var fishToAdd = new CreateFishInListInputModel
            {
                WeightInKilos       = 4,
                LengthInCentimeters = 3,
                FishSpeciesId       = 2,
            };

            var beforeAddFishCount = fishList.Count;
            var addedFishId        = await fishService.CreateAsync(fishToAdd, 1);

            var afterAddFishCount = fishList.Count;

            Assert.Equal(beforeAddFishCount + 1, afterAddFishCount);
        }