public void TestGetCompaniesCount() { 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); AutoMapperConfig.RegisterMappings(typeof(CompaniesServiceTests.MyTest).Assembly); var user = new ApplicationUser { FullName = "IvanIvanov", Email = "test@test", Type = UserType.Employer, }; repository.AddAsync(user); repository.SaveChangesAsync(); Assert.Equal(1, usersService.GetCompaniesCount()); repository.Delete(user); repository.SaveChangesAsync(); }
public void TestsTakeAndDeleteUser() { 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 { Description = "test", Type = UserType.Employer, }; repository.AddAsync(user).GetAwaiter().GetResult(); repository.SaveChangesAsync().GetAwaiter().GetResult(); AutoMapperConfig.RegisterMappings(typeof(CompaniesServiceTests.MyTest).Assembly); usersService.DeleteAsync(user.Id).GetAwaiter().GetResult(); Assert.Empty(repository.All()); repository.Delete(user); repository.SaveChangesAsync().GetAwaiter().GetResult(); }
public async Task EfDeletableEntityRepoAllWithDeletedShouldWork() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "EfDeletableEntityRepoAllWithDeletedShouldWork").Options; var dbContext = new ApplicationDbContext(options); var repository = new EfDeletableEntityRepository <Category>(dbContext); var service = new CategoriesService(repository); await service.AddAsync("test", new Image() { Url = "https://miau.bg/files/lib/600x350/agresive-cat1.jpg" }, "description"); await service.AddAsync("test2", new Image() { Url = "https://miau.bg/files/lib/600x350/agresive-cat1.jpg" }, "description2"); await service.AddAsync("test3", new Image() { Url = "https://miau.bg/files/lib/600x350/agresive-cat1.jpg" }, "description3"); var categoryToDelete = service.GetCategoryByName("test3"); repository.Delete(categoryToDelete); await repository.SaveChangesAsync(); var result = repository.AllWithDeleted().ToList(); Assert.Equal(3, result.Count); }
public void GetCompanyWithId() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options)); var user = new ApplicationUser() { Email = "test", Description = "test", Type = UserType.Employer, }; repository.AddAsync(user); repository.SaveChangesAsync().GetAwaiter().GetResult(); var companyService = new CompaniesService(repository); AutoMapperConfig.RegisterMappings(typeof(CompaniesServiceTests.MyTest).Assembly); var company = companyService.GetCompanyAsync <MyTest>(user.Id); Assert.Equal("test", company.Email); repository.Delete(user); repository.SaveChangesAsync().GetAwaiter().GetResult(); }
public void TestAllPositiveCompanies() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options)); var user = new ApplicationUser { Description = "test", Type = UserType.Employer, }; repository.AddAsync(user).GetAwaiter().GetResult(); repository.SaveChangesAsync().GetAwaiter().GetResult(); var company = new CompaniesService(repository); AutoMapperConfig.RegisterMappings(typeof(CompaniesServiceTests.MyTest).Assembly); var job = company.GetAll <CompaniesServiceTests.MyTest>(); Assert.Single(company.GetAll <CompaniesServiceTests.MyTest>()); repository.Delete(user); repository.SaveChangesAsync().GetAwaiter().GetResult(); }