예제 #1
0
        public async Task DeleteFailsWhenIdNotInDatabase()
        {
            AutoMapperInitializer.InitializeMapper();
            var context    = InMemoryDbContextInitializer.InitializeContext();
            var repository = new EfDeletableEntityRepository <Skill>(context);

            var service = new SkillsService(repository);
            var result  = await service.DeleteAsync(100);

            Assert.False(result);
        }
        public void DeleteSkill()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var repository =
                new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options));
            var studentEfRepository =
                new EfRepository <StudentJob>(new ApplicationDbContext(options.Options));
            var userSkillRepository =
                new EfRepository <UsersSkill>(new ApplicationDbContext(options.Options));
            var jobRepository =
                new EfDeletableEntityRepository <Job>(new ApplicationDbContext(options.Options));
            var jobService      = new JobsService(jobRepository, studentEfRepository);
            var skillRepository =
                new EfDeletableEntityRepository <Skill>(new ApplicationDbContext(options.Options));
            var skillService = new SkillsService(skillRepository, userSkillRepository);
            var usersService = new ApplicationUsersService(repository, jobService, studentEfRepository, jobRepository, skillService, userSkillRepository, skillRepository);
            var user         = new ApplicationUser
            {
                FullName = "Gosho"
            };

            var skill = new Skill
            {
                Name = "C#",
            };

            var userSkill = new UsersSkill
            {
                SkillId           = skill.Id,
                ApplicationUserId = user.Id,
            };

            repository.AddAsync(user).GetAwaiter().GetResult();
            repository.SaveChangesAsync().GetAwaiter().GetResult();
            skillRepository.AddAsync(skill).GetAwaiter().GetResult();
            skillRepository.SaveChangesAsync().GetAwaiter().GetResult();
            userSkillRepository.AddAsync(userSkill).GetAwaiter().GetResult();
            userSkillRepository.SaveChangesAsync();
            userSkillRepository.Delete(userSkill);
            skillService.DeleteAsync(skill.Id, user.Id).GetAwaiter().GetResult();
            Assert.Equal(1, skillRepository.All().Count());
        }
예제 #3
0
        public async Task DeleteMarksRecordAsDeleted()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.Skills.AddAsync(new Skill { Id = 1, Name = "Skill", IsDeleted = false });

            await context.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Skill>(context);

            var service = new SkillsService(repository);

            var result = await service.DeleteAsync(1);

            var dbRecord = await context.Skills.FindAsync(1);

            Assert.True(result);
            Assert.True(dbRecord.IsDeleted);
            Assert.NotNull(dbRecord.DeletedOn);
            Assert.Equal(1, context.Skills.IgnoreQueryFilters().Count());
        }