Exemple #1
0
        public void MatchCandidate_WithExistingCandidateRequest_MatchesOnNewestCandidateWithEmail(
            string email,
            string firstName,
            string lastName,
            string expectedFirstName
            )
        {
            var request = new ExistingCandidateRequest {
                Email = email, FirstName = firstName, LastName = lastName
            };

            _mockService.Setup(mock => mock.CreateQuery("contact", _context)).Returns(MockCandidates());
            _mockService.Setup(mock => mock.LoadProperty(It.IsAny <Entity>(),
                                                         new Relationship("dfe_contact_dfe_candidatequalification_ContactId"), _context));
            _mockService.Setup(mock => mock.LoadProperty(It.IsAny <Entity>(),
                                                         new Relationship("dfe_contact_dfe_candidatepastteachingposition_ContactId"), _context));
            _mockService.Setup(mock => mock.LoadProperty(It.IsAny <Entity>(),
                                                         new Relationship("dfe_contact_dfe_servicesubscription_contact"), _context));
            _mockService.Setup(mock => mock.LoadProperty(It.IsAny <Entity>(),
                                                         new Relationship("msevtmgt_contact_msevtmgt_eventregistration_Contact"), _context));

            var result = _crm.MatchCandidate(request);

            result?.FirstName.Should().Be(expectedFirstName);
        }
        public IActionResult CreateAccessToken([FromBody, SwaggerRequestBody("Candidate access token request (must match an existing candidate).", Required = true)] ExistingCandidateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            if (_appSettings.IsCrmIntegrationPaused)
            {
                return(NotFound());
            }

            var candidate = _crm.MatchCandidate(request);

            if (candidate == null)
            {
                return(NotFound());
            }

            var token           = _accessTokenService.GenerateToken(request, (Guid)candidate.Id);
            var personalisation = new Dictionary <string, dynamic> {
                { "pin_code", token }
            };

            // We respond immediately/assume this will be successful.
            _notifyService.SendEmailAsync(request.Email, NotifyService.NewPinCodeEmailTemplateId, personalisation);

            return(NoContent());
        }
        public IActionResult ExchangeAccessTokenForAttendee(
            [FromRoute, SwaggerParameter("Access token (PIN code).", Required = true)] string accessToken,
            [FromBody, SwaggerRequestBody("Candidate access token request (must match an existing candidate).", Required = true)] ExistingCandidateRequest request)
        {
            var candidate = _crm.MatchCandidate(request);

            if (candidate == null || !_tokenService.IsValid(accessToken, request, (Guid)candidate.Id))
            {
                return(Unauthorized());
            }

            return(Ok(new TeachingEventAddAttendee(candidate)));
        }