Exemple #1
0
        public void Candidate_WhenAddedToAdvertisementWithInvalidId_ThrowsException()
        {
            var service = new AdvertisementCandidateService(context);

            var ex = Assert.Throws <ArgumentException>(() => service.AddCandidateToAdvertisement(2, this.candidate.Id));

            Assert.That(ex.Message, Is.EqualTo("Invalid advertisement id. (Parameter 'advertisementId')"));
        }
Exemple #2
0
        public void Candidate_CanBeAddedToAdvertisement()
        {
            var service = new AdvertisementCandidateService(context);

            service.AddCandidateToAdvertisement(this.advertisement.Id, this.candidate.Id);

            Assert.AreEqual(1, this.context.AdvertisementsCandidates.Count());
        }
Exemple #3
0
        public void CandidateWithoutRelationToAdvertisement_WhenRemoved_ThrowsException()
        {
            var service = new AdvertisementCandidateService(context);

            var ex = Assert.Throws <ArgumentException>(() => service.RemoveCandidateFromAdvertisement(this.advertisement.Id, this.candidate.Id));

            Assert.That(ex.Message, Is.EqualTo("Candidate does not have relation to advertisement (Parameter 'candidateId')"));
        }
Exemple #4
0
        public void CandidateWithInvalidId_WhenRemovedFromAdvertisement_ThrowsException()
        {
            var service = new AdvertisementCandidateService(context);

            var ex = Assert.Throws <ArgumentException>(() => service.RemoveCandidateFromAdvertisement(this.advertisement.Id, 2));

            Assert.That(ex.Message, Is.EqualTo("Invalid candidate id. (Parameter 'candidateId')"));
        }
Exemple #5
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD

        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var userName = User.Identity.Name;

            var advertisementCandidateService = new AdvertisementCandidateService(_context);
            var candidate = this._context.Candidates.FirstOrDefault(c => c.Email == Candidate.Email);

            if (candidate == null)
            {
                candidate = service.CreateCandidate(Candidate.FirstName, Candidate.LastName, Candidate.Email);
            }

            var advId = Convert.ToInt32(Request.Form["advId"]);

            advertisementCandidateService.AddCandidateToAdvertisement(advId, candidate.Id);

            return(RedirectToPage("/Index"));
        }
Exemple #6
0
        public void Candidate_CanBeRemovedFromAdvertisement()
        {
            var otherCandidate = new Candidate();
            var relation1      = new AdvertisementCandidate()
            {
                Advertisement = this.advertisement, Candidate = this.candidate
            };
            var relation2 = new AdvertisementCandidate()
            {
                Advertisement = this.advertisement, Candidate = otherCandidate
            };

            advertisement.Candidates.Add(relation1);
            advertisement.Candidates.Add(relation2);
            candidate.Advertisements.Add(relation1);
            otherCandidate.Advertisements.Add(relation2);
            this.context.SaveChanges();

            var service = new AdvertisementCandidateService(context);

            Assert.AreEqual(2, this.context.AdvertisementsCandidates.Count());
            service.RemoveCandidateFromAdvertisement(this.advertisement.Id, this.candidate.Id);
            Assert.AreEqual(1, this.context.AdvertisementsCandidates.Count());
        }