Exemple #1
0
        public void JobSeekerServiceTests()
        {
            // Addition
            var unit             = new UnitOfWork(GetInMemoryOptions());
            var jobSeekerService = new JobSeekerService(unit);
            var s1 = new JobSeeker()
            {
                Name    = "Joey",
                Surname = "Tribbiani"
            };

            Assert.Null(s1.Id);
            jobSeekerService.RegisterJobSeeker(s1);
            unit.SaveChanges();
            Assert.NotEqual(-1, s1.Id);
            Assert.Equal("Joey", unit.JobSeekerRepository.GetById(s1.Id ?? -1).Name);

            Seeder.Seed(unit);

            var s2 = new JobSeeker()
            {
                Name = "Chandler"
            };

            Assert.Null(s2.Id);
            jobSeekerService.RegisterJobSeeker(s2);
            unit.SaveChanges();
            Assert.NotEqual(-1, s2.Id);
            Assert.Equal("Chandler", unit.JobSeekerRepository.GetById(s2.Id ?? -1).Name);


            // Getter
            Assert.Equal(unit.JobSeekerRepository.GetById(1).Name, jobSeekerService.GetJobSeeker(1).Result.Name);
            Assert.Equal(unit.JobSeekerRepository.GetById(3).Name, jobSeekerService.GetJobSeeker(3).Result.Name);
            Assert.Equal(unit.JobSeekerRepository.GetById(2).Name, jobSeekerService.GetJobSeeker(2).Result.Name);
            Assert.Equal(unit.JobSeekerRepository.GetById(2).Surname, jobSeekerService.GetJobSeeker(2).Result.Surname);
            Assert.Equal(unit.JobSeekerRepository.GetById(2).Email, jobSeekerService.GetJobSeeker(2).Result.Email);


            // Update
            s1.Name = "Rachel";
            jobSeekerService.UpdateJobSeeker(s1);
            unit.SaveChanges();
            Assert.Equal("Rachel", unit.JobSeekerRepository.GetById(s1.Id ?? -1).Name);
            Assert.Equal("Tribbiani", unit.JobSeekerRepository.GetById(s1.Id ?? -1).Surname);

            var seeker = unit.JobSeekerRepository.GetById(3);

            Assert.NotNull(seeker);
            var seekerName    = seeker.Name;
            var seekerSurname = seeker.Surname;

            seeker.Name = "Ross";
            jobSeekerService.UpdateJobSeeker(seeker);
            unit.SaveChanges();
            Assert.Equal("Ross", unit.JobSeekerRepository.GetById(seeker.Id ?? -1).Name);
            Assert.Equal(seekerSurname, unit.JobSeekerRepository.GetById(seeker.Id ?? -1).Surname);
        }
Exemple #2
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 #3
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 #4
0
        public void JobSeekerFacadeTest()
        {
            var unit = new UnitOfWork(GetInMemoryOptions());

            Seeder.Seed(unit);

            var userService      = new UserService(unit, new UserQueryObject(unit));
            var jobSeekerService = new JobSeekerService(unit);
            var jobSeekerFacade  = new JobSeekerFacade(unit, mapper, jobSeekerService, userService);

            var s = new JobSeekerDto()
            {
                Name = "Lol"
            };

            jobSeekerFacade.RegisterAsync(s).Wait();
            Assert.NotNull(s.Id);
            Assert.NotNull(jobSeekerService.GetJobSeeker(s.Id ?? -1).Result);
            s.Id   = null;
            s.Name = "new lol";
            // Null ID get
            var excp1 = Assert.Throws <AggregateException>(() =>
                                                           jobSeekerFacade.GetInfoAsync(s).Wait());

            Assert.Contains("JobSeekerDto.Id can't be null!", excp1.Message);

            // Null ID edit/update
            var excp2 = Assert.Throws <AggregateException>(() =>
                                                           jobSeekerFacade.EditInfoAsync(mapper.Map <JobSeekerDto>(s)).Wait());

            Assert.Contains("Attempted to update or delete an entity that does not exist in the store.",
                            excp2.Message);

            // Addition with conflicting ID
            // This invalidates the database
            var id1 = unit.JobSeekerRepository.GetById(1);

            Assert.NotNull(id1); // makes sure company with id 1 is already in database
            var excp = Assert.Throws <AggregateException>(() =>
                                                          jobSeekerFacade.RegisterAsync(new JobSeekerDto()
            {
                Id = 1
            }).Wait());

            Assert.Contains("The instance of entity type 'JobSeeker' cannot be tracked " +
                            "because another instance with the same key value for {'Id'} is already being tracked.",
                            excp.Message);

            unit.Dispose();
        }
 public async Task <JobSeekerDto> GetByIdAsync(int id)
 {
     return(mapper.Map <JobSeekerDto>(await jobSeekerService.GetJobSeeker(id)));
 }