public void ShouldBeValidName()
        {
            PetFinderContext  context     = dbContextFactory.CreateContext();
            AnimalTypeService cityService = new AnimalTypeService(context, logger);

            string invalidName = "Perro Lobo"; // Solo deberia aceptar numeros de la A a la Z
            bool   isValid     = cityService.IsValidName(invalidName);

            Assert.True(isValid);
        }
        public void ShouldBeInvalidNameIlegalCharacters()
        {
            PetFinderContext  context     = dbContextFactory.CreateContext();
            AnimalTypeService cityService = new AnimalTypeService(context, logger);

            string invalidName = "@asdasd 213"; // Solo deberia aceptar letras de la A a la Z
            bool   isValid     = cityService.IsValidName(invalidName);

            Assert.False(isValid);
        }
        public void ShouldBeInvalidName()
        {
            PetFinderContext  context     = dbContextFactory.CreateContext();
            AnimalTypeService cityService = new AnimalTypeService(context, logger);

            string invalidName = "algo muy largo con muchos caracteres";
            bool   isValid     = cityService.IsValidName(invalidName);

            // Deberia ser falso ya que la cadena tiene 36 caracteres, siendo el maximo 35
            Assert.False(isValid);
        }
        public async Task ShouldNotSaveWithSameName()
        {
            PetFinderContext  context            = dbContextFactory.CreateContext();
            AnimalType        animalType         = CreateAnimalType("Perro");
            AnimalType        animalTypeRepeated = CreateAnimalType("Perro");
            AnimalTypeService animalTypeService  = new AnimalTypeService(context, logger);

            await animalTypeService.Save(animalType);

            GenericResult result = await animalTypeService.Save(animalTypeRepeated);

            // No deberia insertarse ya que existe una ciudad con el mismo nombre
            Assert.False(result.Success);
        }
Example #5
0
        public async Task RemoveAnimalType_AnimalTypeRemoved_RemoveSuccess(
            [Frozen] Mock <IRepositoryWrapper> mockRepositoryWrapper,
            [Frozen] Mock <AnimalType> animalType)
        {
            //Arrange
            mockRepositoryWrapper.Setup(x => x.AnimalTypeRepository.Remove(It.IsAny <AnimalType>()));
            var Sut = new AnimalTypeService(mockRepositoryWrapper.Object);

            //Act
            await Sut.RemoveAnimalType(animalType.Object);

            //Assert
            mockRepositoryWrapper.Verify(x => x.AnimalTypeRepository.Remove(It.IsAny <AnimalType>()));
            mockRepositoryWrapper.Verify(x => x.SaveAsync());
        }
        public async Task ShouldAddAsync()
        {
            PetFinderContext  context           = dbContextFactory.CreateContext();
            AnimalType        animalType        = CreateAnimalType("Perro Lobo");
            AnimalTypeService animalTypeService = new AnimalTypeService(context, logger);

            await animalTypeService.Save(animalType);

            AnimalType animalTypeGato = CreateAnimalType("Gato");
            await animalTypeService.Save(animalTypeGato);

            int numberOfAnimalTypes = context.AnimalTypes.Count();

            // Deberia haber una sola ciudad ya que editamos la misma que insertamos
            Assert.Equal <int>(2, numberOfAnimalTypes);
        }
Example #7
0
        public async Task GetAll_GetSuccess(
            [Frozen] Mock <IRepositoryWrapper> mockRepositoryWrapper,
            [Frozen] ICollection <AnimalType> animalTypes)
        {
            //Arrange
            mockRepositoryWrapper.Setup(x => x.AnimalTypeRepository
                                        .GetAsync(null, It.IsAny <Func <IQueryable <AnimalType>, IIncludableQueryable <AnimalType, object> > >(), null, null, null, false))
            .ReturnsAsync(animalTypes);
            var Sut = new AnimalTypeService(mockRepositoryWrapper.Object);

            //Act
            var actual = await Sut.GetAllAsync();

            //Assert
            Assert.IsType <List <AnimalType> >(actual);
            mockRepositoryWrapper.Verify(x => x.AnimalTypeRepository.GetAsync(null, It.IsAny <Func <IQueryable <AnimalType>, IIncludableQueryable <AnimalType, object> > >(), null, null, null, false));
        }
 public async Task <AnimalTypeDto> GetById([FromRoute] Guid id)
 {
     _logger.LogInformation($"GetAnimalTypeById: {id}");
     return(await AnimalTypeService.GetById(id));
 }
 public IEnumerable <AnimalTypeDto> GetAll()
 {
     _logger.LogInformation("GetAllAnimalTypes");
     return(AnimalTypeService.GetAll().ToArray());
 }