From 2ae66eff622be1e1f21afbbdab1af9a449d13ab8 Mon Sep 17 00:00:00 2001 From: Spencer O'HEGARTY Date: Wed, 22 Jan 2025 18:13:29 +0000 Subject: [PATCH] Removed ContactChannelCreations object which encapsulated list of ContactChannelCreation types given the attribute was masked from the underlying reflection property values extractor. --- GetIntoTeachingApi/Models/Crm/Candidate.cs | 6 +- .../Models/Crm/ContactChannelCreations.cs | 65 ------------------- .../Crm/Validators/CandidateValidator.cs | 2 +- .../Services/CandidateUpserter.cs | 4 +- .../GetIntoTeachingCallbackTests.cs | 4 +- .../MailingListAddMemberTests.cs | 4 +- .../TeachingEventAddAttendeeTests.cs | 4 +- .../SchoolsExperienceSignUpTests.cs | 4 +- .../TeacherTrainingAdviserSignUpTests.cs | 18 ++--- .../Services/CandidateUpserterTests.cs | 2 +- 10 files changed, 24 insertions(+), 89 deletions(-) delete mode 100644 GetIntoTeachingApi/Models/Crm/ContactChannelCreations.cs diff --git a/GetIntoTeachingApi/Models/Crm/Candidate.cs b/GetIntoTeachingApi/Models/Crm/Candidate.cs index bba5ae82..1f62976b 100644 --- a/GetIntoTeachingApi/Models/Crm/Candidate.cs +++ b/GetIntoTeachingApi/Models/Crm/Candidate.cs @@ -298,7 +298,7 @@ public enum RegistrationStatus [EntityRelationship("dfe_contact_dfe_candidateschoolexperience_ContactId", typeof(CandidateSchoolExperience))] public List SchoolExperiences { get; set; } = new List(); [EntityRelationship("dfe_contact_dfe_contactchannelcreation_ContactId", typeof(ContactChannelCreation))] - public ContactChannelCreations ContactChannelCreations { get; set; } = new ContactChannelCreations(); + public List ContactChannelCreations { get; set; } = new List(); public Candidate() : base(){ } @@ -344,7 +344,7 @@ public void ConfigureChannel(ICreateContactChannel contactChannelCreator, Guid? { ChannelId = null; AddContactChannelCreation( - channelCreation: !ContactChannelCreations.HasExistingContactChannelCreations, + channelCreation: !ContactChannelCreations.Any(), contactChannelCreator: contactChannelCreator); } else @@ -378,7 +378,7 @@ public void ConfigureChannel(ICreateContactChannel contactChannelCreator, Guid? /// private void AddContactChannelCreation(bool channelCreation, ICreateContactChannel contactChannelCreator) { - ContactChannelCreations.AddContactChannelCreation( + ContactChannelCreations.Add( ContactChannelCreation.Create( creationChannel: channelCreation, sourceId: contactChannelCreator.CreationChannelSourceId, diff --git a/GetIntoTeachingApi/Models/Crm/ContactChannelCreations.cs b/GetIntoTeachingApi/Models/Crm/ContactChannelCreations.cs deleted file mode 100644 index fc273317..00000000 --- a/GetIntoTeachingApi/Models/Crm/ContactChannelCreations.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System; - -namespace GetIntoTeachingApi.Models.Crm -{ - /// - /// Provides the blueprint for an object which encapsulates a collection of - /// types defined by the - /// parent instance. - /// - public sealed class ContactChannelCreations - { - private readonly IList _contactChannelCreations; - - /// - /// Initialises a new collection of on instantiation. - /// - public ContactChannelCreations() - { - _contactChannelCreations = new List(); - } - - /// - /// Offers read-only access to the underlying - /// collection. - /// - /// - /// The read-only collection of configured types. - /// - public IReadOnlyCollection GetContactChannelCreations() => - new ReadOnlyCollection(_contactChannelCreations); - - /// - /// Allows a safe mechanism to add (mutate) the underlying - /// collection of types. - /// - /// type to add to the underlying collection. - /// > - /// - /// Exception type thrown if the is null. - /// - public void AddContactChannelCreation(ContactChannelCreation contactChannelCreation) - { - if (contactChannelCreation == null!) - { - throw new ArgumentNullException( - nameof(contactChannelCreation), - "The 'ContactChannelCreation' cannot be null."); - } - _contactChannelCreations.Add(contactChannelCreation); - } - - /// - /// Allows the current list of types to be reset. - /// - public void Reset() => _contactChannelCreations.Clear(); - - /// - /// Determines whether we have any existing ContactChannelCreations. - /// - public bool HasExistingContactChannelCreations => _contactChannelCreations.Count > 0; - } -} diff --git a/GetIntoTeachingApi/Models/Crm/Validators/CandidateValidator.cs b/GetIntoTeachingApi/Models/Crm/Validators/CandidateValidator.cs index e8db988f..8f2e3b7f 100644 --- a/GetIntoTeachingApi/Models/Crm/Validators/CandidateValidator.cs +++ b/GetIntoTeachingApi/Models/Crm/Validators/CandidateValidator.cs @@ -60,7 +60,7 @@ public CandidateValidator(IStore store, IDateTimeProvider dateTime) RuleFor(candidate => candidate.ChannelId) .NotNull() .When(candidate => candidate.Id == null) - .When(candidate => !candidate.ContactChannelCreations.HasExistingContactChannelCreations) + .When(candidate => !candidate.ContactChannelCreations.Any()) .SetValidator(new PickListItemIdValidator("contact", "dfe_channelcreation", store)); RuleFor(candidate => candidate.HasGcseEnglishId) .SetValidator(new PickListItemIdValidator("contact", "dfe_websitehasgcseenglish", store)) diff --git a/GetIntoTeachingApi/Services/CandidateUpserter.cs b/GetIntoTeachingApi/Services/CandidateUpserter.cs index cf1ea16a..7c2a18d7 100644 --- a/GetIntoTeachingApi/Services/CandidateUpserter.cs +++ b/GetIntoTeachingApi/Services/CandidateUpserter.cs @@ -96,8 +96,8 @@ private static IEnumerable ClearSchoolExperiences(Can private static IEnumerable ClearContactChannelCreations(Candidate candidate) { List contactChannelCreations = - new(candidate.ContactChannelCreations.GetContactChannelCreations()); - candidate.ContactChannelCreations.Reset(); + new(candidate.ContactChannelCreations); + candidate.ContactChannelCreations.Clear(); return contactChannelCreations; } diff --git a/GetIntoTeachingApiTests/Models/GetIntoTeaching/GetIntoTeachingCallbackTests.cs b/GetIntoTeachingApiTests/Models/GetIntoTeaching/GetIntoTeachingCallbackTests.cs index effa6fd0..e7bc7bca 100644 --- a/GetIntoTeachingApiTests/Models/GetIntoTeaching/GetIntoTeachingCallbackTests.cs +++ b/GetIntoTeachingApiTests/Models/GetIntoTeaching/GetIntoTeachingCallbackTests.cs @@ -66,7 +66,7 @@ public void ExistingCandidate_MapsCorrectly() candidate.PrivacyPolicy.AcceptedPolicyId.Should().Be((Guid)request.AcceptedPolicyId); candidate.PrivacyPolicy.AcceptedAt.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(30)); - var contactChannelCreation = candidate.ContactChannelCreations.GetContactChannelCreations().First(); + var contactChannelCreation = candidate.ContactChannelCreations.First(); contactChannelCreation.CreationChannel.Should().Be(false); contactChannelCreation.CreationChannelSourceId.Should().Be(request.CreationChannelSourceId); contactChannelCreation.CreationChannelServiceId.Should().Be(request.CreationChannelServiceId); @@ -85,7 +85,7 @@ public void NewCandidate_MapsCorrectly() CreationChannelActivityId = 222750001, }; - var contactChannelCreation = request.Candidate.ContactChannelCreations.GetContactChannelCreations().First(); + var contactChannelCreation = request.Candidate.ContactChannelCreations.First(); contactChannelCreation.CreationChannel.Should().Be(true); contactChannelCreation.CreationChannelSourceId.Should().Be(request.CreationChannelSourceId); contactChannelCreation.CreationChannelServiceId.Should().Be(request.CreationChannelServiceId); diff --git a/GetIntoTeachingApiTests/Models/GetIntoTeaching/MailingListAddMemberTests.cs b/GetIntoTeachingApiTests/Models/GetIntoTeaching/MailingListAddMemberTests.cs index dbbea6d7..1165c45b 100644 --- a/GetIntoTeachingApiTests/Models/GetIntoTeaching/MailingListAddMemberTests.cs +++ b/GetIntoTeachingApiTests/Models/GetIntoTeaching/MailingListAddMemberTests.cs @@ -116,7 +116,7 @@ public void ExistingCandidate_MapsCorrectly() candidate.Qualifications.First().TypeId.Should().Be((int)CandidateQualification.DegreeType.Degree); candidate.Qualifications.First().Id.Should().Be(request.QualificationId); - var contactChannelCreation = candidate.ContactChannelCreations.GetContactChannelCreations().First(); + var contactChannelCreation = candidate.ContactChannelCreations.First(); contactChannelCreation.CreationChannel.Should().Be(false); contactChannelCreation.CreationChannelSourceId.Should().Be(request.CreationChannelSourceId); contactChannelCreation.CreationChannelServiceId.Should().Be(request.CreationChannelServiceId); @@ -135,7 +135,7 @@ public void NewCandidate_MapsCreationChannelCorrectly() CreationChannelActivityId = 222750001, }; - var contactChannelCreation = request.Candidate.ContactChannelCreations.GetContactChannelCreations().First(); + var contactChannelCreation = request.Candidate.ContactChannelCreations.First(); contactChannelCreation.CreationChannel.Should().Be(true); contactChannelCreation.CreationChannelSourceId.Should().Be(request.CreationChannelSourceId); contactChannelCreation.CreationChannelServiceId.Should().Be(request.CreationChannelServiceId); diff --git a/GetIntoTeachingApiTests/Models/GetIntoTeaching/TeachingEventAddAttendeeTests.cs b/GetIntoTeachingApiTests/Models/GetIntoTeaching/TeachingEventAddAttendeeTests.cs index 4987c1c8..1a6943ef 100644 --- a/GetIntoTeachingApiTests/Models/GetIntoTeaching/TeachingEventAddAttendeeTests.cs +++ b/GetIntoTeachingApiTests/Models/GetIntoTeaching/TeachingEventAddAttendeeTests.cs @@ -125,7 +125,7 @@ public void ExistingCandidate_MapsCorrectly() candidate.Qualifications.First().TypeId.Should().Be((int)CandidateQualification.DegreeType.Degree); candidate.Qualifications.First().Id.Should().Be(request.QualificationId); - var contactChannelCreation = candidate.ContactChannelCreations.GetContactChannelCreations().First(); + var contactChannelCreation = candidate.ContactChannelCreations.First(); contactChannelCreation.CreationChannel.Should().Be(false); contactChannelCreation.CreationChannelSourceId.Should().Be(request.CreationChannelSourceId); contactChannelCreation.CreationChannelServiceId.Should().Be(request.CreationChannelServiceId); @@ -144,7 +144,7 @@ public void NewCandidate_MapsCorrectly() CreationChannelActivityId = 222750001, }; - var contactChannelCreation = request.Candidate.ContactChannelCreations.GetContactChannelCreations().First(); + var contactChannelCreation = request.Candidate.ContactChannelCreations.First(); contactChannelCreation.CreationChannel.Should().Be(true); contactChannelCreation.CreationChannelSourceId.Should().Be(request.CreationChannelSourceId); contactChannelCreation.CreationChannelServiceId.Should().Be(request.CreationChannelServiceId); diff --git a/GetIntoTeachingApiTests/Models/SchoolsExperience/SchoolsExperienceSignUpTests.cs b/GetIntoTeachingApiTests/Models/SchoolsExperience/SchoolsExperienceSignUpTests.cs index 9552dc7e..85fe1c1b 100644 --- a/GetIntoTeachingApiTests/Models/SchoolsExperience/SchoolsExperienceSignUpTests.cs +++ b/GetIntoTeachingApiTests/Models/SchoolsExperience/SchoolsExperienceSignUpTests.cs @@ -106,7 +106,7 @@ public void ExistingCandidate_MapsCorrectly() candidate.PrivacyPolicy.AcceptedPolicyId.Should().Be((Guid)request.AcceptedPolicyId); candidate.PrivacyPolicy.AcceptedAt.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(30)); - var contactChannelCreation = candidate.ContactChannelCreations.GetContactChannelCreations().First(); + var contactChannelCreation = candidate.ContactChannelCreations.First(); contactChannelCreation.CreationChannel.Should().Be(false); contactChannelCreation.CreationChannelSourceId.Should().Be(request.CreationChannelSourceId); contactChannelCreation.CreationChannelServiceId.Should().Be(request.CreationChannelServiceId); @@ -125,7 +125,7 @@ public void NewCandidate_MapsCorrectly() CreationChannelActivityId = 222750001, }; - var contactChannelCreation = request.Candidate.ContactChannelCreations.GetContactChannelCreations().First(); + var contactChannelCreation = request.Candidate.ContactChannelCreations.First(); contactChannelCreation.CreationChannel.Should().Be(true); contactChannelCreation.CreationChannelSourceId.Should().Be(request.CreationChannelSourceId); contactChannelCreation.CreationChannelServiceId.Should().Be(request.CreationChannelServiceId); diff --git a/GetIntoTeachingApiTests/Models/TeacherTrainingAdviser/TeacherTrainingAdviserSignUpTests.cs b/GetIntoTeachingApiTests/Models/TeacherTrainingAdviser/TeacherTrainingAdviserSignUpTests.cs index 05ad0963..4694417c 100644 --- a/GetIntoTeachingApiTests/Models/TeacherTrainingAdviser/TeacherTrainingAdviserSignUpTests.cs +++ b/GetIntoTeachingApiTests/Models/TeacherTrainingAdviser/TeacherTrainingAdviserSignUpTests.cs @@ -203,9 +203,9 @@ public void Candidate_MapsCorrectly() candidate.Qualifications.First().DegreeSubject.Should().Be(request.DegreeSubject); candidate.Qualifications.First().TypeId.Should().Be(request.DegreeTypeId); - candidate.ContactChannelCreations.GetContactChannelCreations().First().CreationChannelSourceId.Should().Be(request.CreationChannelSourceId); - candidate.ContactChannelCreations.GetContactChannelCreations().First().CreationChannelServiceId.Should().Be(request.CreationChannelServiceId); - candidate.ContactChannelCreations.GetContactChannelCreations().First().CreationChannelActivityId.Should().Be(request.CreationChannelActivityId); + candidate.ContactChannelCreations.First().CreationChannelSourceId.Should().Be(request.CreationChannelSourceId); + candidate.ContactChannelCreations.First().CreationChannelServiceId.Should().Be(request.CreationChannelServiceId); + candidate.ContactChannelCreations.First().CreationChannelActivityId.Should().Be(request.CreationChannelActivityId); candidate.HasTeacherTrainingAdviserSubscription.Should().BeTrue(); } @@ -301,9 +301,9 @@ public void Candidate_ContactChannelCreationWhenCandidateIdIsNull() request.Candidate.ChannelId.Should().BeNull(); request.Candidate.ChangedPropertyNames.Should().Contain("ContactChannelCreations"); - request.Candidate.ContactChannelCreations.GetContactChannelCreations().First().CreationChannelSourceId.Should().Be(222750000); - request.Candidate.ContactChannelCreations.GetContactChannelCreations().First().CreationChannelServiceId.Should().Be(222750001); - request.Candidate.ContactChannelCreations.GetContactChannelCreations().First().CreationChannelActivityId.Should().Be(222750002); + request.Candidate.ContactChannelCreations.First().CreationChannelSourceId.Should().Be(222750000); + request.Candidate.ContactChannelCreations.First().CreationChannelServiceId.Should().Be(222750001); + request.Candidate.ContactChannelCreations.First().CreationChannelActivityId.Should().Be(222750002); } [Fact] @@ -320,9 +320,9 @@ public void Candidate_ContactChannelCreationWhenCandidateIdIsNotNull() request.Candidate.ChannelId.Should().BeNull(); request.Candidate.ChangedPropertyNames.Should().NotContain("ChannelId"); request.Candidate.ChangedPropertyNames.Should().Contain("ContactChannelCreations"); - request.Candidate.ContactChannelCreations.GetContactChannelCreations().First().CreationChannelSourceId.Should().Be(222750000); - request.Candidate.ContactChannelCreations.GetContactChannelCreations().First().CreationChannelServiceId.Should().Be(222750001); - request.Candidate.ContactChannelCreations.GetContactChannelCreations().First().CreationChannelActivityId.Should().Be(222750002); + request.Candidate.ContactChannelCreations.First().CreationChannelSourceId.Should().Be(222750000); + request.Candidate.ContactChannelCreations.First().CreationChannelServiceId.Should().Be(222750001); + request.Candidate.ContactChannelCreations.First().CreationChannelActivityId.Should().Be(222750002); } [Fact] diff --git a/GetIntoTeachingApiTests/Services/CandidateUpserterTests.cs b/GetIntoTeachingApiTests/Services/CandidateUpserterTests.cs index f2a4822a..62183de1 100644 --- a/GetIntoTeachingApiTests/Services/CandidateUpserterTests.cs +++ b/GetIntoTeachingApiTests/Services/CandidateUpserterTests.cs @@ -275,7 +275,7 @@ public void Upsert_WithContactChannelCreation_SavesContactChannelCreations() CreationChannelSourceId = 222750002, }; - _candidate.ContactChannelCreations.AddContactChannelCreation(contactChannelCreation); + _candidate.ContactChannelCreations.Add(contactChannelCreation); _upserter.Upsert(_candidate);