public async Task SaveAsyncWhenSaveReturnsSaved()
        {
            //Arrange
            var mockVeterinaryProfileRepository   = GetDefaultIVeterinaryProfileRepositoryInstance();
            var mockVeterinarySpecialtyRepository = GetDefaultIVeterinarySpecialtyRepositoryInstance();
            var mockVetVeterinaryRepository       = GetDefaultIVetVeterinaryRepositoryInstance();
            var mockUnitOfWork         = GetDefaultIUnitOfWorkInstance();
            var mockCityRepository     = GetDefaultICityRepositoryInstance();
            var mockProvinceRepository = GetDefaultIProvinceRepositoryInstance();

            Province province = new Province {
                Id = 1, Name = "Lima"
            };
            City city = new City {
                Id = 10, Name = "SJL", ProvinceId = 1
            };
            VeterinaryProfile veterinaryProfile = new VeterinaryProfile {
                Id = 10, Name = "Huellitas"
            };

            mockProvinceRepository.Setup(p => p.AddAsync(province))
            .Returns(Task.FromResult <Province>(province));

            mockProvinceRepository.Setup(p => p.FindById(1))
            .Returns(Task.FromResult <Province>(province));

            mockCityRepository.Setup(r => r.AddAsync(city))
            .Returns(Task.FromResult <City>(city));


            mockCityRepository.Setup(p => p.FindById(10))
            .Returns(Task.FromResult <City>(city));

            mockVeterinaryProfileRepository.Setup(r => r.AddAsync(veterinaryProfile))
            .Returns(Task.FromResult <VeterinaryProfile>(veterinaryProfile));

            var service = new VeterinaryProfileService(mockVeterinaryProfileRepository.Object, mockVeterinarySpecialtyRepository.Object
                                                       , mockVetVeterinaryRepository.Object, mockUnitOfWork.Object, mockProvinceRepository.Object, mockCityRepository.Object);

            //Act
            VeterinaryProfileResponse result = await service.SaveAsync(10, 1, veterinaryProfile);

            //Assert
            result.Resource.Should().Be(veterinaryProfile);
        }
Exemplo n.º 2
0
        public async Task <VeterinaryProfileResponse> UpdateAsync(int id, VeterinaryProfile veterinaryProfile)
        {
            var existingVeterinaryProfile = await _veterinaryProfileRepository.FindById(id);

            if (existingVeterinaryProfile == null)
            {
                return(new VeterinaryProfileResponse("Veterinary not found"));
            }
            existingVeterinaryProfile.Name             = veterinaryProfile.Name;
            existingVeterinaryProfile.TelephonicNumber = veterinaryProfile.TelephonicNumber;
            try
            {
                _veterinaryProfileRepository.Update(existingVeterinaryProfile);
                await _unitOfWork.CompleteAsync();

                return(new VeterinaryProfileResponse(existingVeterinaryProfile));
            }
            catch (Exception ex)
            {
                return(new VeterinaryProfileResponse($"An error ocurred while updating: {ex.Message}"));
            }
        }
Exemplo n.º 3
0
        public async Task <VeterinaryProfileResponse> SaveAsync(int cityId, int provinceId, VeterinaryProfile veterinaryProfile)
        {
            var existingProvince = await _provinceRepository.FindById(provinceId);

            var existingCity = await _cityRepository.FindById(cityId);

            if (existingProvince == null)
            {
                return(new VeterinaryProfileResponse("Province not found, a veterinary needs a province to exist"));
            }
            if (existingCity == null)
            {
                return(new VeterinaryProfileResponse("City not found, a veterinary needs a city to exist"));
            }
            if (existingCity.ProvinceId != provinceId)
            {
                return(new VeterinaryProfileResponse("The City does not exist in the province"));
            }
            try
            {
                await _veterinaryProfileRepository.AddAsync(veterinaryProfile);

                await _unitOfWork.CompleteAsync();

                return(new VeterinaryProfileResponse(veterinaryProfile));
            }
            catch (Exception ex)
            {
                return(new VeterinaryProfileResponse($"An error ocurred while saving veterinary profile: {ex.Message}"));
            }
        }
 public void Update(VeterinaryProfile veterinaryProfile)
 {
     _context.VeterinaryProfiles.Update(veterinaryProfile);
 }
 public void Remove(VeterinaryProfile veterinaryProfile)
 {
     _context.VeterinaryProfiles.Remove(veterinaryProfile);
 }
 public async Task AddAsync(VeterinaryProfile veterinaryProfile)
 {
     await _context.VeterinaryProfiles.AddAsync(veterinaryProfile);
 }