Exemplo n.º 1
0
        public void JobOfferFacadeTest()
        {
            var unit = new UnitOfWork(GetInMemoryOptions());

            Seeder.Seed(unit);

            var jobOfferService = new JobOfferService(unit, new JobOfferQueryObject(unit));
            var jobOfferFacade  = new JobOfferFacade(unit, jobOfferService, mapper);

            var o = new JobOfferDto()
            {
                Name = "Lol"
            };

            jobOfferFacade.CreateAsync(o).Wait();
            var s = unit.JobOfferQuery.FilterByName("Lol").ExecuteAsync().Result.First();

            Assert.NotNull(s.Id);
            Assert.NotNull(jobOfferService.GetByIdAsync(s.Id ?? -1).Result);
            s.Id   = null;
            s.Name = "new lol";
            // Null ID get IMPOSSIBLE due to GetById accepting only int

            // Null ID edit/update
            var excp2 = Assert.Throws <AggregateException>(() =>
                                                           jobOfferFacade.UpdateAsync(mapper.Map <JobOfferDto>(s)).Wait());

            Assert.Contains("The property 'Id' on entity type 'JobOffer' is part of a key " +
                            "and so cannot be modified or marked as modified.",
                            excp2.Message);

            // Null ID delete
            excp2 = Assert.Throws <AggregateException>(() =>
                                                       jobOfferFacade.DeleteAsync(mapper.Map <JobOfferDto>(s)).Wait());
            Assert.Contains("JobOfferDto.Id can't be null!",
                            excp2.Message);

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

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

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

            unit.Dispose();
        }
Exemplo n.º 2
0
        public async Task <IActionResult> EditJobOffer(JobOfferDto jobOffer)
        {
            var user = await userFacade.GetByIdAsync(int.Parse(User.Identity.Name));

            if (ModelState.IsValid && jobOffer.CompanyId == user.CompanyId)
            {
                await jobOfferFacade.UpdateAsync(jobOffer);

                return(RedirectToAction(nameof(Index)));
            }

            throw new ArgumentException();
        }