public virtual async Task SaveJobOfferAsync(JobOffer jobOfferToSave)
        {
            var recruiterExists = await _recruiterRepository.CheckEntityExistsAsync(jobOfferToSave.RecruiterId);

            if (!recruiterExists)
            {
                throw new InvalidOperationException(DomainErrorMessages.INVALID_RECRUITER);
            }

            var companyExists = await _companyRepository.CheckEntityExistsAsync(jobOfferToSave.CompanyId);

            if (!companyExists)
            {
                throw new InvalidOperationException(DomainErrorMessages.COMPANY_INVALID);
            }

            var jobOfferExists = await _jobOfferRepository.CheckEntityExistsAsync(jobOfferToSave.Id);

            if (jobOfferExists)
            {
                var jobOfferCreatedBySameRecruiter = await _jobOfferRepository.JobOfferBelongsToRecruiter(jobOfferToSave);

                if (!jobOfferCreatedBySameRecruiter)
                {
                    throw new InvalidOperationException(DomainErrorMessages.RECRUITER_WHO_SAVE_THE_JOBOFFER_SHOULD_BE_THE_SAME_THAN_CREATED_IT);
                }
            }

            await _jobOfferRepository.UpsertAsync(jobOfferToSave);
        }
Exemple #2
0
        public async Task AddClientAsync_OnlyAddsAClientToRecruiter_WhenCompanyAlreadyExists()
        {
            //Arrage

            var recruiter1 = new Recruiter()
            {
                FirstName    = "Patricia",
                LastName     = "Maidana",
                IdentityCard = "28123456"
            };

            var recruiter2 = new Recruiter()
            {
                FirstName    = "Carolina",
                LastName     = "Leanza",
                IdentityCard = "28987561"
            };

            await _recruiterService.CreateRecruiterAsync(recruiter1);

            await _recruiterService.CreateRecruiterAsync(recruiter2);

            var company      = new Company("Acme", "Software");
            var otherCompany = new Company("Mulesoft", "Software");

            await _recruiterService.AddClientAsync(company, recruiter1.Id);

            await _recruiterService.AddClientAsync(otherCompany, recruiter1.Id);

            //Act
            await _recruiterService.AddClientAsync(otherCompany, recruiter2.Id);

            recruiter1 = await _recruiterRepository.GetByIdAsync(recruiter1.Id);

            recruiter2 = await _recruiterRepository.GetByIdAsync(recruiter2.Id);

            //Assert
            Assert.IsTrue(await _companyRepository.CheckEntityExistsAsync(company.Id), "Company 1 was not recorded");
            Assert.IsTrue(await _companyRepository.CheckEntityExistsAsync(otherCompany.Id), "Company 2 was not recorded");
            Assert.AreEqual(2, recruiter1.ClientCompanies.Count(), "Recruiter1 does not have all the clientes linked");
            Assert.AreEqual(1, recruiter2.ClientCompanies.Count(), "Recruiter2 does not have all the clientes linked");
            Assert.AreEqual(otherCompany.Id, recruiter2.ClientCompanies.First(), "Recruiter2 does not have linked the existing company");
        }