コード例 #1
0
        public void Validate_WhenValid_HasNoErrors()
        {
            var mockPickListItem = new PickListItem {
                Id = 123
            };
            var mockLookupItem = new LookupItem {
                Id = Guid.NewGuid()
            };
            var mockPrivacyPolicy = new PrivacyPolicy {
                Id = Guid.NewGuid()
            };

            var request = new MailingListAddMember()
            {
                CandidateId = null,
                PreferredTeachingSubjectId  = mockLookupItem.Id,
                AcceptedPolicyId            = (Guid)mockPrivacyPolicy.Id,
                ConsiderationJourneyStageId = mockPickListItem.Id,
                DegreeStatusId  = mockPickListItem.Id,
                Email           = "*****@*****.**",
                FirstName       = "John",
                LastName        = "Doe",
                AddressPostcode = "KY11 9YU",
            };

            var result = _validator.TestValidate(request);

            // Ensure no validation errors on root object (we expect errors on the Candidate
            // properties as we can't mock them).
            var propertiesWithErrors = result.Errors.Select(e => e.PropertyName);

            propertiesWithErrors.All(p => p.StartsWith("Candidate.")).Should().BeTrue();
        }
        public void Candidate_AddressPostcode_IsFormatted()
        {
            var request = new MailingListAddMember()
            {
                AddressPostcode = "ky119yu"
            };

            request.Candidate.AddressPostcode.Should().Be("KY11 9YU");
        }
        public void Candidate_AddressPostcodeNotProvided_EventsSubscriptionIsNotCreated()
        {
            var request = new MailingListAddMember()
            {
                AddressPostcode = null,
            };

            request.Candidate.HasEventsSubscription.Should().BeNull();
        }
        public void Candidate_ChannelIdWhenCandidateIdIsNull_IsMailingList()
        {
            var request = new MailingListAddMember()
            {
                CandidateId = null
            };

            request.Candidate.ChannelId.Should().Be((int)Candidate.Channel.MailingList);
        }
        public void Candidate_ChannelIdWhenCandidateIdIsNotNull_IsNotChanged()
        {
            var request = new MailingListAddMember()
            {
                CandidateId = Guid.NewGuid()
            };

            request.Candidate.ChannelId.Should().BeNull();
            request.Candidate.ChangedPropertyNames.Should().NotContain("ChannelId");
        }
コード例 #6
0
        public void Validate_CandidateIsInvalid_HasError()
        {
            var request = new MailingListAddMember
            {
                PreferredTeachingSubjectId = Guid.NewGuid(),
            };

            var result = _validator.TestValidate(request);

            result.ShouldHaveValidationErrorFor("Candidate.PreferredTeachingSubjectId");
        }
        public void Candidate_WhenChannelIsProvided_SetsOnAllModels()
        {
            var request = new MailingListAddMember()
            {
                ChannelId = 123, AddressPostcode = "TE7 8KE"
            };

            request.Candidate.ChannelId.Should().Be(123);
            request.Candidate.MailingListSubscriptionChannelId.Should().Be(123);
            request.Candidate.EventsSubscriptionChannelId.Should().Be(123);
        }
        public void Constructor_WithCandidate_MapsCorrectly()
        {
            var latestQualification = new CandidateQualification()
            {
                Id              = Guid.NewGuid(),
                CreatedAt       = DateTime.UtcNow.AddDays(10),
                UkDegreeGradeId = 1,
            };

            var qualifications = new List <CandidateQualification>()
            {
                new CandidateQualification()
                {
                    Id = Guid.NewGuid(), CreatedAt = DateTime.UtcNow.AddDays(3)
                },
                latestQualification,
                new CandidateQualification()
                {
                    Id = Guid.NewGuid(), CreatedAt = DateTime.UtcNow.AddDays(5)
                },
            };

            var candidate = new Candidate()
            {
                Id = Guid.NewGuid(),
                PreferredTeachingSubjectId  = Guid.NewGuid(),
                ConsiderationJourneyStageId = 1,
                Email                 = "*****@*****.**",
                FirstName             = "John",
                LastName              = "Doe",
                AddressPostcode       = "KY11 9YU",
                Qualifications        = qualifications,
                HasEventsSubscription = true,
                HasTeacherTrainingAdviserSubscription = true,
            };

            var response = new MailingListAddMember(candidate);

            response.CandidateId.Should().Be(candidate.Id);
            response.PreferredTeachingSubjectId.Should().Be(candidate.PreferredTeachingSubjectId);
            response.ConsiderationJourneyStageId.Should().Be(candidate.ConsiderationJourneyStageId);
            response.Email.Should().Be(candidate.Email);
            response.FirstName.Should().Be(candidate.FirstName);
            response.LastName.Should().Be(candidate.LastName);
            response.AddressPostcode.Should().Be(candidate.AddressPostcode);

            response.QualificationId.Should().Be(latestQualification.Id);
            response.DegreeStatusId.Should().Be(latestQualification.DegreeStatusId);

            response.AlreadySubscribedToEvents.Should().BeTrue();
            response.AlreadySubscribedToMailingList.Should().BeFalse();
            response.AlreadySubscribedToTeacherTrainingAdviser.Should().BeTrue();
        }
コード例 #9
0
        public IActionResult AddMember(
            [FromBody, SwaggerRequestBody("Member to add to the mailing list.", Required = true)] MailingListAddMember request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            string json = request.Candidate.SerializeChangeTracked();

            _jobClient.Enqueue <UpsertCandidateJob>((x) => x.Run(json, null));

            return(NoContent());
        }
コード例 #10
0
        public void AddMember_ValidRequest_EnqueuesJobRespondsWithNoContent()
        {
            var request = new MailingListAddMember()
            {
                Email = "*****@*****.**", FirstName = "John", LastName = "Doe"
            };

            var response = _controller.AddMember(request);

            response.Should().BeOfType <NoContentResult>();
            _mockJobClient.Verify(x => x.Create(
                                      It.Is <Job>(job => job.Type == typeof(UpsertCandidateJob) && job.Method.Name == "Run" &&
                                                  IsMatch(request.Candidate, (string)job.Args[0])),
                                      It.IsAny <EnqueuedState>()));
        }
コード例 #11
0
        public void AddMember_InvalidRequest_RespondsWithValidationErrors()
        {
            var request = new MailingListAddMember()
            {
                FirstName = null
            };

            _controller.ModelState.AddModelError("FirstName", "First name must be specified.");

            var response = _controller.AddMember(request);

            var badRequest = response.Should().BeOfType <BadRequestObjectResult>().Subject;
            var errors     = badRequest.Value.Should().BeOfType <SerializableError>().Subject;

            errors.Should().ContainKey("FirstName").WhichValue.Should().BeOfType <string[]>().Which.Should().Contain("First name must be specified.");
        }
コード例 #12
0
        public IActionResult AddMember(
            [FromBody, SwaggerRequestBody("Member to add to the mailing list.", Required = true)] MailingListAddMember request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            // This is the only way we can mock/freeze the current date/time
            // in contract tests (there's no other way to inject it into this class).
            request.DateTimeProvider = _dateTime;
            string json = request.Candidate.SerializeChangeTracked();

            _jobClient.Enqueue <UpsertCandidateJob>((x) => x.Run(json, null));

            return(NoContent());
        }
        public void Candidate_MapsCorrectly()
        {
            var request = new MailingListAddMember()
            {
                CandidateId                 = Guid.NewGuid(),
                QualificationId             = Guid.NewGuid(),
                PreferredTeachingSubjectId  = Guid.NewGuid(),
                AcceptedPolicyId            = Guid.NewGuid(),
                ConsiderationJourneyStageId = 1,
                DegreeStatusId              = 2,
                Email           = "*****@*****.**",
                FirstName       = "John",
                LastName        = "Doe",
                AddressPostcode = "KY11 9YU",
            };

            var candidate = request.Candidate;

            candidate.Id.Should().Equals(request.CandidateId);
            candidate.ConsiderationJourneyStageId.Should().Be(request.ConsiderationJourneyStageId);
            candidate.PreferredTeachingSubjectId.Should().Be(request.PreferredTeachingSubjectId);

            candidate.Email.Should().Be(request.Email);
            candidate.FirstName.Should().Be(request.FirstName);
            candidate.LastName.Should().Be(request.LastName);
            candidate.AddressPostcode.Should().Be(request.AddressPostcode);
            candidate.ChannelId.Should().BeNull();
            candidate.OptOutOfSms.Should().BeFalse();
            candidate.DoNotBulkEmail.Should().BeFalse();
            candidate.DoNotEmail.Should().BeFalse();
            candidate.DoNotBulkPostalMail.Should().BeTrue();
            candidate.DoNotPostalMail.Should().BeTrue();
            candidate.DoNotSendMm.Should().BeFalse();
            candidate.EligibilityRulesPassed.Should().Be("false");

            candidate.PrivacyPolicy.AcceptedPolicyId.Should().Be((Guid)request.AcceptedPolicyId);
            candidate.PrivacyPolicy.AcceptedAt.Should().BeCloseTo(DateTime.UtcNow);

            candidate.HasMailingListSubscription.Should().BeTrue();
            candidate.HasEventsSubscription.Should().BeTrue();

            candidate.Qualifications.First().DegreeStatusId.Should().Be(request.DegreeStatusId);
            candidate.Qualifications.First().TypeId.Should().Be((int)CandidateQualification.DegreeType.Degree);
            candidate.Qualifications.First().Id.Should().Be(request.QualificationId);
        }