Esempio n. 1
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);
            });
        }
Esempio n. 2
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);
        }
Esempio n. 3
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));
        }
Esempio n. 4
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);
            });
        }
Esempio n. 5
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);
        }