public async Task <IActionResult> EditJobSeeker(JobSeekerDto jobSeeker)
        {
            if (ModelState.IsValid && jobSeeker.UserId == int.Parse(User.Identity.Name))
            {
                await jobSeekerFacade.EditInfoAsync(jobSeeker);

                return(RedirectToAction("Index", "Home"));
            }

            throw new ArgumentException();
        }
Example #2
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();
        }