public async Task GetAllAsync_WithValidData_WorksCorrectly()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var expectedResults = new[] { "Subject1", "Subject2", "Subject3" }
            .OrderBy(s => s)
            .ToArray();

            foreach (var model in expectedResults)
            {
                context.ContactMessages.Add(new ContactMessage()
                {
                    FullName = "TestFullName",
                    Email    = "*****@*****.**",
                    Subject  = model,
                    Message  = "MessageTest"
                });
            }

            await context.SaveChangesAsync();

            var contactMessagesService = new ContactMessagesService(new EfRepository <ContactMessage>(context),
                                                                    new EfRepository <User>(context));

            var actualResults = (await contactMessagesService.GetAllAsync())
                                .Select(s => s.Subject)
                                .OrderBy(s => s)
                                .ToArray();

            Assert.Equal(expectedResults, actualResults);
        }
        public async Task DeleteAsync_WithExistingMessage_ReturnsTrue()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new ContactMessage()
            {
                FullName = "TestFullName",
                Email    = "*****@*****.**",
                Subject  = "TestSubject",
                Message  = "MessageTest"
            };

            context.ContactMessages.Add(model);

            await context.SaveChangesAsync();

            var contactMessagesService = new ContactMessagesService(new EfRepository <ContactMessage>(context),
                                                                    new EfRepository <User>(context));

            var result = await contactMessagesService.DeleteAsync(model.Id);

            Assert.True(result);

            var dbModels = await context.ContactMessages.AnyAsync();

            Assert.False(dbModels);
        }
Exemple #3
0
        public async Task DeleteAsync_WithExistentResume_ReturnsTrue()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Resume()
            {
                JobSeeker = new JobSeeker()
                {
                    FirstName = "JobSeekerFirstName",
                    LastName  = "JobSeekerFirstName",
                    User      = new User()
                    {
                        UserName = "******"
                    }
                }
            };

            await context.AddAsync(model);

            context.SaveChanges();

            var resumeService = new ResumeService(new EfRepository <JobSeeker>(context),
                                                  new EfRepository <Resume>(context),
                                                  new EfRepository <User>(context));

            var result = await resumeService.DeleteAsync(model.Id);

            var dbModels = await context.Resumes.AnyAsync();

            Assert.True(result);

            Assert.False(dbModels);
        }
Exemple #4
0
        public async Task AddResume_ToUser_WithOne_ReturnsFalse()
        {
            string testUsername = "******";

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Resume()
            {
                JobSeeker = new JobSeeker()
                {
                    FirstName = "JobSeekerFirstName",
                    LastName  = "JobSeekerFirstName",
                    User      = new User()
                    {
                        UserName = "******"
                    }
                }
            };

            await context.AddAsync(model);

            context.SaveChanges();

            var resumeService = new ResumeService(new EfRepository <JobSeeker>(context),
                                                  new EfRepository <Resume>(context),
                                                  new EfRepository <User>(context));

            var result = await resumeService.AddResumeToJobSeeker(testUsername);

            Assert.False(result);
        }
 public UserToken Get(string pDeToken)
 {
     using (JobFinderDbContext context = new JobFinderDbContext())
     {
         return(context.UserTokens.FirstOrDefault(c => c.DeToken == pDeToken));
     }
 }
Exemple #6
0
 public Candidate Get(int pIdUser, int pIdJob)
 {
     using (JobFinderDbContext context = new JobFinderDbContext())
     {
         return(context.Candidates.FirstOrDefault(c => c.IdCustomer == pIdUser && c.IdJob == pIdJob));
     }
 }
Exemple #7
0
        public async Task GetByIdAsync_WorksCorrectly()
        {
            string expectedResult = "MajorTest";

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Education()
            {
                Major     = expectedResult,
                Institute = "InstituteTest",
                From      = 2000,
                To        = 2001,
                Resume    = new Resume()
            };

            await context.AddAsync(model);

            context.SaveChanges();

            var educationsService = new EducationsService(new EfRepository <Education>(context),
                                                          new EfRepository <Resume>(context));

            var result = await educationsService.GetByIdAsync(model.Id);

            Assert.Equal(expectedResult, result.Major);
        }
        public async Task GetAllByCategoriesAsyncWithData_WorksCorrectly()
        {
            var expectedResults = new[] { "Category1", "Category2", "Category3" }
            .OrderBy(c => c)
            .ToArray();

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            foreach (var model in expectedResults)
            {
                context.Categories.Add(new Category
                {
                    CategoryType = model
                });
            }

            context.SaveChanges();

            var categoriesService = new CategoryService(new EfRepository <Category>(context));

            var actualResults = (await categoriesService.GetAllAsync())
                                .Select(c => c.CategoryType)
                                .OrderBy(c => c)
                                .ToArray();

            Assert.Equal(expectedResults, actualResults);
        }
Exemple #9
0
        public async Task GetJobSeekerForUser_WithNonExistentUser_ReturnsNull()
        {
            var testUserName = Guid.NewGuid().ToString();

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new JobSeeker
            {
                FirstName = "TestFirstName",
                LastName  = "TestLastName",
                User      = new User
                {
                    UserName = testUserName
                }
            };

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var result = await jobSeekerService.GetJobSeeker(testUserName);

            Assert.Null(result);
        }
Exemple #10
0
        public async Task RemoveExistingEducation_ReturnsTrue()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Education()
            {
                Major     = "MajorTest",
                Institute = "InstituteTest",
                From      = 2000,
                To        = 2001,
            };

            await context.AddAsync(model);

            context.SaveChanges();

            var educationsService = new EducationsService(new EfRepository <Education>(context),
                                                          new EfRepository <Resume>(context));

            var result = await educationsService.RemoveEducationById(model.Id);

            Assert.True(result);

            var dbModels = await context.EducationsHistory.AnyAsync();

            Assert.False(dbModels);
        }
Exemple #11
0
        public async Task GetJobSeekerForUser_WithValidUser_WorksCorrectly()
        {
            string userName = "******";

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new JobSeeker
            {
                FirstName = "TestFirstName",
                LastName  = "TestLastName",
                User      = new User
                {
                    UserName = userName
                }
            };

            await context.JobSeekers.AddAsync(model);

            context.SaveChanges();

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var serviceModel = await jobSeekerService.GetJobSeeker(userName);

            var dbModel = await context.JobSeekers.SingleOrDefaultAsync();

            Assert.Equal(dbModel.Id, serviceModel.Id);
        }
Exemple #12
0
        public async Task GetAllJobSeekers_WithData_WorksCorrectly()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var expectedResults = new[] { "JobSeeker1", "JobSeeker2", "JobSeeker3" }
            .OrderBy(j => j)
            .ToArray();

            foreach (var model in expectedResults)
            {
                context.JobSeekers.Add(new JobSeeker()
                {
                    FirstName = model,
                    LastName  = model,
                    User      = new User
                    {
                        UserName = model
                    }
                });
            }

            await context.SaveChangesAsync();

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var actualResults = (await jobSeekerService.GetAllJobSeekers())
                                .Select(j => j.FirstName)
                                .OrderBy(j => j)
                                .ToArray();

            Assert.Equal(expectedResults, actualResults);
        }
Exemple #13
0
        public async Task GetAsync_WithNotExistingJobSeeker_ReturnsFalse()
        {
            string userName = "******";

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new JobSeeker
            {
                FirstName = "TestFirstName",
                LastName  = "TestLastName",
                User      = new User
                {
                    UserName = userName
                }
            };

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var result = await jobSeekerService.GetJobSeekerById(model.Id);

            Assert.Null(result);
        }
Exemple #14
0
        public async Task UpdateAsync_WithNonExistentJobSeeker_ReturnsFalse()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new JobSeeker
            {
                FirstName = "TestFirstName",
                LastName  = "TestLastName",
                User      = new User
                {
                    UserName = "******"
                }
            };

            var serviceModel = new JobSeekerServiceModel
            {
                Id = model.Id
            };

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var result = await jobSeekerService.UpdateAsync(serviceModel);

            Assert.False(result);
        }
        public async Task CreateAsync_WithValidModel_WorksCorrectly_WithUnsignedUser()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var serviceModel = new ContactMessageServiceModel
            {
                Subject  = "TestSubjectName",
                Message  = "TestMessage",
                FullName = "TestFullName",
                Email    = "*****@*****.**"
            };

            var contactMessagesService = new ContactMessagesService(new EfRepository <ContactMessage>(context),
                                                                    new EfRepository <User>(context));

            var result = await contactMessagesService.CreateAsync(serviceModel);

            Assert.True(result);

            var dbModel = context.ContactMessages.SingleOrDefault();

            Assert.NotNull(dbModel);
        }
Exemple #16
0
        public async Task CreateAsync_WithInValidModel_ReturnsFalse()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var user = new User
            {
                UserName = "******"
            };

            await context.Users.AddAsync(user);

            context.SaveChanges();

            var serviceModel = new CompanyServiceModel
            {
                User = new UserServiceModel
                {
                    UserName = user.UserName
                }
            };

            var companyService = new CompanyService(new EfRepository <User>(context),
                                                    new EfRepository <Company>(context));

            var result = await companyService.CreateAsync(serviceModel);

            Assert.False(result);

            var dbModels = await context.Companies.AnyAsync();

            Assert.False(dbModels);
        }
        public async Task RemoveExistingWorkExperience_ReturnsTrue()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new WorkExperience()
            {
                Position  = "PositionTest",
                Institute = "InstituteTest",
                From      = 2000,
                To        = 2001,
            };

            await context.AddAsync(model);

            context.SaveChanges();

            var workService = new WorkHistoryService(new EfRepository <Resume>(context),
                                                     new EfRepository <WorkExperience>(context));

            var result = await workService.RemoveWorkExperience(model.Id);

            Assert.True(result);

            var dbModels = await context.WorksHistory.AnyAsync();

            Assert.False(dbModels);
        }
Exemple #18
0
        public async Task GetAllCompanies_WithData_WorksCorrectly()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var expectedResults = new[] { "Company1", "Company2", "Company3" }
            .OrderBy(c => c)
            .ToArray();

            foreach (var model in expectedResults)
            {
                context.Companies.Add(new Company()
                {
                    CompanyName = model,
                    User        = new User()
                    {
                        UserName = model
                    }
                });
            }

            await context.SaveChangesAsync();

            var companyService = new CompanyService(new EfRepository <User>(context),
                                                    new EfRepository <Company>(context));

            var actualResults = (await companyService.GetAllCompanies())
                                .Select(c => c.CompanyName)
                                .OrderBy(c => c)
                                .ToArray();

            Assert.Equal(expectedResults, actualResults);
        }
Exemple #19
0
        public async Task UpdateAsync_WithNonExistentCompany_ReturnsFalse()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var company = new Company
            {
                CompanyName = "TestCompanyName123456",
                User        = new User()
                {
                    UserName = "******"
                }
            };

            var companyService = new CompanyService(new EfRepository <User>(context),
                                                    new EfRepository <Company>(context));

            var serviceModel = new CompanyServiceModel
            {
                Id = company.Id,
            };

            var result = await companyService.UpdateAsync(serviceModel);

            Assert.False(result);
        }
Exemple #20
0
        public async Task GetCompanyForUser_WithNonExistentUser_ReturnsNull()
        {
            var testUserName = Guid.NewGuid().ToString();

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var company = new Company
            {
                CompanyName = "CompanyName",
                User        = new User()
                {
                    UserName = "******"
                }
            };

            await context.Companies.AddAsync(company);

            context.SaveChanges();

            var companyService = new CompanyService(new EfRepository <User>(context),
                                                    new EfRepository <Company>(context));

            var result = await companyService.GetCompanyForUser(testUserName);

            Assert.Null(result);
        }
Exemple #21
0
        public async Task GetAsync_WithValidCompany_WorksCorrectly()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var company = new Company
            {
                CompanyName = "TestCompanyName123456",
                User        = new User()
                {
                    UserName = "******"
                }
            };

            await context.Companies.AddAsync(company);

            context.SaveChanges();

            var companyService = new CompanyService(new EfRepository <User>(context),
                                                    new EfRepository <Company>(context));

            var result = await companyService.GetAsync(company.Id);

            var dbModel = await context.Companies.SingleOrDefaultAsync();

            Assert.Equal(dbModel.Id, result.Id);
        }
        public async Task AddSkill_WithValidData_ToExistingResume_WorksCorrectly()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Resume()
            {
                JobSeeker = new JobSeeker()
                {
                    FirstName = "JobSeekerName1",
                    LastName  = "JobSeekerName2",
                    User      = new User()
                    {
                        UserName = "******"
                    }
                }
            };

            await context.AddAsync(model);

            context.SaveChanges();

            var serviceModel = new SkillServiceModel()
            {
                Name = "SkillName1"
            };

            var skillService = new SkillService(new EfRepository <Resume>(context),
                                                new EfRepository <Skill>(context));

            var result = await skillService.AddSkill(model.Id, serviceModel);

            Assert.True(result);
        }
        public async Task AddSkill_ToNonExistingResume_ReturnsFalse()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Resume()
            {
                JobSeeker = new JobSeeker()
                {
                    FirstName = "JobSeekerName1",
                    LastName  = "JobSeekerName2",
                    User      = new User()
                    {
                        UserName = "******"
                    }
                }
            };

            var serviceModel = new SkillServiceModel();

            var skillService = new SkillService(new EfRepository <Resume>(context),
                                                new EfRepository <Skill>(context));

            var result = await skillService.AddSkill(model.Id, serviceModel);

            Assert.False(result);
        }
        public async Task RemoveExistingSkill_ReturnsTrue()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Skill()
            {
                Name   = "Skill1",
                Resume = new Resume()
            };

            await context.AddAsync(model);

            context.SaveChanges();

            var skillService = new SkillService(new EfRepository <Resume>(context),
                                                new EfRepository <Skill>(context));

            var result = await skillService.RemoveSkill(model.Id);

            Assert.True(result);

            var dbModels = await context.Skills.AnyAsync();

            Assert.False(dbModels);
        }
        public async Task UpdateAsync_WithInvalidData_ReturnsTrue()
        {
            string expectedResult = "Skill1";

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Skill()
            {
                Name   = expectedResult,
                Resume = new Resume()
            };

            await context.AddAsync(model);

            context.SaveChanges();

            var serviceModel = new SkillServiceModel()
            {
                Id = model.Id,
            };

            var skillService = new SkillService(new EfRepository <Resume>(context),
                                                new EfRepository <Skill>(context));

            var result = await skillService.UpdateAsync(serviceModel);

            Assert.False(result);

            var actualResult = (await context.Skills.SingleAsync(s => s.Id == model.Id)).Name;

            Assert.Equal(expectedResult, actualResult);
        }
Exemple #26
0
        public async Task UpdateAsync_WithValidModel_WorksCorrectly()
        {
            // Arrange
            const string expectedResult = "TestJobTitle";

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Job()
            {
                Location    = "Test Location",
                Description = "Random description",
                EndDate     = DateTime.UtcNow,

                Company = new Company()
                {
                    CompanyName = "Test Company",
                    User        = new User()
                    {
                        UserName = "******"
                    },
                },
                Category = new Category()
                {
                    CategoryType = "NewCategory"
                },
                JobType = new JobType()
                {
                    Type = "NewType"
                }
            };

            await context.AddAsync(model);

            context.SaveChanges();

            var jobService = new JobService(new EfRepository <Company>(context),
                                            new EfRepository <Job>(context),
                                            new EfRepository <JobCandidate>(context),
                                            new EfRepository <User>(context),
                                            new EfRepository <JobSeeker>(context));

            var serviceModel = new JobServiceModel
            {
                Id          = model.Id,
                Title       = expectedResult,
                Location    = model.Location,
                Description = model.Description,
                EndDate     = model.EndDate
            };

            var result = await jobService.UpdateAsync(serviceModel);

            Assert.True(result);

            var actualResult = (await context.Jobs.SingleAsync(j => j.Id == model.Id)).Title;

            Assert.Equal(expectedResult, actualResult);
        }
Exemple #27
0
 public void SeedData()
 {
     using (Context = new JobFinderDbContext())
     {
         SeedRoles();
         SeedUsers();
     }
 }
 public void Update(T pObject)
 {
     using (JobFinderDbContext context = new JobFinderDbContext())
     {
         context.Entry(pObject).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void Delete(T pObject)
 {
     using (JobFinderDbContext context = new JobFinderDbContext())
     {
         context.Set <T>().Remove(pObject);
         context.SaveChanges();
     }
 }
 public void Add(T pObject)
 {
     using (JobFinderDbContext context = new JobFinderDbContext())
     {
         context.Set <T>().Add(pObject);
         context.SaveChanges();
     }
 }