diff --git a/.github/workflows/build-and-push-package.yml b/.github/workflows/build-and-push-package.yml index 6cef3b1c..71a81157 100644 --- a/.github/workflows/build-and-push-package.yml +++ b/.github/workflows/build-and-push-package.yml @@ -2,10 +2,8 @@ name: Build and Push NuGet Package on: push: - branches: - - release/* - paths: - - 'Dfe.PersonsApi.Client*/**' + tags: + - 'production-*' env: DOTNET_VERSION: '8.0.x' diff --git a/Dfe.Academies.Application/MappingProfiles/AcademyWithGovernanceProfile.cs b/Dfe.Academies.Application/MappingProfiles/AcademyWithGovernanceProfile.cs index 395c8071..6301f738 100644 --- a/Dfe.Academies.Application/MappingProfiles/AcademyWithGovernanceProfile.cs +++ b/Dfe.Academies.Application/MappingProfiles/AcademyWithGovernanceProfile.cs @@ -9,6 +9,8 @@ public AcademyWithGovernanceProfile() { CreateMap() .ForMember(dest => dest.Id, opt => opt.MapFrom(src => (int)src.EducationEstablishmentGovernance.SK)) + .ForMember(dest => dest.UKPRN, opt => opt.MapFrom(src => src.Establishment.UKPRN)) + .ForMember(dest => dest.URN, opt => opt.MapFrom(src => src.Establishment.URN)) .ForMember(dest => dest.FirstName, opt => opt.MapFrom(src => src.EducationEstablishmentGovernance.Forename1)) .ForMember(dest => dest.LastName, opt => opt.MapFrom(src => src.EducationEstablishmentGovernance.Surname)) .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.EducationEstablishmentGovernance.Email)) diff --git a/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/ConstituenciesControllerTests.cs b/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/ConstituenciesControllerTests.cs index cd831d36..65a45ff0 100644 --- a/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/ConstituenciesControllerTests.cs +++ b/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/ConstituenciesControllerTests.cs @@ -13,7 +13,7 @@ namespace Dfe.Academies.PersonsApi.Tests.Integration.Controllers public class ConstituenciesControllerTests { [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetMemberOfParliamentByConstituencyAsync_ShouldReturnMp_WhenConstituencyExists( CustomWebApplicationDbContextFactory factory, IConstituenciesClient constituenciesClient) @@ -38,7 +38,7 @@ await dbContext.Constituencies } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetMemberOfParliamentByConstituencyAsync_ShouldReturnNotFound_WhenConstituencyDoesNotExist( CustomWebApplicationDbContextFactory factory, IConstituenciesClient constituenciesClient) @@ -56,7 +56,7 @@ public async Task GetMemberOfParliamentByConstituencyAsync_ShouldReturnNotFound_ } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetMemberOfParliamentByConstituenciesAsync_ShouldReturnMps_WhenConstituenciesExists( CustomWebApplicationDbContextFactory factory, IConstituenciesClient constituenciesClient) @@ -82,7 +82,7 @@ await dbcontext.Constituencies.Where(x => x.ConstituencyName == "Test Constituen } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetMemberOfParliamentByConstituenciesAsync_ShouldReturnEmpty_WhenConstituenciesDontExists( CustomWebApplicationDbContextFactory factory, IConstituenciesClient constituenciesClient) @@ -100,7 +100,7 @@ public async Task GetMemberOfParliamentByConstituenciesAsync_ShouldReturnEmpty_W } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetMemberOfParliamentByConstituenciesAsync_ShouldThrowAnException_WhenConstituenciesNotProvided( CustomWebApplicationDbContextFactory factory, IConstituenciesClient constituenciesClient) diff --git a/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/EstablishmentsControllerTests.cs b/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/EstablishmentsControllerTests.cs index e71c0c89..ab6ddbe7 100644 --- a/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/EstablishmentsControllerTests.cs +++ b/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/EstablishmentsControllerTests.cs @@ -13,7 +13,7 @@ namespace Dfe.Academies.PersonsApi.Tests.Integration.Controllers public class EstablishmentsControllerTests { [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetAllPersonsAssociatedWithAcademyAsync_ShouldReturnPeople_WhenAcademyExists( CustomWebApplicationDbContextFactory factory, IEstablishmentsClient establishmentsClient) @@ -39,7 +39,7 @@ await dbContext.Establishments.Where(x => x.SK == 1) } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetAllPersonsAssociatedWithAcademyAsync_ShouldReturnEmptyList_WhenAcademyExistWithNoPeople( CustomWebApplicationDbContextFactory factory, IEstablishmentsClient establishmentsClient) @@ -61,7 +61,7 @@ await dbContext.Establishments.Where(x => x.SK == 2) } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetAllPersonsAssociatedWithAcademyAsync_ShouldThrowAnException_WhenAcademyDoesntExists( CustomWebApplicationDbContextFactory factory, IEstablishmentsClient establishmentsClient) @@ -77,7 +77,7 @@ public async Task GetAllPersonsAssociatedWithAcademyAsync_ShouldThrowAnException } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetGetMemberOfParliamentBySchoolUrnAsync_ShouldReturnMP_WhenSchoolExists( CustomWebApplicationDbContextFactory factory, IEstablishmentsClient establishmentsClient) @@ -106,7 +106,7 @@ await mopDbContext.Constituencies.Where(x => x.ConstituencyName == "Test Constit } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetGetMemberOfParliamentBySchoolUrnAsync_ShouldReturnNull_WhenSchoolDoesntExists( CustomWebApplicationDbContextFactory factory, IEstablishmentsClient establishmentsClient) diff --git a/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/TrustsControllerTests.cs b/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/TrustsControllerTests.cs index ef96ca2c..f563d284 100644 --- a/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/TrustsControllerTests.cs +++ b/Tests/Dfe.Academies.PersonsApi.Tests.Integration/Controllers/TrustsControllerTests.cs @@ -11,7 +11,7 @@ namespace Dfe.Academies.PersonsApi.Tests.Integration.Controllers public class TrustsControllerTests { [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetAllPersonsAssociatedWithTrustAsync_ShouldReturnPeople_WhenTrustExists( CustomWebApplicationDbContextFactory factory, ITrustsClient trustsClient) @@ -32,7 +32,7 @@ public async Task GetAllPersonsAssociatedWithTrustAsync_ShouldReturnPeople_WhenT } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetAllPersonsAssociatedWithTrustAsync_ShouldReturnEmptyList_WhenTrustExistWithNoPeople( CustomWebApplicationDbContextFactory factory, ITrustsClient trustsClient) @@ -49,7 +49,7 @@ public async Task GetAllPersonsAssociatedWithTrustAsync_ShouldReturnEmptyList_Wh } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetAllPersonsAssociatedWithTrustAsync_ShouldThrowAnException_WhenTrustDoesntExists( CustomWebApplicationDbContextFactory factory, ITrustsClient trustsClient) @@ -65,7 +65,7 @@ public async Task GetAllPersonsAssociatedWithTrustAsync_ShouldThrowAnException_W } [Theory] - [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] + [CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] public async Task GetAllPersonsAssociatedWithTrustAsync_ShouldThrowAnException_WhenInvalidIdProvided( CustomWebApplicationDbContextFactory factory, ITrustsClient trustsClient) diff --git a/Tests/Dfe.Academies.Tests.Common/Customizations/CustomWebApplicationDbContextFactoryCustomization.cs b/Tests/Dfe.Academies.Tests.Common/Customizations/CustomWebApplicationDbContextFactoryCustomization.cs index 94396f5d..bf166579 100644 --- a/Tests/Dfe.Academies.Tests.Common/Customizations/CustomWebApplicationDbContextFactoryCustomization.cs +++ b/Tests/Dfe.Academies.Tests.Common/Customizations/CustomWebApplicationDbContextFactoryCustomization.cs @@ -1,38 +1,34 @@ -using System.Security.Claims; -using AutoFixture; -using DfE.CoreLibs.Testing.Mocks.WebApplicationFactory; +using AutoFixture; +using Dfe.Academies.Infrastructure; +using Dfe.Academies.Tests.Common.Seeders; using Dfe.PersonsApi.Client; using Dfe.PersonsApi.Client.Contracts; using Dfe.PersonsApi.Client.Extensions; +using DfE.CoreLibs.Testing.Mocks.Authentication; +using DfE.CoreLibs.Testing.Mocks.WebApplicationFactory; +using Microsoft.AspNetCore.Authentication; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using DfE.CoreLibs.Testing.Mocks.Authentication; -using Microsoft.AspNetCore.Authentication; using System.Net.Http.Headers; -using Dfe.Academies.Domain.Constituencies; -using Dfe.Academies.Domain.Establishment; -using Dfe.Academies.Domain.Trust; -using Dfe.Academies.Domain.ValueObjects; -using Dfe.Academies.Infrastructure; -using TrustGovernance = Dfe.Academies.Domain.Trust.TrustGovernance; +using System.Security.Claims; +using PersonsApi; namespace Dfe.Academies.Tests.Common.Customizations { - public class CustomWebApplicationDbContextFactoryCustomization : ICustomization - where TProgram : class + public class CustomWebApplicationDbContextFactoryCustomization : ICustomization { public void Customize(IFixture fixture) { - fixture.Customize>(composer => composer.FromFactory(() => + fixture.Customize>(composer => composer.FromFactory(() => { - var factory = new CustomWebApplicationDbContextFactory() + var factory = new CustomWebApplicationDbContextFactory() { SeedData = new Dictionary> { - { typeof(MstrContext), context => MstrSeedData((MstrContext)context) }, - { typeof(MopContext), context => MopSeedData((MopContext)context) } + { typeof(MstrContext), context => MstrContextSeeder.Seed((MstrContext)context) }, + { typeof(MopContext), context => MopContextSeeder.Seed((MopContext)context) } }, ExternalServicesConfiguration = services => { @@ -79,210 +75,5 @@ public void Customize(IFixture fixture) return factory; })); } - - private static void MstrSeedData(MstrContext mstrContext) - { - - if (!mstrContext.Trusts.Any() && !mstrContext.Establishments.Any() && - !mstrContext.EducationEstablishmentTrusts.Any() && !mstrContext.GovernanceRoleTypes.Any() && - !mstrContext.EducationEstablishmentGovernances.Any()) - { - - // Populate Trust - var trust1 = new Trust - { - SK = 1, - Name = "Trust A", - TrustTypeId = mstrContext.TrustTypes.FirstOrDefault()?.SK, - GroupUID = "G1", - Modified = DateTime.UtcNow, - ModifiedBy = "System", - UKPRN = "12345678", - GroupID = "TR00024" - }; - var trust2 = new Trust - { - SK = 2, - Name = "Trust B", - TrustTypeId = mstrContext.TrustTypes.FirstOrDefault()?.SK, - GroupUID = "G2", - Modified = DateTime.UtcNow, - ModifiedBy = "System", - UKPRN = "87654321", - GroupID = "TR00025" - }; - mstrContext.Trusts.AddRange(trust1, trust2); - - // Populate Establishment - var establishment1 = new Establishment - { - SK = 1, - URN = 22, - EstablishmentName = "School A", - LocalAuthorityId = mstrContext.LocalAuthorities.FirstOrDefault()?.SK, - EstablishmentTypeId = mstrContext.EstablishmentTypes.FirstOrDefault()?.SK, - Latitude = 54.9784, - Longitude = -1.6174, - MainPhone = "01234567890", - Email = "schoolA@example.com", - Modified = DateTime.UtcNow, - ModifiedBy = "System", - ParliamentaryConstituency = "Test Constituency 1" - }; - var establishment2 = new Establishment - { - SK = 2, - URN = 33, - EstablishmentName = "School B", - LocalAuthorityId = mstrContext.LocalAuthorities.FirstOrDefault()?.SK, - EstablishmentTypeId = mstrContext.EstablishmentTypes.FirstOrDefault()?.SK, - Latitude = 50.3763, - Longitude = -4.1427, - MainPhone = "09876543210", - Email = "schoolB@example.com", - Modified = DateTime.UtcNow, - ModifiedBy = "System", - ParliamentaryConstituency = "Test Constituency 2" - }; - mstrContext.Establishments.AddRange(establishment1, establishment2); - - // Populate EducationEstablishmentTrust - var educationEstablishmentTrust1 = new EducationEstablishmentTrust - { - SK = 1, - EducationEstablishmentId = (int)establishment1.SK, - TrustId = (int)trust1.SK, - }; - var educationEstablishmentTrust2 = new EducationEstablishmentTrust - { - SK = 2, - EducationEstablishmentId = (int)establishment2.SK, - TrustId = (int)trust2.SK, - - }; - mstrContext.EducationEstablishmentTrusts.AddRange(educationEstablishmentTrust1, educationEstablishmentTrust2); - - // Populate GovernanceRoleType - var governanceRoleType1 = new GovernanceRoleType - { SK = 1, Name = "Chair of Governors", Modified = DateTime.UtcNow, ModifiedBy = "System" }; - var governanceRoleType2 = new GovernanceRoleType - { SK = 2, Name = "Vice Chair of Governors", Modified = DateTime.UtcNow, ModifiedBy = "System" }; - var governanceRoleType3 = new GovernanceRoleType - { SK = 3, Name = "Trustee", Modified = DateTime.UtcNow, ModifiedBy = "System" }; - mstrContext.GovernanceRoleTypes.AddRange(governanceRoleType1, governanceRoleType2, governanceRoleType3); - - // Populate EducationEstablishmentGovernance - var governance1 = new EducationEstablishmentGovernance - { - SK = 1, - EducationEstablishmentId = establishment1.SK, - GovernanceRoleTypeId = governanceRoleType1.SK, - GID = "GID1", - Title = "Mr.", - Forename1 = "John", - Surname = "Doe", - Email = "johndoe@example.com", - Modified = DateTime.UtcNow, - ModifiedBy = "System" - }; - var governance3 = new EducationEstablishmentGovernance - { - SK = 3, - EducationEstablishmentId = establishment1.SK, - GovernanceRoleTypeId = governanceRoleType2.SK, - GID = "GID2", - Title = "Ms.", - Forename1 = "Anna", - Surname = "Smith", - Email = "annasmith@example.com", - Modified = DateTime.UtcNow, - ModifiedBy = "System" - }; - mstrContext.EducationEstablishmentGovernances.AddRange(governance1, governance3); - - // Populate TrustGovernance - var trustGovernance1 = new TrustGovernance - { - SK = 1, - TrustId = trust2.SK, - GovernanceRoleTypeId = governanceRoleType3.SK, - GID = "GID1", - Title = "Mr.", - Forename1 = "John", - Surname = "Wood", - Email = "johnWood@example.com", - Modified = DateTime.UtcNow, - ModifiedBy = "System" - }; - var trustGovernance2 = new TrustGovernance - { - SK = 2, - TrustId = trust2.SK, - GovernanceRoleTypeId = governanceRoleType3.SK, - GID = "GID1", - Title = "Mr.", - Forename1 = "Joe", - Surname = "Wood", - Email = "joeWood@example.com", - Modified = DateTime.UtcNow, - ModifiedBy = "System" - }; - mstrContext.TrustGovernances.AddRange(trustGovernance1, trustGovernance2); - - // Save changes - mstrContext.SaveChanges(); - } - } - - private static void MopSeedData(MopContext mopContext) - { - - var memberContact1 = new MemberContactDetails( - new MemberId(1), - 1, - "test1@example.com", - null - ); - - var memberContact2 = new MemberContactDetails( - new MemberId(2), - 1, - "test2@example.com", - null - ); - - var constituency1 = new Constituency( - new ConstituencyId(1), - new MemberId(1), - "Test Constituency 1", - new NameDetails( - "Wood, John", - "John Wood", - "Mr. John Wood MP" - ), - DateTime.UtcNow, - null, - memberContact1 - ); - - var constituency2 = new Constituency( - new ConstituencyId(2), - new MemberId(2), - "Test Constituency 2", - new NameDetails( - "Wood, Joe", - "Joe Wood", - "Mr. Joe Wood MP" - ), - DateTime.UtcNow, - null, - memberContact2 - ); - - mopContext.Constituencies.Add(constituency1); - mopContext.Constituencies.Add(constituency2); - - mopContext.SaveChanges(); - } } } diff --git a/Tests/Dfe.Academies.Tests.Common/Dfe.Academies.Tests.Common.csproj b/Tests/Dfe.Academies.Tests.Common/Dfe.Academies.Tests.Common.csproj index 1ad273ce..d6bca8fb 100644 --- a/Tests/Dfe.Academies.Tests.Common/Dfe.Academies.Tests.Common.csproj +++ b/Tests/Dfe.Academies.Tests.Common/Dfe.Academies.Tests.Common.csproj @@ -20,7 +20,7 @@ - + diff --git a/Tests/Dfe.Academies.Tests.Common/Seeders/MopContextSeeder.cs b/Tests/Dfe.Academies.Tests.Common/Seeders/MopContextSeeder.cs new file mode 100644 index 00000000..270fad3a --- /dev/null +++ b/Tests/Dfe.Academies.Tests.Common/Seeders/MopContextSeeder.cs @@ -0,0 +1,60 @@ +using Dfe.Academies.Domain.Constituencies; +using Dfe.Academies.Domain.ValueObjects; +using Dfe.Academies.Infrastructure; + +namespace Dfe.Academies.Tests.Common.Seeders +{ + public class MopContextSeeder + { + public static void Seed(MopContext mopContext) + { + + var memberContact1 = new MemberContactDetails( + new MemberId(1), + 1, + "test1@example.com", + null + ); + + var memberContact2 = new MemberContactDetails( + new MemberId(2), + 1, + "test2@example.com", + null + ); + + var constituency1 = new Constituency( + new ConstituencyId(1), + new MemberId(1), + "Test Constituency 1", + new NameDetails( + "Wood, John", + "John Wood", + "Mr. John Wood MP" + ), + DateTime.UtcNow, + null, + memberContact1 + ); + + var constituency2 = new Constituency( + new ConstituencyId(2), + new MemberId(2), + "Test Constituency 2", + new NameDetails( + "Wood, Joe", + "Joe Wood", + "Mr. Joe Wood MP" + ), + DateTime.UtcNow, + null, + memberContact2 + ); + + mopContext.Constituencies.Add(constituency1); + mopContext.Constituencies.Add(constituency2); + + mopContext.SaveChanges(); + } + } +} diff --git a/Tests/Dfe.Academies.Tests.Common/Seeders/MstrContextSeeder.cs b/Tests/Dfe.Academies.Tests.Common/Seeders/MstrContextSeeder.cs new file mode 100644 index 00000000..b45fa74d --- /dev/null +++ b/Tests/Dfe.Academies.Tests.Common/Seeders/MstrContextSeeder.cs @@ -0,0 +1,162 @@ +using Dfe.Academies.Domain.Establishment; +using Dfe.Academies.Domain.Trust; +using Dfe.Academies.Infrastructure; + +namespace Dfe.Academies.Tests.Common.Seeders +{ + public class MstrContextSeeder + { + public static void Seed(MstrContext mstrContext) + { + if (!mstrContext.Trusts.Any() && !mstrContext.Establishments.Any() && + !mstrContext.EducationEstablishmentTrusts.Any() && !mstrContext.GovernanceRoleTypes.Any() && + !mstrContext.EducationEstablishmentGovernances.Any()) + { + + // Populate Trust + var trust1 = new Trust + { + SK = 1, + Name = "Trust A", + TrustTypeId = mstrContext.TrustTypes.FirstOrDefault()?.SK, + GroupUID = "G1", + Modified = DateTime.UtcNow, + ModifiedBy = "System", + UKPRN = "12345678", + GroupID = "TR00024" + }; + var trust2 = new Trust + { + SK = 2, + Name = "Trust B", + TrustTypeId = mstrContext.TrustTypes.FirstOrDefault()?.SK, + GroupUID = "G2", + Modified = DateTime.UtcNow, + ModifiedBy = "System", + UKPRN = "87654321", + GroupID = "TR00025" + }; + mstrContext.Trusts.AddRange(trust1, trust2); + + // Populate Establishment + var establishment1 = new Establishment + { + SK = 1, + URN = 22, + EstablishmentName = "School A", + LocalAuthorityId = mstrContext.LocalAuthorities.FirstOrDefault()?.SK, + EstablishmentTypeId = mstrContext.EstablishmentTypes.FirstOrDefault()?.SK, + Latitude = 54.9784, + Longitude = -1.6174, + MainPhone = "01234567890", + Email = "schoolA@example.com", + Modified = DateTime.UtcNow, + ModifiedBy = "System", + ParliamentaryConstituency = "Test Constituency 1" + }; + var establishment2 = new Establishment + { + SK = 2, + URN = 33, + EstablishmentName = "School B", + LocalAuthorityId = mstrContext.LocalAuthorities.FirstOrDefault()?.SK, + EstablishmentTypeId = mstrContext.EstablishmentTypes.FirstOrDefault()?.SK, + Latitude = 50.3763, + Longitude = -4.1427, + MainPhone = "09876543210", + Email = "schoolB@example.com", + Modified = DateTime.UtcNow, + ModifiedBy = "System", + ParliamentaryConstituency = "Test Constituency 2" + }; + mstrContext.Establishments.AddRange(establishment1, establishment2); + + // Populate EducationEstablishmentTrust + var educationEstablishmentTrust1 = new EducationEstablishmentTrust + { + SK = 1, + EducationEstablishmentId = (int)establishment1.SK, + TrustId = (int)trust1.SK, + }; + var educationEstablishmentTrust2 = new EducationEstablishmentTrust + { + SK = 2, + EducationEstablishmentId = (int)establishment2.SK, + TrustId = (int)trust2.SK, + + }; + mstrContext.EducationEstablishmentTrusts.AddRange(educationEstablishmentTrust1, educationEstablishmentTrust2); + + // Populate GovernanceRoleType + var governanceRoleType1 = new GovernanceRoleType + { SK = 1, Name = "Chair of Governors", Modified = DateTime.UtcNow, ModifiedBy = "System" }; + var governanceRoleType2 = new GovernanceRoleType + { SK = 2, Name = "Vice Chair of Governors", Modified = DateTime.UtcNow, ModifiedBy = "System" }; + var governanceRoleType3 = new GovernanceRoleType + { SK = 3, Name = "Trustee", Modified = DateTime.UtcNow, ModifiedBy = "System" }; + mstrContext.GovernanceRoleTypes.AddRange(governanceRoleType1, governanceRoleType2, governanceRoleType3); + + // Populate EducationEstablishmentGovernance + var governance1 = new EducationEstablishmentGovernance + { + SK = 1, + EducationEstablishmentId = establishment1.SK, + GovernanceRoleTypeId = governanceRoleType1.SK, + GID = "GID1", + Title = "Mr.", + Forename1 = "John", + Surname = "Doe", + Email = "johndoe@example.com", + Modified = DateTime.UtcNow, + ModifiedBy = "System" + }; + var governance3 = new EducationEstablishmentGovernance + { + SK = 3, + EducationEstablishmentId = establishment1.SK, + GovernanceRoleTypeId = governanceRoleType2.SK, + GID = "GID2", + Title = "Ms.", + Forename1 = "Anna", + Surname = "Smith", + Email = "annasmith@example.com", + Modified = DateTime.UtcNow, + ModifiedBy = "System" + }; + mstrContext.EducationEstablishmentGovernances.AddRange(governance1, governance3); + + // Populate TrustGovernance + var trustGovernance1 = new TrustGovernance + { + SK = 1, + TrustId = trust2.SK, + GovernanceRoleTypeId = governanceRoleType3.SK, + GID = "GID1", + Title = "Mr.", + Forename1 = "John", + Surname = "Wood", + Email = "johnWood@example.com", + Modified = DateTime.UtcNow, + ModifiedBy = "System" + }; + var trustGovernance2 = new TrustGovernance + { + SK = 2, + TrustId = trust2.SK, + GovernanceRoleTypeId = governanceRoleType3.SK, + GID = "GID1", + Title = "Mr.", + Forename1 = "Joe", + Surname = "Wood", + Email = "joeWood@example.com", + Modified = DateTime.UtcNow, + ModifiedBy = "System" + }; + mstrContext.TrustGovernances.AddRange(trustGovernance1, trustGovernance2); + + // Save changes + mstrContext.SaveChanges(); + } + } + } +}