public async void Post_ApplicationDoesNotExist_CreatedResultWithJobApplication()
        {
            // Arrange
            var jobApplication = new JobApplication
            {
                CompanyName     = "Company 1",
                ApplicationDate = new DateTime(2017, 11, 13),
                Status          = Status.Interview
            };

            _jobApplicationService.AddNewApplication(jobApplication).Returns(jobApplication);

            // Act
            IActionResult result = await _jobApplicationsController.Post(jobApplication).ConfigureAwait(false);

            // Assert
            await _jobApplicationService.Received().AddNewApplication(jobApplication).ConfigureAwait(false);

            Assert.IsType <CreatedAtRouteResult>(result);
            var createdResult = (CreatedAtRouteResult)result;

            Assert.Equal(jobApplication, createdResult.Value);
        }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] JobApplication jobApplication)
        {
            try
            {
                JobApplication createdJobApplication = await _service.AddNewApplication(jobApplication).ConfigureAwait(false);

                return(CreatedAtRoute("GetJobApplication", new { companyName = createdJobApplication.CompanyName }, createdJobApplication));
            }
            catch (Exception e)
            {
                _logger.LogError(LoggingEvents.JobApplications,
                                 e,
                                 $"Exception when trying to create application for application with Name \"{jobApplication.CompanyName}\"");
                return(BadRequest(e));
            }
        }