Ejemplo n.º 1
0
        public void Run(string json, PerformContext context)
        {
            _logger.LogInformation($"UpsertCandidateJob - Started ({AttemptInfo(context, _contextAdapter)})");
            _logger.LogInformation($"UpsertCandidateJob - Payload {Redactor.RedactJson(json)}");

            var candidate = json.DeserializeChangeTracked <Candidate>();

            if (IsLastAttempt(context, _contextAdapter))
            {
                var personalisation = new Dictionary <string, dynamic>();

                // We fire and forget the email, ensuring the job succeeds.
                _notifyService.SendEmailAsync(
                    candidate.Email,
                    NotifyService.CandidateRegistrationFailedEmailTemplateId,
                    personalisation);
                _logger.LogInformation("UpsertCandidateJob - Deleted");
            }
            else
            {
                var registrations = ClearTeachingEventRegistrations(candidate);
                var phoneCall     = ClearPhoneCall(candidate);
                SaveCandidate(candidate);
                SaveTeachingEventRegistrations(registrations, candidate);
                SavePhoneCall(phoneCall, candidate);
                IncrementCallbackBookingQuotaNumberOfBookings(phoneCall);

                _logger.LogInformation($"UpsertCandidateJob - Succeeded - {candidate.Id}");
            }

            var duration = (DateTime.UtcNow - _contextAdapter.GetJobCreatedAt(context)).TotalSeconds;

            _metrics.HangfireJobQueueDuration.WithLabels(new[] { "UpsertCandidateJob" }).Observe(duration);
        }
        public void RedactJson_WithInvalidJson_ReturnsEmpty()
        {
            var invalidJson = "my password is 123456";

            var result = Redactor.RedactJson(invalidJson);

            result.Should().Be(string.Empty);
        }
Ejemplo n.º 3
0
        private void LogInformation(string identifier, string payload, HttpContext context)
        {
            var info = new
            {
                context.Request.Scheme,
                context.Request.Host,
                context.Request.Path,
                context.Request.QueryString,
                Payload = Redactor.RedactJson(payload),
            };

            _logger.LogInformation($"{identifier}: {info}");
        }
        public void Run_OnSuccess_SavesCandidate()
        {
            _mockContext.Setup(m => m.GetRetryCount(null)).Returns(0);

            var json = _candidate.SerializeChangeTracked();

            _job.Run(json, null);

            _mockCrm.Verify(mock => mock.Save(It.Is <Candidate>(c => IsMatch(_candidate, c))), Times.Once);
            _mockLogger.VerifyInformationWasCalled("UpsertCandidateJob - Started (1/24)");
            _mockLogger.VerifyInformationWasCalled($"UpsertCandidateJob - Payload {Redactor.RedactJson(json)}");
            _mockLogger.VerifyInformationWasCalled($"UpsertCandidateJob - Succeeded - {_candidate.Id}");
            _metrics.HangfireJobQueueDuration.WithLabels(new[] { "UpsertCandidateJob" }).Count.Should().Be(1);
        }
        public void RedactJson_WithValidJson_RedactsSensitiveData()
        {
            string json = JsonSerializer.Serialize(
                new
            {
                password  = "******",
                firstName = "Ross",
                nested    = new
                {
                    addressLine1 = "6 main street",
                    password     = "******",
                },
                email           = new string[] { "first", "second" },
                addressPostcode = "TE7 1NG",
            }
                );

            string redactedJson = JsonSerializer.Serialize(
                new
            {
                password  = "******",
                firstName = "******",
                nested    = new
                {
                    addressLine1 = "******",
                    password     = "******",
                },
                email           = "******",
                addressPostcode = "TE7 1NG",
            }
                );

            var result = Redactor.RedactJson(json);

            result.Should().Be(redactedJson);
        }