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(); 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); }
public CommentService(PetFinderContext context, ILogger logger, UserManager <ApplicationUser> userManager, PetService petService) { _context = context; _logger = logger; _userManager = userManager; _petService = petService; }
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; }
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 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)); }
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)); }
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); }
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 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); }); }
public LoginModel(SignInManager <ApplicationUser> signInManager, ILogger logger, UserManager <ApplicationUser> userManager, IAuthJwtService jwtService, PetFinderContext context) { _userManager = userManager; _signInManager = signInManager; _logger = logger; _jwtService = jwtService; _context = context; }
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); }
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); }
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); }
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); }
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); }); }
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())); }
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); }
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); } }
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); }
public PetsController(PetFinderContext context) { _context = context; }