Ejemplo n.º 1
0
        public void JobOfferServiceTests()
        {
            // Addition
            var unit            = new UnitOfWork(GetInMemoryOptions());
            var jobOfferService = new JobOfferService(unit, new JobOfferQueryObject(unit));
            var c1 = new JobOffer()
            {
                Name = "Lol"
            };

            Assert.Null(c1.Id);
            jobOfferService.CreateAsync(c1).Wait();
            unit.SaveChanges();
            Assert.NotEqual(-1, c1.Id);
            Assert.Equal("Lol", unit.JobOfferRepository.GetById(c1.Id ?? -1).Name);

            Seeder.Seed(unit);

            var c2 = new JobOffer()
            {
                Name = "New addition"
            };

            Assert.Null(c2.Id);
            jobOfferService.CreateAsync(c2).Wait();
            unit.SaveChanges();
            Assert.NotEqual(-1, c2.Id);
            Assert.Equal("New addition", unit.JobOfferRepository.GetById(c2.Id ?? -1).Name);

            // Getter
            Assert.Equal(unit.JobOfferRepository.GetById(1).Name, jobOfferService.GetByIdAsync(1).Result.Name);
            Assert.Equal(unit.JobOfferRepository.GetById(3).Name, jobOfferService.GetByIdAsync(3).Result.Name);
            Assert.Equal(unit.JobOfferRepository.GetById(2).Name, jobOfferService.GetByIdAsync(2).Result.Name);
            Assert.Equal(unit.JobOfferRepository.GetById(2).Description, jobOfferService.GetByIdAsync(2).Result.Description);
            Assert.Equal(unit.JobOfferRepository.GetById(2).CompanyId, jobOfferService.GetByIdAsync(2).Result.CompanyId);

            // Update
            c1.Name = "new Lol";
            jobOfferService.UpdateAsync(c1).Wait();
            unit.SaveChanges();
            Assert.Equal("new Lol", unit.JobOfferRepository.GetById(c1.Id ?? -1).Name);
            Assert.Equal("new Lol", unit.JobOfferQuery
                         .FilterByNameContains("Lol")
                         .ExecuteAsync()
                         .Result
                         .First()
                         .Name);


            var appleOffer = unit.JobOfferQuery.FilterByNameContains("Apple")
                             .OrderBy(o => o.Name)
                             .ExecuteAsync()
                             .Result
                             .First();

            Assert.NotNull(appleOffer);
            Assert.Equal("Software development at Apple", appleOffer.Name);
            appleOffer.Name = "Not Apple";
            jobOfferService.UpdateAsync(appleOffer).Wait();
            unit.SaveChanges();
            Assert.Equal("Not Apple", unit.JobOfferRepository.GetById(appleOffer.Id ?? -1).Name);
            Assert.Equal(new List <string>()
            {
                "Not Apple", "Well-paid position at Apple"
            }, unit.JobOfferQuery
                         .FilterByNameContains("Apple")
                         .OrderBy(o => o.Name)
                         .ExecuteAsync()
                         .Result
                         .Select(o => o.Name));

            // Delete
            int size = unit.JobOfferRepository.GetAll().Count();

            jobOfferService.DeleteAsync(c1.Id ?? -1).Wait();
            Assert.Equal(size - 1, unit.JobOfferRepository.GetAll().Count());
        }
Ejemplo n.º 2
0
        public async Task UpdateAsync(JobOfferDto jobOffer)
        {
            await jobOfferService.UpdateAsync(mapper.Map <JobOfferDto, JobOffer>(jobOffer));

            await unitOfWork.SaveChangesAsync();
        }