Exemplo n.º 1
0
 public IActionResult PutJobAdvertisement(Guid id, Guid jobAddId, [FromBody] JobAdvertisementDTO jobAdvertisement)
 {
     try
     {
         _jobAddService.UpdateAdvertisement(id, jobAddId, jobAdvertisement);
         return(NoContent());
     }
     catch (Exception e)
     {
         return(_handler.HandleError(e));
     }
 }
        public void CreateAdvertisement_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var  service   = this.CreateService();
            Guid companyId = default(global::System.Guid);
            JobAdvertisementDTO advertisement = null;

            // Act
            //var result = service.CreateAdvertisement(
            //    companyId,
            //    advertisement);

            // Assert
            Assert.True(true);
            this.mockRepository.VerifyAll();
        }
Exemplo n.º 3
0
        public JobAdvertisementDTO CreateAdvertisement(Guid companyId, JobAdvertisementDTO advertisement)
        {
            var mapped  = _mapper.Map <JobAdvertisement>(advertisement);
            var company = _context.CompanyEntities.Find(companyId);

            if (company == null)
            {
                throw new KeyNotFoundException();
            }
            mapped.CompanyID = companyId;
            _context.JobAdvertisementEntities.Add(mapped);
            _context.SaveChanges();
            var response = advertisement;

            response.JobAdvertisementID = mapped.JobAdvertisementID;
            return(response);
        }
Exemplo n.º 4
0
        public void UpdateAdvertisement(Guid companyId, Guid id, JobAdvertisementDTO advertisement)
        {
            if (id != advertisement.JobAdvertisementID || companyId != advertisement.CompanyID)
            {
                throw new ArgumentException();
            }

            var mapped            = _mapper.Map <JobAdvertisement>(advertisement);
            var advertisementInDb = _context.JobAdvertisementEntities.Where(item => item.CompanyID == companyId && item.JobAdvertisementID == id).First();

            if (advertisementInDb == null)
            {
                throw new KeyNotFoundException();
            }
            else
            {
                _context.Entry(advertisementInDb).CurrentValues.SetValues(mapped);
                _context.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public void PostJobAdvertisement_Default_ShouldReturnCreatedJobAdd(JobAdvertisementDTO newJobAdd)
        {
            // Arrange
            var companiesController = this.CreateCompaniesController();

            MockJobAdvertisementService(new List <JobAdvertisementDTO> {
                new JobAdvertisementDTO()
            });
            JobAdvertisementDTO jobAdd = newJobAdd;
            Guid id = new Guid(newJobAdd.CompanyID.ToString());

            // Act
            var result = companiesController.PostJobAdvertisement(id,
                                                                  jobAdd) as CreatedAtActionResult;

            // Assert
            Assert.Equal(201, result.StatusCode);
            Assert.Equal(jobAdd, result.Value);
            mockJobAdvertisementService.Verify(m => m.CreateAdvertisement(id, jobAdd));
        }
Exemplo n.º 6
0
        public void PutJobAdvertisement_Default_ShouldCallServiceToUpdate(JobAdvertisementDTO expected)
        {
            // Arrange
            MockJobAdvertisementService(new List <JobAdvertisementDTO> {
                expected
            });
            var  companiesController = this.CreateCompaniesController();
            Guid id       = new Guid(expected.CompanyID.ToString());
            Guid jobAddId = new Guid(expected.JobAdvertisementID.ToString());
            JobAdvertisementDTO jobAdvertisement = expected;

            // Act
            var result = companiesController.PutJobAdvertisement(
                id,
                jobAddId, jobAdvertisement) as NoContentResult;

            // Assert
            Assert.Equal(204, result.StatusCode);
            mockJobAdvertisementService.Verify(m => m.UpdateAdvertisement(id, jobAddId, jobAdvertisement));
        }
Exemplo n.º 7
0
        public void GetJobAdvertisement_Default_ShouldReturnJobAdd(JobAdvertisementDTO expected)
        {
            // Arrange
            MockJobAdvertisementService(new List <JobAdvertisementDTO> {
                expected
            });
            var companiesController = this.CreateCompaniesController();
            var companyId           = new Guid(expected.CompanyID.ToString());
            var id = new Guid(expected.JobAdvertisementID.ToString());

            // Act
            var result      = companiesController.GetJobAdvertisement(companyId, id) as OkObjectResult;
            var resultValue = result.Value as JobAdvertisementDTO;

            // Assert
            Assert.Equal(200, result.StatusCode);
            Assert.Equal(expected, resultValue);
            Assert.Equal(companyId, resultValue.CompanyID);
            mockJobAdvertisementService.Verify(m => m.GetAdvertisementByCompany(companyId, id));
        }