Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void ShouldBeInvalidName()
        {
            PetFinderContext context     = dbContextFactory.CreateContext();
            PetService       petService  = new PetService(context);
            string           invalidName = "asdasdasdasdasdasdasd";
            bool             isValid     = petService.IsValidName(invalidName);

            // Deberia ser falso ya que la cadena tiene 21 caracteres, siendo el maximo 20
            Assert.False(isValid);
        }
Ejemplo n.º 3
0
 public CommentService(PetFinderContext context,
                       ILogger logger,
                       UserManager <ApplicationUser> userManager,
                       PetService petService)
 {
     _context     = context;
     _logger      = logger;
     _userManager = userManager;
     _petService  = petService;
 }
Ejemplo n.º 4
0
        public void ShouldBeMissingDataAsync()
        {
            PetFinderContext context = dbContextFactory.CreateContext();
            Pet           pet        = new Pet();
            PetService    petService = new PetService(context);
            List <string> errors     = petService.CheckPet(pet);

            //Deberia dar 6 errores
            Assert.Equal <int>(6, errors.Count);
        }
 public CommentsController(ILogger <CommentsController> logger,
                           PetFinderContext context,
                           ICommentService commentService,
                           IJWTService jwtService)
 {
     _logger         = logger;
     _context        = context;
     _commentService = commentService;
     _JWTService     = jwtService;
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public async Task ShouldInsertAsync()
        {
            PetFinderContext context       = dbContextFactory.CreateContext();
            Gender           gender        = CreateGender("Masculino");
            GenderService    genderService = new GenderService(context);

            await genderService.Save(gender);

            // Deberia insertarse
            Assert.Equal <Gender>(gender, context.Genders.Find(gender.Id));
        }
Ejemplo n.º 8
0
        public async Task ShouldInsertAsync()
        {
            PetFinderContext context     = dbContextFactory.CreateContext();
            City             city        = CreateCity("Tres Arroyos");
            CityService      cityService = new CityService(context, logger);

            await cityService.Save(city);

            // Deberia insertarse
            Assert.Equal <City>(city, context.Cities.Find(city.Id));
        }
Ejemplo n.º 9
0
        public async void ShouldBeNotRepeated()
        {
            PetFinderContext context       = dbContextFactory.CreateContext();
            GenderService    genderService = new GenderService(context);

            string notRepeatedName = "Masculino";
            bool   isValid         = await genderService.IsRepeated(notRepeatedName);

            // Deberia ser falso ya que la cadena tiene 21 caracteres, siendo el maximo 20
            Assert.False(isValid);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        public async Task ShouldNotInsertAsync()
        {
            PetFinderContext context       = dbContextFactory.CreateContext();
            Gender           gender        = new Gender();
            GenderService    genderService = new GenderService(context);

            // No deberia insertarse ya que no tiene nombre
            await Assert.ThrowsAsync <DbUpdateException>(async() =>
            {
                await genderService.Save(gender);
            });
        }
Ejemplo n.º 12
0
 public LoginModel(SignInManager <ApplicationUser> signInManager,
                   ILogger logger,
                   UserManager <ApplicationUser> userManager,
                   IAuthJwtService jwtService,
                   PetFinderContext context)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _logger        = logger;
     _jwtService    = jwtService;
     _context       = context;
 }
Ejemplo n.º 13
0
        public async Task ShouldNotInsertAsync()
        {
            PetFinderContext context     = dbContextFactory.CreateContext();
            City             city        = new City();
            CityService      cityService = new CityService(context, logger);

            // No deberia insertarse ya que no tiene nombre
            GenericResult result = await cityService.Save(city);

            // No deberia insertarse ya que existe una ciudad con el mismo nombre
            Assert.False(result.Success);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        public async Task ShouldNotSaveWithSameName()
        {
            PetFinderContext context      = dbContextFactory.CreateContext();
            City             city         = CreateCity("Tres Arroyos");
            City             cityRepeated = CreateCity("Tres Arroyos");
            CityService      cityService  = new CityService(context, logger);

            await cityService.Save(city);

            // No deberia insertarse ya que existe una ciudad con el mismo nombre
            GenericResult result = await cityService.Save(cityRepeated);

            // No deberia insertarse ya que existe una ciudad con el mismo nombre
            Assert.False(result.Success);
        }
Ejemplo n.º 16
0
        public async Task ShouldDelete()
        {
            PetFinderContext context     = dbContextFactory.CreateContext();
            City             city        = CreateCity("Tres Arroyos");
            CityService      cityService = new CityService(context, logger);

            await cityService.Save(city);

            await cityService.Delete(city.Id);

            int numberOfCities = await context.Cities.CountAsync();

            // No debería haber ciudades ya que se elimino la unica que se inserto
            Assert.Equal <int>(0, numberOfCities);
        }
Ejemplo n.º 17
0
        public async Task ShouldNotSaveWithSameName()
        {
            PetFinderContext context       = dbContextFactory.CreateContext();
            Gender           gender1       = CreateGender("Masculino");
            Gender           gender2       = CreateGender("Masculino");
            GenderService    genderService = new GenderService(context);

            await genderService.Save(gender1);

            // No deberia insertarse ya que existe un genero con el mismo nombre
            await Assert.ThrowsAsync <GenderAlreadyExistsException>(async() =>
            {
                await genderService.Save(gender2);
            });
        }
Ejemplo n.º 18
0
        public async Task ShouldDelete()
        {
            PetFinderContext context       = dbContextFactory.CreateContext();
            Gender           gender        = CreateGender("Masculino");
            GenderService    genderService = new GenderService(context);

            await genderService.Save(gender);

            await genderService.Delete(gender.Id);

            int numberOfGenders = await context.Genders.CountAsync();

            // Deberia haber 2 generos que son los que vienen por defecto
            Assert.Equal <int>(2, numberOfGenders);
        }
        public PetFinderContext CreateContext()
        {
            if (_connection == null)
            {
                _connection = new SqliteConnection("DataSource=:memory:");
                _connection.Open();

                var options = CreateOptions();
                using (var context = new PetFinderContext(options))
                {
                    context.Database.EnsureCreated();
                }
            }

            return(new PetFinderContext(CreateOptions()));
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        public async Task ShouldUpdateAsync()
        {
            PetFinderContext context       = dbContextFactory.CreateContext();
            Gender           gender        = CreateGender("Masculino");
            GenderService    genderService = new GenderService(context);

            await genderService.Save(gender);

            gender.Name = "Femenino";
            await genderService.Save(gender);

            int numberOfGenders = await context.Genders.CountAsync();

            // Deberia haber tres generos ya que dos vienen por defecto e insertamos uno solo
            Assert.Equal <int>(3, numberOfGenders);
        }
        public PetFinderContext CreateContext()
        {
            var options = CreateOptions(Guid.NewGuid().ToString("N"));
            var context = new PetFinderContext(options);

            var initialGenders = new List <Gender>
            {
                new() { Name = "Macho", SerializedName = "MACHO" },
                new() { Name = "Hembra", SerializedName = "HEMBRA" }
            };

            context.Genders.AddRange(initialGenders);
            context.SaveChanges();

            return(context);
        }
    }
Ejemplo n.º 23
0
        public async Task ShouldUpdateAsync()
        {
            PetFinderContext context     = dbContextFactory.CreateContext();
            City             city        = CreateCity("Tres Arroyos");
            CityService      cityService = new CityService(context, logger);

            await cityService.Save(city);

            city.Name           = "Edited mock";
            city.SerializedName = "EDITEDMOCK";
            await cityService.Save(city);

            int numberOfCities = await context.Cities.CountAsync();

            // Deberia haber una sola ciudad ya que editamos la misma que insertamos
            Assert.Equal <int>(1, numberOfCities);
        }
Ejemplo n.º 24
0
 public PetsController(PetFinderContext context)
 {
     _context = context;
 }