From f3139000c4386a83935e20b15510ed70359add98 Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Sun, 2 Jun 2024 09:57:47 +0100 Subject: [PATCH 01/11] git commit -m "CFODEV-469 (CFODEV-470 and CFODEV-473) create domain test" --- cats.sln | 7 ++++ .../AddEdit/AddEditKeyValueCommandHandler.cs | 4 +- .../Delete/DeleteKeyValueCommandHandler.cs | 2 +- .../Import/ImportKeyValuesCommandHandler.cs | 7 +++- src/Domain/Common/Events/CreatedEvent.cs | 2 +- src/Domain/Common/Events/DeletedEvent.cs | 9 +---- src/Domain/Common/Events/UpdatedEvent.cs | 9 +---- src/Domain/Entities/KeyValue.cs | 8 ++++ src/Domain/Events/ContractCreatedEvent.cs | 2 +- src/Domain/Events/LocationEvents.cs | 2 +- src/Domain/Events/ParticipantCreatedEvent.cs | 4 +- src/Domain/Events/TenantCreatedEvent.cs | 2 +- .../Domain.ArchitectureTests.csproj | 29 ++++++++++++++ test/Domain.ArchitectureTests/EntityTests.cs | 38 +++++++++++++++++++ 14 files changed, 100 insertions(+), 25 deletions(-) create mode 100644 test/Domain.ArchitectureTests/Domain.ArchitectureTests.csproj create mode 100644 test/Domain.ArchitectureTests/EntityTests.cs diff --git a/cats.sln b/cats.sln index 0c22543d..56317b58 100644 --- a/cats.sln +++ b/cats.sln @@ -37,6 +37,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{62ABFE2F-D EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application.UnitTests", "test\Application.UnitTests\Application.UnitTests.csproj", "{2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain.ArchitectureTests", "test\Domain.ArchitectureTests\Domain.ArchitectureTests.csproj", "{386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -79,6 +81,10 @@ Global {2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E}.Debug|Any CPU.Build.0 = Debug|Any CPU {2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E}.Release|Any CPU.ActiveCfg = Release|Any CPU {2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E}.Release|Any CPU.Build.0 = Release|Any CPU + {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -93,6 +99,7 @@ Global {7721D89A-D919-41A8-8B5B-8D5BF862B3F7} = {28581377-5421-47F6-A678-9510117A7791} {50485EFF-8E12-4F8A-A087-A9882D2C31C7} = {28581377-5421-47F6-A678-9510117A7791} {2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E} = {62ABFE2F-D4F3-4E44-AA07-20D679B04CF3} + {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6} = {62ABFE2F-D4F3-4E44-AA07-20D679B04CF3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {916B96E7-FFB9-4D43-A9BD-88CB137B2783} diff --git a/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommandHandler.cs b/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommandHandler.cs index df1a56e4..a60782f7 100644 --- a/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommandHandler.cs +++ b/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommandHandler.cs @@ -21,14 +21,14 @@ public async Task> Handle(AddEditKeyValueCommand request, Cancellati var keyValue = await _context.KeyValues.FindAsync(new object[] { request.Id }, cancellationToken); _ = keyValue ?? throw new NotFoundException($"KeyValue Pair {request.Id} Not Found."); keyValue = _mapper.Map(request, keyValue); - keyValue.AddDomainEvent(new UpdatedEvent(keyValue)); + keyValue.AddDomainEvent(new KeyValueUpdatedEvent(keyValue)); await _context.SaveChangesAsync(cancellationToken); return await Result.SuccessAsync(keyValue.Id); } else { var keyValue = _mapper.Map(request); - keyValue.AddDomainEvent(new UpdatedEvent(keyValue)); + keyValue.AddDomainEvent(new KeyValueUpdatedEvent(keyValue)); _context.KeyValues.Add(keyValue); await _context.SaveChangesAsync(cancellationToken); return await Result.SuccessAsync(keyValue.Id); diff --git a/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommandHandler.cs b/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommandHandler.cs index fd1f443a..f9b56206 100644 --- a/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommandHandler.cs +++ b/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommandHandler.cs @@ -8,7 +8,7 @@ public async Task> Handle(DeleteKeyValueCommand request, Cancellatio var items = await context.KeyValues.Where(x => request.Id.Contains(x.Id)).ToListAsync(cancellationToken); foreach (var item in items) { - var changeEvent = new UpdatedEvent(item); + var changeEvent = new KeyValueUpdatedEvent(item); item.AddDomainEvent(changeEvent); context.KeyValues.Remove(item); } diff --git a/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommandHandler.cs b/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommandHandler.cs index c28ace0c..8ffcf461 100644 --- a/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommandHandler.cs +++ b/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommandHandler.cs @@ -73,9 +73,12 @@ public async Task Handle(ImportKeyValuesCommand request, CancellationTok { var exist = await _context.KeyValues.AnyAsync(x => x.Name == item.Name && x.Value == item.Value, cancellationToken); - if (exist) continue; + if (exist) + { + continue; + } - item.AddDomainEvent(new CreatedEvent(item)); + item.AddDomainEvent(new KeyValueCreatedEvent(item)); await _context.KeyValues.AddAsync(item, cancellationToken); } else diff --git a/src/Domain/Common/Events/CreatedEvent.cs b/src/Domain/Common/Events/CreatedEvent.cs index f571aebd..e956a459 100644 --- a/src/Domain/Common/Events/CreatedEvent.cs +++ b/src/Domain/Common/Events/CreatedEvent.cs @@ -2,7 +2,7 @@ namespace Cfo.Cats.Domain.Common.Events; -public class CreatedEvent(T entity) : DomainEvent +public abstract class CreatedEvent(T entity) : DomainEvent where T : IEntity { public T Entity { get; } = entity; diff --git a/src/Domain/Common/Events/DeletedEvent.cs b/src/Domain/Common/Events/DeletedEvent.cs index d8e10d10..2527fff5 100644 --- a/src/Domain/Common/Events/DeletedEvent.cs +++ b/src/Domain/Common/Events/DeletedEvent.cs @@ -2,13 +2,8 @@ namespace Cfo.Cats.Domain.Common.Events; -public class DeletedEvent : DomainEvent +public abstract class DeletedEvent(T entity) : DomainEvent where T : IEntity { - public DeletedEvent(T entity) - { - Entity = entity; - } - - public T Entity { get; } + public T Entity { get; } = entity; } diff --git a/src/Domain/Common/Events/UpdatedEvent.cs b/src/Domain/Common/Events/UpdatedEvent.cs index b6f8d4ae..93d3e64e 100644 --- a/src/Domain/Common/Events/UpdatedEvent.cs +++ b/src/Domain/Common/Events/UpdatedEvent.cs @@ -2,13 +2,8 @@ namespace Cfo.Cats.Domain.Common.Events; -public class UpdatedEvent : DomainEvent +public abstract class UpdatedEvent(T entity) : DomainEvent where T : IEntity { - public UpdatedEvent(T entity) - { - Entity = entity; - } - - public T Entity { get; } + public T Entity { get; } = entity; } diff --git a/src/Domain/Entities/KeyValue.cs b/src/Domain/Entities/KeyValue.cs index edf5ab30..c92ba3c9 100644 --- a/src/Domain/Entities/KeyValue.cs +++ b/src/Domain/Entities/KeyValue.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using Cfo.Cats.Domain.Common.Contracts; using Cfo.Cats.Domain.Common.Entities; +using Cfo.Cats.Domain.Common.Events; namespace Cfo.Cats.Domain.Entities { @@ -18,5 +19,12 @@ public enum Picklist ReferralSource = 0 } + + public sealed class KeyValueCreatedEvent(KeyValue entity) : CreatedEvent(entity) + { + } + public sealed class KeyValueUpdatedEvent(KeyValue entity) : UpdatedEvent(entity) + { + } } \ No newline at end of file diff --git a/src/Domain/Events/ContractCreatedEvent.cs b/src/Domain/Events/ContractCreatedEvent.cs index eb6d1a1c..9b68dbd8 100644 --- a/src/Domain/Events/ContractCreatedEvent.cs +++ b/src/Domain/Events/ContractCreatedEvent.cs @@ -3,4 +3,4 @@ namespace Cfo.Cats.Domain.Events; -public class ContractCreatedEvent(Contract entity) : CreatedEvent(entity); \ No newline at end of file +public sealed class ContractCreatedEvent(Contract entity) : CreatedEvent(entity); \ No newline at end of file diff --git a/src/Domain/Events/LocationEvents.cs b/src/Domain/Events/LocationEvents.cs index 61cb90a6..24966fc8 100644 --- a/src/Domain/Events/LocationEvents.cs +++ b/src/Domain/Events/LocationEvents.cs @@ -3,4 +3,4 @@ namespace Cfo.Cats.Domain.Events; -public class LocationCreatedEvent(Location entity) : CreatedEvent(entity); \ No newline at end of file +public sealed class LocationCreatedEvent(Location entity) : CreatedEvent(entity); \ No newline at end of file diff --git a/src/Domain/Events/ParticipantCreatedEvent.cs b/src/Domain/Events/ParticipantCreatedEvent.cs index 831981cf..f1da4a0c 100644 --- a/src/Domain/Events/ParticipantCreatedEvent.cs +++ b/src/Domain/Events/ParticipantCreatedEvent.cs @@ -2,12 +2,12 @@ namespace Cfo.Cats.Domain.Events; -public class ParticipantCreatedEvent(Participant participant) : DomainEvent +public sealed class ParticipantCreatedEvent(Participant participant) : DomainEvent { public Participant Item = participant; } -public class ParticipantAssignedEvent(Participant participant, int? from, int? to) : DomainEvent +public sealed class ParticipantAssignedEvent(Participant participant, int? from, int? to) : DomainEvent { public Participant Item = participant; public int? FromOwner = from; diff --git a/src/Domain/Events/TenantCreatedEvent.cs b/src/Domain/Events/TenantCreatedEvent.cs index bf1ad8a3..df1a8fcb 100644 --- a/src/Domain/Events/TenantCreatedEvent.cs +++ b/src/Domain/Events/TenantCreatedEvent.cs @@ -3,4 +3,4 @@ namespace Cfo.Cats.Domain.Events; -public class TenantCreatedEvent(Tenant entity) : CreatedEvent(entity); \ No newline at end of file +public sealed class TenantCreatedEvent(Tenant entity) : CreatedEvent(entity); \ No newline at end of file diff --git a/test/Domain.ArchitectureTests/Domain.ArchitectureTests.csproj b/test/Domain.ArchitectureTests/Domain.ArchitectureTests.csproj new file mode 100644 index 00000000..0b1f944c --- /dev/null +++ b/test/Domain.ArchitectureTests/Domain.ArchitectureTests.csproj @@ -0,0 +1,29 @@ + + + + net8.0 + Cfo.Cats.Domain.ArchitectureTests + Cfo.Cats.Domain.ArchitectureTests + false + default + + + + + + + + + + + + + + + + + + + + + diff --git a/test/Domain.ArchitectureTests/EntityTests.cs b/test/Domain.ArchitectureTests/EntityTests.cs new file mode 100644 index 00000000..72d10761 --- /dev/null +++ b/test/Domain.ArchitectureTests/EntityTests.cs @@ -0,0 +1,38 @@ +using System.Linq; +using System.Reflection; +using Cfo.Cats.Domain.Common; +using Cfo.Cats.Domain.Common.Contracts; +using FluentAssertions; +using NetArchTest.Rules; +using NUnit.Framework; + +namespace Cfo.Cats.Domain.ArchitectureTests; + +public class EntityTests +{ + private static readonly Assembly DomainAssembly = typeof(IEntity).Assembly; + + [Test] + public void DomainEvents_Should_BeSealed() + { + var result = Types.InAssembly(DomainAssembly) + .That() + .Inherit(typeof(DomainEvent)) + .And() + .AreNotAbstract() + .Should() + .BeSealed() + .GetResult(); + + + var failedTypes = result.FailingTypes?.Select(t => t.FullName).ToList(); + + var formattedFailedTypes = failedTypes == null ? "None" : string.Join("\n", failedTypes); + + + result.IsSuccessful + .Should() + .BeTrue($"The following types failed the test:\n {formattedFailedTypes}"); + + } +} From 5654d44abf11c8b747feffd1b1997fa43d6e3934 Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Sun, 2 Jun 2024 10:00:59 +0100 Subject: [PATCH 02/11] CFODEV-470 create blank test project for application architecture tests --- cats.sln | 7 +++++ .../Application.ArchitectureTests.csproj | 29 +++++++++++++++++++ test/Application.ArchitectureTests/Class1.cs | 6 ++++ 3 files changed, 42 insertions(+) create mode 100644 test/Application.ArchitectureTests/Application.ArchitectureTests.csproj create mode 100644 test/Application.ArchitectureTests/Class1.cs diff --git a/cats.sln b/cats.sln index 56317b58..43c99225 100644 --- a/cats.sln +++ b/cats.sln @@ -39,6 +39,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application.UnitTests", "te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain.ArchitectureTests", "test\Domain.ArchitectureTests\Domain.ArchitectureTests.csproj", "{386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application.ArchitectureTests", "test\Application.ArchitectureTests\Application.ArchitectureTests.csproj", "{7602C41E-1A8C-448D-B29C-CDF8F1E89CEB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -85,6 +87,10 @@ Global {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}.Debug|Any CPU.Build.0 = Debug|Any CPU {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}.Release|Any CPU.ActiveCfg = Release|Any CPU {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}.Release|Any CPU.Build.0 = Release|Any CPU + {7602C41E-1A8C-448D-B29C-CDF8F1E89CEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7602C41E-1A8C-448D-B29C-CDF8F1E89CEB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7602C41E-1A8C-448D-B29C-CDF8F1E89CEB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7602C41E-1A8C-448D-B29C-CDF8F1E89CEB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -100,6 +106,7 @@ Global {50485EFF-8E12-4F8A-A087-A9882D2C31C7} = {28581377-5421-47F6-A678-9510117A7791} {2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E} = {62ABFE2F-D4F3-4E44-AA07-20D679B04CF3} {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6} = {62ABFE2F-D4F3-4E44-AA07-20D679B04CF3} + {7602C41E-1A8C-448D-B29C-CDF8F1E89CEB} = {62ABFE2F-D4F3-4E44-AA07-20D679B04CF3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {916B96E7-FFB9-4D43-A9BD-88CB137B2783} diff --git a/test/Application.ArchitectureTests/Application.ArchitectureTests.csproj b/test/Application.ArchitectureTests/Application.ArchitectureTests.csproj new file mode 100644 index 00000000..ea071819 --- /dev/null +++ b/test/Application.ArchitectureTests/Application.ArchitectureTests.csproj @@ -0,0 +1,29 @@ + + + + net8.0 + Cfo.Cats.Application.ArchitectureTests + Cfo.Cats.Application.ArchitectureTests + false + default + + + + + + + + + + + + + + + + + + + + + diff --git a/test/Application.ArchitectureTests/Class1.cs b/test/Application.ArchitectureTests/Class1.cs new file mode 100644 index 00000000..f620e2fe --- /dev/null +++ b/test/Application.ArchitectureTests/Class1.cs @@ -0,0 +1,6 @@ +namespace Application.ArchitectureTests; + +public class Class1 +{ + +} From ae0699a2b9941309c8793d3f69c3f9abba8076d6 Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Sun, 2 Jun 2024 12:08:57 +0100 Subject: [PATCH 03/11] CFODEV-473 - DomainEvents should be called NOUN_DomainEvent --- .../AddEdit/AddEditKeyValueCommandHandler.cs | 4 ++-- .../Delete/DeleteKeyValueCommandHandler.cs | 2 +- .../Import/ImportKeyValuesCommandHandler.cs | 2 +- .../KeyValueChangedEventHandler.cs | 4 ++-- ...{CreatedEvent.cs => CreatedDomainEvent.cs} | 2 +- ...{DeletedEvent.cs => DeletedDomainEvent.cs} | 2 +- ...{UpdatedEvent.cs => UpdatedDomainEvent.cs} | 2 +- .../Entities/Administration/Contract.cs | 2 +- .../Entities/Administration/Location.cs | 2 +- src/Domain/Entities/Administration/Tenant.cs | 2 +- src/Domain/Entities/KeyValue.cs | 4 ++-- .../Entities/Participants/Participant.cs | 4 ++-- ...Event.cs => ContractCreatedDomainEvent.cs} | 2 +- src/Domain/Events/LocationEvents.cs | 2 +- ...nt.cs => ParticipantCreatedDomainEvent.cs} | 4 ++-- ...edEvent.cs => TenantCreatedDomainEvent.cs} | 2 +- .../{EntityTests.cs => DomainEventTests.cs} | 24 ++++++++++++++++++- 17 files changed, 44 insertions(+), 22 deletions(-) rename src/Domain/Common/Events/{CreatedEvent.cs => CreatedDomainEvent.cs} (68%) rename src/Domain/Common/Events/{DeletedEvent.cs => DeletedDomainEvent.cs} (68%) rename src/Domain/Common/Events/{UpdatedEvent.cs => UpdatedDomainEvent.cs} (68%) rename src/Domain/Events/{ContractCreatedEvent.cs => ContractCreatedDomainEvent.cs} (54%) rename src/Domain/Events/{ParticipantCreatedEvent.cs => ParticipantCreatedDomainEvent.cs} (54%) rename src/Domain/Events/{TenantCreatedEvent.cs => TenantCreatedDomainEvent.cs} (55%) rename test/Domain.ArchitectureTests/{EntityTests.cs => DomainEventTests.cs} (55%) diff --git a/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommandHandler.cs b/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommandHandler.cs index a60782f7..c0f5a944 100644 --- a/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommandHandler.cs +++ b/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommandHandler.cs @@ -21,14 +21,14 @@ public async Task> Handle(AddEditKeyValueCommand request, Cancellati var keyValue = await _context.KeyValues.FindAsync(new object[] { request.Id }, cancellationToken); _ = keyValue ?? throw new NotFoundException($"KeyValue Pair {request.Id} Not Found."); keyValue = _mapper.Map(request, keyValue); - keyValue.AddDomainEvent(new KeyValueUpdatedEvent(keyValue)); + keyValue.AddDomainEvent(new KeyValueUpdatedDomainEvent(keyValue)); await _context.SaveChangesAsync(cancellationToken); return await Result.SuccessAsync(keyValue.Id); } else { var keyValue = _mapper.Map(request); - keyValue.AddDomainEvent(new KeyValueUpdatedEvent(keyValue)); + keyValue.AddDomainEvent(new KeyValueUpdatedDomainEvent(keyValue)); _context.KeyValues.Add(keyValue); await _context.SaveChangesAsync(cancellationToken); return await Result.SuccessAsync(keyValue.Id); diff --git a/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommandHandler.cs b/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommandHandler.cs index f9b56206..bfb12c81 100644 --- a/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommandHandler.cs +++ b/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommandHandler.cs @@ -8,7 +8,7 @@ public async Task> Handle(DeleteKeyValueCommand request, Cancellatio var items = await context.KeyValues.Where(x => request.Id.Contains(x.Id)).ToListAsync(cancellationToken); foreach (var item in items) { - var changeEvent = new KeyValueUpdatedEvent(item); + var changeEvent = new KeyValueUpdatedDomainEvent(item); item.AddDomainEvent(changeEvent); context.KeyValues.Remove(item); } diff --git a/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommandHandler.cs b/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommandHandler.cs index 8ffcf461..03c8de89 100644 --- a/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommandHandler.cs +++ b/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommandHandler.cs @@ -78,7 +78,7 @@ public async Task Handle(ImportKeyValuesCommand request, CancellationTok continue; } - item.AddDomainEvent(new KeyValueCreatedEvent(item)); + item.AddDomainEvent(new KeyValueCreatedDomainEvent(item)); await _context.KeyValues.AddAsync(item, cancellationToken); } else diff --git a/src/Application/Features/KeyValues/EventHandlers/KeyValueChangedEventHandler.cs b/src/Application/Features/KeyValues/EventHandlers/KeyValueChangedEventHandler.cs index d9832567..ae886a0d 100644 --- a/src/Application/Features/KeyValues/EventHandlers/KeyValueChangedEventHandler.cs +++ b/src/Application/Features/KeyValues/EventHandlers/KeyValueChangedEventHandler.cs @@ -3,10 +3,10 @@ namespace Cfo.Cats.Application.Features.KeyValues.EventHandlers; public class KeyValueChangedEventHandler( IPicklistService picklistService, ILogger logger -) : INotificationHandler> +) : INotificationHandler> { - public Task Handle(UpdatedEvent notification, CancellationToken cancellationToken) + public Task Handle(UpdatedDomainEvent notification, CancellationToken cancellationToken) { logger.LogInformation("KeyValue Changed {DomainEvent},{@Entity}", nameof(notification), notification.Entity); picklistService.Refresh(); diff --git a/src/Domain/Common/Events/CreatedEvent.cs b/src/Domain/Common/Events/CreatedDomainEvent.cs similarity index 68% rename from src/Domain/Common/Events/CreatedEvent.cs rename to src/Domain/Common/Events/CreatedDomainEvent.cs index e956a459..5cc51919 100644 --- a/src/Domain/Common/Events/CreatedEvent.cs +++ b/src/Domain/Common/Events/CreatedDomainEvent.cs @@ -2,7 +2,7 @@ namespace Cfo.Cats.Domain.Common.Events; -public abstract class CreatedEvent(T entity) : DomainEvent +public abstract class CreatedDomainEvent(T entity) : DomainEvent where T : IEntity { public T Entity { get; } = entity; diff --git a/src/Domain/Common/Events/DeletedEvent.cs b/src/Domain/Common/Events/DeletedDomainEvent.cs similarity index 68% rename from src/Domain/Common/Events/DeletedEvent.cs rename to src/Domain/Common/Events/DeletedDomainEvent.cs index 2527fff5..eb016e2e 100644 --- a/src/Domain/Common/Events/DeletedEvent.cs +++ b/src/Domain/Common/Events/DeletedDomainEvent.cs @@ -2,7 +2,7 @@ namespace Cfo.Cats.Domain.Common.Events; -public abstract class DeletedEvent(T entity) : DomainEvent +public abstract class DeletedDomainEvent(T entity) : DomainEvent where T : IEntity { public T Entity { get; } = entity; diff --git a/src/Domain/Common/Events/UpdatedEvent.cs b/src/Domain/Common/Events/UpdatedDomainEvent.cs similarity index 68% rename from src/Domain/Common/Events/UpdatedEvent.cs rename to src/Domain/Common/Events/UpdatedDomainEvent.cs index 93d3e64e..fe8b2195 100644 --- a/src/Domain/Common/Events/UpdatedEvent.cs +++ b/src/Domain/Common/Events/UpdatedDomainEvent.cs @@ -2,7 +2,7 @@ namespace Cfo.Cats.Domain.Common.Events; -public abstract class UpdatedEvent(T entity) : DomainEvent +public abstract class UpdatedDomainEvent(T entity) : DomainEvent where T : IEntity { public T Entity { get; } = entity; diff --git a/src/Domain/Entities/Administration/Contract.cs b/src/Domain/Entities/Administration/Contract.cs index a7155c62..32ebdb73 100644 --- a/src/Domain/Entities/Administration/Contract.cs +++ b/src/Domain/Entities/Administration/Contract.cs @@ -29,7 +29,7 @@ private Contract(string id, int lotNumber, string description, string? tenantId, Description = description; Lifetime = new Lifetime(startDate, endDate); - AddDomainEvent( new ContractCreatedEvent(this) ); + AddDomainEvent( new ContractCreatedDomainEvent(this) ); } public int LotNumber { get; private set; } diff --git a/src/Domain/Entities/Administration/Location.cs b/src/Domain/Entities/Administration/Location.cs index 48296f37..e3358a97 100644 --- a/src/Domain/Entities/Administration/Location.cs +++ b/src/Domain/Entities/Administration/Location.cs @@ -33,7 +33,7 @@ private Location(string name, int genderProvisionId, int locationTypeId, string _contractId = contractId; _lifetime = new Lifetime(lifetimeStart, lifetimeEnd); - this.AddDomainEvent(new LocationCreatedEvent(this)); + this.AddDomainEvent(new LocationCreatedDomainEvent(this)); } public static Location Create(string name, int genderProvisionId, int locationTypeId, string? contractId, diff --git a/src/Domain/Entities/Administration/Tenant.cs b/src/Domain/Entities/Administration/Tenant.cs index 1aa15095..82e3a0f0 100644 --- a/src/Domain/Entities/Administration/Tenant.cs +++ b/src/Domain/Entities/Administration/Tenant.cs @@ -17,7 +17,7 @@ private Tenant(string id, string name, string description) Name = name; Description = description; - AddDomainEvent(new TenantCreatedEvent(this)); + AddDomainEvent(new TenantCreatedDomainEvent(this)); } public static Tenant Create(string id, string name, string description) diff --git a/src/Domain/Entities/KeyValue.cs b/src/Domain/Entities/KeyValue.cs index c92ba3c9..6e541d1f 100644 --- a/src/Domain/Entities/KeyValue.cs +++ b/src/Domain/Entities/KeyValue.cs @@ -20,11 +20,11 @@ public enum Picklist } - public sealed class KeyValueCreatedEvent(KeyValue entity) : CreatedEvent(entity) + public sealed class KeyValueCreatedDomainEvent(KeyValue entity) : CreatedDomainEvent(entity) { } - public sealed class KeyValueUpdatedEvent(KeyValue entity) : UpdatedEvent(entity) + public sealed class KeyValueUpdatedDomainEvent(KeyValue entity) : UpdatedDomainEvent(entity) { } } \ No newline at end of file diff --git a/src/Domain/Entities/Participants/Participant.cs b/src/Domain/Entities/Participants/Participant.cs index bf004175..97020a35 100644 --- a/src/Domain/Entities/Participants/Participant.cs +++ b/src/Domain/Entities/Participants/Participant.cs @@ -32,7 +32,7 @@ public static Participant CreateFrom(Candidate candidate, string referralSource, ReferralComments = referralComments }; - p.AddDomainEvent(new ParticipantCreatedEvent(p)); + p.AddDomainEvent(new ParticipantCreatedDomainEvent(p)); return p; } @@ -56,7 +56,7 @@ public void AssignTo(int? userId) { if (userId != OwnerId) { - AddDomainEvent(new ParticipantAssignedEvent(this, OwnerId, userId)); + AddDomainEvent(new ParticipantAssignedDomainEvent(this, OwnerId, userId)); OwnerId = userId; } } diff --git a/src/Domain/Events/ContractCreatedEvent.cs b/src/Domain/Events/ContractCreatedDomainEvent.cs similarity index 54% rename from src/Domain/Events/ContractCreatedEvent.cs rename to src/Domain/Events/ContractCreatedDomainEvent.cs index 9b68dbd8..7d56d684 100644 --- a/src/Domain/Events/ContractCreatedEvent.cs +++ b/src/Domain/Events/ContractCreatedDomainEvent.cs @@ -3,4 +3,4 @@ namespace Cfo.Cats.Domain.Events; -public sealed class ContractCreatedEvent(Contract entity) : CreatedEvent(entity); \ No newline at end of file +public sealed class ContractCreatedDomainEvent(Contract entity) : CreatedDomainEvent(entity); \ No newline at end of file diff --git a/src/Domain/Events/LocationEvents.cs b/src/Domain/Events/LocationEvents.cs index 24966fc8..c3098484 100644 --- a/src/Domain/Events/LocationEvents.cs +++ b/src/Domain/Events/LocationEvents.cs @@ -3,4 +3,4 @@ namespace Cfo.Cats.Domain.Events; -public sealed class LocationCreatedEvent(Location entity) : CreatedEvent(entity); \ No newline at end of file +public sealed class LocationCreatedDomainEvent(Location entity) : CreatedDomainEvent(entity); \ No newline at end of file diff --git a/src/Domain/Events/ParticipantCreatedEvent.cs b/src/Domain/Events/ParticipantCreatedDomainEvent.cs similarity index 54% rename from src/Domain/Events/ParticipantCreatedEvent.cs rename to src/Domain/Events/ParticipantCreatedDomainEvent.cs index f1da4a0c..3a58539f 100644 --- a/src/Domain/Events/ParticipantCreatedEvent.cs +++ b/src/Domain/Events/ParticipantCreatedDomainEvent.cs @@ -2,12 +2,12 @@ namespace Cfo.Cats.Domain.Events; -public sealed class ParticipantCreatedEvent(Participant participant) : DomainEvent +public sealed class ParticipantCreatedDomainEvent(Participant participant) : DomainEvent { public Participant Item = participant; } -public sealed class ParticipantAssignedEvent(Participant participant, int? from, int? to) : DomainEvent +public sealed class ParticipantAssignedDomainEvent(Participant participant, int? from, int? to) : DomainEvent { public Participant Item = participant; public int? FromOwner = from; diff --git a/src/Domain/Events/TenantCreatedEvent.cs b/src/Domain/Events/TenantCreatedDomainEvent.cs similarity index 55% rename from src/Domain/Events/TenantCreatedEvent.cs rename to src/Domain/Events/TenantCreatedDomainEvent.cs index df1a8fcb..483b4569 100644 --- a/src/Domain/Events/TenantCreatedEvent.cs +++ b/src/Domain/Events/TenantCreatedDomainEvent.cs @@ -3,4 +3,4 @@ namespace Cfo.Cats.Domain.Events; -public sealed class TenantCreatedEvent(Tenant entity) : CreatedEvent(entity); \ No newline at end of file +public sealed class TenantCreatedDomainEvent(Tenant entity) : CreatedDomainEvent(entity); \ No newline at end of file diff --git a/test/Domain.ArchitectureTests/EntityTests.cs b/test/Domain.ArchitectureTests/DomainEventTests.cs similarity index 55% rename from test/Domain.ArchitectureTests/EntityTests.cs rename to test/Domain.ArchitectureTests/DomainEventTests.cs index 72d10761..d3b9d125 100644 --- a/test/Domain.ArchitectureTests/EntityTests.cs +++ b/test/Domain.ArchitectureTests/DomainEventTests.cs @@ -8,7 +8,7 @@ namespace Cfo.Cats.Domain.ArchitectureTests; -public class EntityTests +public class DomainEventTests { private static readonly Assembly DomainAssembly = typeof(IEntity).Assembly; @@ -35,4 +35,26 @@ public void DomainEvents_Should_BeSealed() .BeTrue($"The following types failed the test:\n {formattedFailedTypes}"); } + + [Test] + public void DomainEvents_Should_HaveDomainEventPostfix() + { + var result = Types.InAssembly(DomainAssembly) + .That() + .Inherit(typeof(DomainEvent)) + .Should() + .HaveNameEndingWith("DomainEvent") + .Or() + .HaveNameEndingWith("DomainEvent`1") // this allows for our generic type + .GetResult(); + + var failedTypes = result.FailingTypes?.Select(t => t.FullName).ToList(); + + var formattedFailedTypes = failedTypes == null ? "None" : string.Join("\n", failedTypes); + + result.IsSuccessful + .Should() + .BeTrue($"The following types failed the test:\n {formattedFailedTypes}"); + } + } From 97e9e6539c8184020974cae90da06a5291aa4082 Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Sun, 2 Jun 2024 16:38:06 +0100 Subject: [PATCH 04/11] Test to confirm Entities have a private, parameterless constructor. note: tests currently fail due to needing another branch merging with this one. --- .../Entities/Administration/Location.cs | 4 +- src/Domain/Entities/AuditTrail.cs | 1 + src/Domain/Entities/Candidates/Candidate.cs | 4 ++ src/Domain/Entities/Documents/Document.cs | 4 ++ src/Domain/Entities/KeyValue.cs | 1 + .../AssemblyExtensions.cs | 41 ++++++++++++++++++ test/Domain.ArchitectureTests/EntityTests.cs | 42 +++++++++++++++++++ 7 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 test/Domain.ArchitectureTests/AssemblyExtensions.cs create mode 100644 test/Domain.ArchitectureTests/EntityTests.cs diff --git a/src/Domain/Entities/Administration/Location.cs b/src/Domain/Entities/Administration/Location.cs index e3358a97..d29a6142 100644 --- a/src/Domain/Entities/Administration/Location.cs +++ b/src/Domain/Entities/Administration/Location.cs @@ -19,7 +19,7 @@ public class Location : BaseAuditableEntity, ILifetimeEntity private readonly List _childLocations = new(); #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - protected Location() + private Location() { } #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. @@ -48,7 +48,7 @@ public static Location Create(string name, int genderProvisionId, int locationTy public LocationType LocationType => LocationType.FromValue(_locationTypeId); - public virtual Contract Contract { get; private set; } + public virtual Contract? Contract { get; private set; } public Lifetime Lifetime => _lifetime; diff --git a/src/Domain/Entities/AuditTrail.cs b/src/Domain/Entities/AuditTrail.cs index 6d655806..7c67a5dc 100644 --- a/src/Domain/Entities/AuditTrail.cs +++ b/src/Domain/Entities/AuditTrail.cs @@ -9,6 +9,7 @@ namespace Cfo.Cats.Domain.Entities; public class AuditTrail : IEntity { + public int Id { get; set; } public int? UserId { get; set; } public virtual ApplicationUser? Owner { get; set; } diff --git a/src/Domain/Entities/Candidates/Candidate.cs b/src/Domain/Entities/Candidates/Candidate.cs index 05c45bc0..89b6be3a 100644 --- a/src/Domain/Entities/Candidates/Candidate.cs +++ b/src/Domain/Entities/Candidates/Candidate.cs @@ -8,6 +8,10 @@ namespace Cfo.Cats.Domain.Entities.Candidates; public class Candidate : BaseAuditableEntity { + private Candidate() + { + } + private List _identifiers = new(); public string FirstName { get; private set; } diff --git a/src/Domain/Entities/Documents/Document.cs b/src/Domain/Entities/Documents/Document.cs index 90e934ac..e52bff5e 100644 --- a/src/Domain/Entities/Documents/Document.cs +++ b/src/Domain/Entities/Documents/Document.cs @@ -4,6 +4,10 @@ namespace Cfo.Cats.Domain.Entities.Documents; public class Document : BaseAuditableSoftDeleteEntity { + private Document() + { + } + public string FileName { get; set; } public string ContentType { get; set; } } \ No newline at end of file diff --git a/src/Domain/Entities/KeyValue.cs b/src/Domain/Entities/KeyValue.cs index 6e541d1f..12e73298 100644 --- a/src/Domain/Entities/KeyValue.cs +++ b/src/Domain/Entities/KeyValue.cs @@ -7,6 +7,7 @@ namespace Cfo.Cats.Domain.Entities { public class KeyValue : BaseAuditableEntity, IAuditTrial { + public Picklist Name { get; set; } = Picklist.ReferralSource; public string? Value { get; set; } public string? Text { get; set; } diff --git a/test/Domain.ArchitectureTests/AssemblyExtensions.cs b/test/Domain.ArchitectureTests/AssemblyExtensions.cs new file mode 100644 index 00000000..2507c121 --- /dev/null +++ b/test/Domain.ArchitectureTests/AssemblyExtensions.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Cfo.Cats.Domain.ArchitectureTests; + +public static class AssemblyExtensions +{ + public static List GetConcreteTypesThatImplement(this Assembly assembly, Type interfaceType) + { + if (interfaceType.IsInterface == false) + { + throw new ArgumentException("The provided type must be an interface", nameof(interfaceType)); + } + + return assembly.GetTypes() + .Where(type => type.IsAbstract == false && type.IsInterface == false && ImplementsInterface(type, interfaceType)) + .ToList(); + } + + private static bool ImplementsInterface(Type type, Type interfaceType) + { + if (interfaceType.IsAssignableFrom(type)) + { + return true; + } + + var currentType = type.BaseType; + while (currentType != null && currentType != typeof(object)) + { + if (interfaceType.IsAssignableFrom(currentType)) + { + return true; + } + currentType = currentType.BaseType; + } + + return false; + } +} \ No newline at end of file diff --git a/test/Domain.ArchitectureTests/EntityTests.cs b/test/Domain.ArchitectureTests/EntityTests.cs new file mode 100644 index 00000000..30e48a0d --- /dev/null +++ b/test/Domain.ArchitectureTests/EntityTests.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Cfo.Cats.Domain.Common.Contracts; +using Cfo.Cats.Domain.Entities; +using FluentAssertions; +using NetArchTest.Rules; +using NUnit.Framework; + +namespace Cfo.Cats.Domain.ArchitectureTests; + +public class EntityTests +{ + private static readonly Assembly DomainAssembly = typeof(IEntity).Assembly; + + [Test] + public void Entities_Should_HavePrivateParameterlessConstructor() + { + var entityTypes = DomainAssembly.GetConcreteTypesThatImplement(typeof(IEntity)); + + var failingTypes = new List(); + + foreach (var type in entityTypes) + { + if (type == typeof(AuditTrail)) + { + continue; + } + + var constructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance); + + if (constructors.Any(c => c.IsPrivate && c.GetParameters().Length == 0) == false) + { + failingTypes.Add(type); + } + } + + failingTypes.Should().BeEmpty(); + + } +} \ No newline at end of file From 6579afc1b881ffbc721649f7c3cd4fb002da6267 Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Fri, 31 May 2024 14:59:14 +0100 Subject: [PATCH 05/11] Remove seeds from the initializer and add to a script instead --- db/seed/001_development_seed.sql | 236 ++++++++++++++++++ db/seed/README.md | 8 + .../ApplicationDbContextInitializer.cs | 145 +---------- .../DataSeeds/Development/Locations.json | 91 ------- .../DataSeeds/Development/Users.json | 30 --- .../Persistence/Initializers/SeedingData.cs | 161 ------------ src/Server.UI/Program.cs | 1 - 7 files changed, 246 insertions(+), 426 deletions(-) create mode 100644 db/seed/001_development_seed.sql create mode 100644 db/seed/README.md delete mode 100644 src/Infrastructure/Persistence/DataSeeds/Development/Locations.json delete mode 100644 src/Infrastructure/Persistence/DataSeeds/Development/Users.json delete mode 100644 src/Infrastructure/Persistence/Initializers/SeedingData.cs diff --git a/db/seed/001_development_seed.sql b/db/seed/001_development_seed.sql new file mode 100644 index 00000000..51a4dfc8 --- /dev/null +++ b/db/seed/001_development_seed.sql @@ -0,0 +1,236 @@ + +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.', N'CFO', N'Root tenant for Creating Future Opportunities', N'2024-05-31 12:30:38.3849332', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.', N'CFO Evolution', N'Top level tenant for Evolution Programme', N'2024-05-31 12:30:38.3850497', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.1.', N'Alpha', N'Alpha', N'2024-05-31 12:30:38.3850635', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.', N'Bravo', N'Top level tenant for provider Bravo', N'2024-05-31 12:30:38.3850637', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.1.', N'Bravo (A)', N'Bravo (A)', N'2024-05-31 12:30:38.3850640', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.2.', N'Bravo (B)', N'Bravo (B)', N'2024-05-31 12:30:38.3850641', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.3.', N'Bravo (C)', N'Bravo (C)', N'2024-05-31 12:30:38.3850643', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.3.', N'Charlie', N'Charlie', N'2024-05-31 12:30:38.3850645', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.', N'Delta', N'Top level tenant for Delta', N'2024-05-31 12:30:38.3850647', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.1.', N'Delta (A)', N'Delta (A)', N'2024-05-31 12:30:38.3850648', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.2.', N'Delta (B)', N'Delta (B)', N'2024-05-31 12:30:38.3850650', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.5.', N'Echo', N'Echo', N'2024-05-31 12:30:38.3850651', null, null, null); +INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.6.', N'Foxtrot', N'Foxtrot', N'2024-05-31 12:30:38.3850653', null, null, null); + +GO + +SET IDENTITY_INSERT ApplicationRole ON; + +INSERT INTO dbo.ApplicationRole (Id, Description, Name, NormalizedName, ConcurrencyStamp) VALUES (1, N'Admin Group', N'Admin', N'ADMIN', N'e6340a9c-8144-4f9d-8489-2e21af06bc56'); +INSERT INTO dbo.ApplicationRole (Id, Description, Name, NormalizedName, ConcurrencyStamp) VALUES (2, N'Basic User Group', N'Basic', N'BASIC', N'67781ee3-3fbc-4214-bec7-3fba39ea0eb3'); + +SET IDENTITY_INSERT ApplicationRole OFF; + +GO + +SET IDENTITY_INSERT ApplicationRoleClaim ON; + +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (1, null, null, 1, N'Permission', N'Permissions.AuditTrails.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (2, null, null, 1, N'Permission', N'Permissions.AuditTrails.Search'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (3, null, null, 1, N'Permission', N'Permissions.AuditTrails.Export'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (4, null, null, 1, N'Permission', N'Permissions.Dashboards.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (5, null, null, 1, N'Permission', N'Permissions.Dictionaries.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (6, null, null, 1, N'Permission', N'Permissions.Dictionaries.Create'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (7, null, null, 1, N'Permission', N'Permissions.Dictionaries.Edit'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (8, null, null, 1, N'Permission', N'Permissions.Dictionaries.Delete'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (9, null, null, 1, N'Permission', N'Permissions.Dictionaries.Search'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (10, null, null, 1, N'Permission', N'Permissions.Dictionaries.Export'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (11, null, null, 1, N'Permission', N'Permissions.Dictionaries.Import'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (12, null, null, 1, N'Permission', N'Permissions.Enrolments.Search'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (13, null, null, 1, N'Permission', N'Permissions.Hangfire.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (14, null, null, 1, N'Permission', N'Permissions.Hangfire.Jobs'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (15, null, null, 1, N'Permission', N'Permissions.Logs.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (16, null, null, 1, N'Permission', N'Permissions.Logs.Search'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (17, null, null, 1, N'Permission', N'Permissions.Logs.Export'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (18, null, null, 1, N'Permission', N'Permissions.Logs.Purge'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (19, null, null, 1, N'Permission', N'Permissions.RoleClaims.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (20, null, null, 1, N'Permission', N'Permissions.RoleClaims.Create'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (21, null, null, 1, N'Permission', N'Permissions.RoleClaims.Edit'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (22, null, null, 1, N'Permission', N'Permissions.RoleClaims.Delete'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (23, null, null, 1, N'Permission', N'Permissions.RoleClaims.Search'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (24, null, null, 1, N'Permission', N'Permissions.Roles.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (25, null, null, 1, N'Permission', N'Permissions.Roles.Create'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (26, null, null, 1, N'Permission', N'Permissions.Roles.Edit'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (27, null, null, 1, N'Permission', N'Permissions.Roles.Delete'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (28, null, null, 1, N'Permission', N'Permissions.Roles.Search'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (29, null, null, 1, N'Permission', N'Permissions.Roles.Export'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (30, null, null, 1, N'Permission', N'Permissions.Roles.Import'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (31, null, null, 1, N'Permission', N'Permissions.Roles.Permissions'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (32, null, null, 1, N'Permission', N'Permissions.Roles.Navigation'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (33, null, null, 1, N'Permission', N'Permissions.Tenants.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (34, null, null, 1, N'Permission', N'Permissions.Tenants.Create'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (35, null, null, 1, N'Permission', N'Permissions.Tenants.Edit'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (36, null, null, 1, N'Permission', N'Permissions.Tenants.Delete'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (37, null, null, 1, N'Permission', N'Permissions.Tenants.Search'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (38, null, null, 1, N'Permission', N'Permissions.Tenants.Export'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (39, null, null, 1, N'Permission', N'Permissions.Users.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (40, null, null, 1, N'Permission', N'Permissions.Users.Create'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (41, null, null, 1, N'Permission', N'Permissions.Users.Edit'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (42, null, null, 1, N'Permission', N'Permissions.Users.Delete'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (43, null, null, 1, N'Permission', N'Permissions.Users.Search'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (44, null, null, 1, N'Permission', N'Permissions.Users.Import'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (45, null, null, 1, N'Permission', N'Permissions.Dictionaries.Export'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (46, null, null, 1, N'Permission', N'Permissions.Users.ManageRoles'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (47, null, null, 1, N'Permission', N'Permissions.Users.RestPassword'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (48, null, null, 1, N'Permission', N'Permissions.Users.Active'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (49, null, null, 1, N'Permission', N'Permissions.Users.Permissions'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (50, null, null, 2, N'Permission', N'Permissions.AuditTrails.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (51, null, null, 2, N'Permission', N'Permissions.Dashboards.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (52, null, null, 2, N'Permission', N'Permissions.Dictionaries.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (53, null, null, 2, N'Permission', N'Permissions.Hangfire.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (54, null, null, 2, N'Permission', N'Permissions.Logs.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (55, null, null, 2, N'Permission', N'Permissions.RoleClaims.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (56, null, null, 2, N'Permission', N'Permissions.Roles.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (57, null, null, 2, N'Permission', N'Permissions.Tenants.View'); +INSERT INTO dbo.ApplicationRoleClaim (Id, Description, [Group], RoleId, ClaimType, ClaimValue) VALUES (58, null, null, 2, N'Permission', N'Permissions.Users.View'); + +SET IDENTITY_INSERT ApplicationRoleClaim OFF; + +GO + +SET IDENTITY_INSERT ApplicationUser ON; + +INSERT INTO dbo.ApplicationUser (Id, DisplayName, Provider, TenantId, TenantName, ProfilePictureDataUrl, IsActive, IsLive, RefreshToken, RefreshTokenExpiryTime, SuperiorId, UserName, NormalizedUserName, Email, NormalizedEmail, EmailConfirmed, PasswordHash, SecurityStamp, ConcurrencyStamp, PhoneNumber, PhoneNumberConfirmed, TwoFactorEnabled, LockoutEnd, LockoutEnabled, AccessFailedCount) VALUES (1, N'Support Worker', N'Local', N'1.', N'CFO', N'https://avatars.githubusercontent.com/u/9332472?s=400&u=73c208bf07ba967d5407aae9068580539cfc80a2&v=4', 1, 0, null, N'0001-01-01 00:00:00.0000000', null, N'support.worker@justice.gov.uk', N'SUPPORT.WORKER@JUSTICE.GOV.UK', N'support.worker@justice.gov.uk', N'SUPPORT.WORKER@JUSTICE.GOV.UK', 1, N'AQAAAAIAAYagAAAAEAVdTO5H3lP4OTTB1CzJun94RqDWYMHHxDYYLCcf3zER/g2IRxukunJEOYggb0xWZg==', N'5OAC7CKMMFBY3SMD4MZ7GKVDZRZ7CVUZ', N'49dbf347-de6b-4579-997b-3cfd4d79afa0', null, 0, 0, null, 1, 0); + +SET IDENTITY_INSERT ApplicationUser OFF; + +GO + +INSERT INTO dbo.ApplicationUserRole (UserId, RoleId) VALUES (1, 1); + + +GO + +INSERT INTO dbo.Contract (Id, LotNumber, LifetimeStart, LifetimeEnd, Description, TenantId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'Evolution1', 1, N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', N'North West', N'1.', N'2024-05-31 12:30:38.9702330', null, null, null); +INSERT INTO dbo.Contract (Id, LotNumber, LifetimeStart, LifetimeEnd, Description, TenantId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'Evolution2', 2, N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', N'North East', N'1.', N'2024-05-31 12:30:38.9702326', null, null, null); +INSERT INTO dbo.Contract (Id, LotNumber, LifetimeStart, LifetimeEnd, Description, TenantId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'Evolution3', 3, N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', N'Yorkshire and Humberside', N'1.', N'2024-05-31 12:30:38.9702322', null, null, null); +INSERT INTO dbo.Contract (Id, LotNumber, LifetimeStart, LifetimeEnd, Description, TenantId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'Evolution4', 4, N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', N'West Midlands', N'1.', N'2024-05-31 12:30:38.9702315', null, null, null); +INSERT INTO dbo.Contract (Id, LotNumber, LifetimeStart, LifetimeEnd, Description, TenantId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'Evolution5', 5, N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', N'East Midlands', N'1.', N'2024-05-31 12:30:38.9702311', null, null, null); +INSERT INTO dbo.Contract (Id, LotNumber, LifetimeStart, LifetimeEnd, Description, TenantId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'Evolution6', 6, N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', N'East Of England', N'1.', N'2024-05-31 12:30:38.9702308', null, null, null); +INSERT INTO dbo.Contract (Id, LotNumber, LifetimeStart, LifetimeEnd, Description, TenantId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'Evolution7', 7, N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', N'London', N'1.', N'2024-05-31 12:30:38.9702304', null, null, null); +INSERT INTO dbo.Contract (Id, LotNumber, LifetimeStart, LifetimeEnd, Description, TenantId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'Evolution8', 8, N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', N'South West', N'1.', N'2024-05-31 12:30:38.9702300', null, null, null); +INSERT INTO dbo.Contract (Id, LotNumber, LifetimeStart, LifetimeEnd, Description, TenantId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'Evolution9', 9, N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', N'South East', N'1.', N'2024-05-31 12:30:38.9702153', null, null, null); + +GO + +SET IDENTITY_INSERT KeyValue ON; + +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (1, N'ReferralSource', N'CFO Evolution Provider', N'CFO Evolution Provider', N'A referral source', N'2024-05-31 12:30:42.7615462', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (2, N'ReferralSource', N'Probation', N'Probation', N'A referral source', N'2024-05-31 12:30:42.7615457', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (3, N'ReferralSource', N'Approved Premises', N'Approved Premises', N'A referral source', N'2024-05-31 12:30:42.7615453', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (4, N'ReferralSource', N'CAS2', N'CAS2', N'A referral source', N'2024-05-31 12:30:42.7615451', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (5, N'ReferralSource', N'CAS3', N'CAS3', N'A referral source', N'2024-05-31 12:30:42.7615449', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (6, N'ReferralSource', N'Custodial Family Services', N'Custodial Family Services', N'A referral source', N'2024-05-31 12:30:42.7615448', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (7, N'ReferralSource', N'CRS - Women', N'CRS- Women', N'A referral source', N'2024-05-31 12:30:42.7615445', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (8, N'ReferralSource', N'CRS - Personal Wellbeing', N'CRS- Personal Wellbeing', N'A referral source', N'2024-05-31 12:30:42.7615443', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (9, N'ReferralSource', N'CRS - Dependency & Recovery', N'CRS- Dependency & Recovery', N'A referral source', N'2024-05-31 12:30:42.7615441', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (10, N'ReferralSource', N'CRS - Accommodation', N'CRS- Accommodation', N'A referral source', N'2024-05-31 12:30:42.7615439', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (11, N'ReferralSource', N'Custody staff', N'Custody staff', N'A referral source', N'2024-05-31 12:30:42.7615436', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (12, N'ReferralSource', N'New Futures Network', N'New Futures Network', N'A referral source', N'2024-05-31 12:30:42.7615428', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (13, N'ReferralSource', N'Prison Education Provider', N'Prison Education Provider', N'A referral source', N'2024-05-31 12:30:42.7615425', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (14, N'ReferralSource', N'DWP', N'DWP', N'A referral source', N'2024-05-31 12:30:42.7615421', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (15, N'ReferralSource', N'Healthcare', N'Healthcare', N'A referral source', N'2024-05-31 12:30:42.7615417', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (16, N'ReferralSource', N'Community / Voluntary Sector organisation', N'Community / Voluntary Sector organisation', N'A referral source', N'2024-05-31 12:30:42.7615414', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (17, N'ReferralSource', N'Local Authority', N'Local Authority', N'A referral source', N'2024-05-31 12:30:42.7615410', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (18, N'ReferralSource', N'Courts', N'Courts', N'A referral source', N'2024-05-31 12:30:42.7615390', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (19, N'ReferralSource', N'Self-referral', N'Self-referral', N'A referral source', N'2024-05-31 12:30:42.7615372', null, null, null); +INSERT INTO dbo.KeyValue (Id, Name, Value, Text, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (20, N'ReferralSource', N'Other', N'Other', N'A referral source (please state)', N'2024-05-31 12:30:42.7615265', null, null, null); + +SET IDENTITY_INSERT KeyValue OFF; + +GO + +SET IDENTITY_INSERT Location ON; + +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (1, N'Risley', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888014', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (2, N'Lancaster', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888012', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (3, N'Forest Bank', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888009', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (4, N'Altcourse', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888007', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (5, N'Preston', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888004', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (6, N'Buckley Hall', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888001', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (7, N'Liverpool', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5887998', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (8, N'Manchester', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5887995', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (9, N'Thorn Cross', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5887991', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (10, N'Haverigg', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5887988', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (11, N'Hindley', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5887984', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (12, N'Kirkham', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5887894', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (13, N'Wymott', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5886872', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (14, N'Styal', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888017', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (15, N'Holme House', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888025', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (16, N'Northumberland', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888028', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (17, N'Durham', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888030', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (18, N'Kirklevington Grange', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888032', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (19, N'Low Newton', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888034', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (20, N'Wealstun', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888037', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (21, N'Moorland', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888043', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (22, N'Humber', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888046', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (23, N'Doncaster', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888051', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (24, N'Leeds', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888053', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (25, N'Hull', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888055', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (26, N'Full Sutton', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888058', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (27, N'Hatfield', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888060', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (28, N'Lindholme', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888063', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (29, N'Askham Grange', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888066', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (30, N'New Hall', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888076', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (31, N'Featherstone', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888088', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (32, N'Drake Hall', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888091', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (33, N'Birmingham', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888093', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (34, N'Brinsford', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888096', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (35, N'Dovegate', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888101', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (36, N'Hewell', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888104', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (37, N'Oakwood', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888106', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (38, N'Stoke Heath', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888108', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (39, N'Swinfen Hall', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888111', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (40, N'Ranby', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888114', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (41, N'Nottingham', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888118', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (42, N'Five Wells', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888121', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (43, N'Lincoln', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888125', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (44, N'North Sea Camp', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888127', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (45, N'Onley', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888130', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (46, N'Stocken', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888132', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (47, N'Whatton', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888135', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (48, N'Foston Hall', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888138', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (49, N'The Mount', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888140', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (50, N'Peterborough (M)', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888143', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (51, N'Bedford', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888146', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (52, N'Chelmsford', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888149', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (53, N'Highpoint', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888151', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (54, N'Hollesley Bay', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888153', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (55, N'Littlehey', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888157', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (56, N'Norwich', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888159', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (57, N'Wayland', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888162', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (58, N'Peterborough (F)', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888165', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (59, N'High Down', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888167', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (60, N'Wandsworth', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888170', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (61, N'Thameside', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888171', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (62, N'Brixton', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888179', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (63, N'Feltham', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888181', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (64, N'Isis', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888184', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (65, N'Pentonville', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888186', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (66, N'Bronzefield', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888189', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (67, N'Downview', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888197', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (68, N'Portland', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888199', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (69, N'Exeter', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888201', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (70, N'Bristol', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888204', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (71, N'Channings Wood', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888206', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (72, N'Dartmoor', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888209', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (73, N'Leyhill', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888212', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (74, N'Guys Marsh', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888214', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (75, N'The Verne', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888217', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (76, N'Eastwood Park', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888219', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (77, N'Rochester', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888221', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (78, N'Elmley', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888224', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (79, N'Lewes', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888227', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (80, N'Winchester', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888229', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (81, N'Aylesbury', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888232', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (82, N'Bullingdon', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888234', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (83, N'Ford', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888237', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (84, N'Springhill', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888239', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (85, N'Stanford Hill', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888241', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (86, N'Swaleside', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888244', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (87, N'Woodhill', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 2, N'2024-05-31 12:30:39.5888246', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (88, N'Send', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888253', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (89, N'East Sutton Park', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); + +SET IDENTITY_INSERT Location OFF; \ No newline at end of file diff --git a/db/seed/README.md b/db/seed/README.md new file mode 100644 index 00000000..f2273736 --- /dev/null +++ b/db/seed/README.md @@ -0,0 +1,8 @@ +# Database Seed Scripts + +This directory contains SQL scripts to seed the database with initial data. + +## How to Use + +1. Ensure your database is created and migrated using EF Core. +2. Run the seed scripts in the alphabetical order \ No newline at end of file diff --git a/src/Infrastructure/Persistence/ApplicationDbContextInitializer.cs b/src/Infrastructure/Persistence/ApplicationDbContextInitializer.cs index 169abf47..3411f55d 100644 --- a/src/Infrastructure/Persistence/ApplicationDbContextInitializer.cs +++ b/src/Infrastructure/Persistence/ApplicationDbContextInitializer.cs @@ -1,35 +1,7 @@ -using System.Text.Json; -using Cfo.Cats.Domain.Common.Enums; -using Cfo.Cats.Domain.Entities.Administration; -using Cfo.Cats.Domain.Identity; -using Cfo.Cats.Infrastructure.Constants.ClaimTypes; -using Cfo.Cats.Infrastructure.Constants.Role; -using Cfo.Cats.Infrastructure.PermissionSet; -using Cfo.Cats.Infrastructure.Persistence.Initializers; -using DocumentFormat.OpenXml.Office2010.Excel; +namespace Cfo.Cats.Infrastructure.Persistence; -namespace Cfo.Cats.Infrastructure.Persistence; - -public class ApplicationDbContextInitializer +public class ApplicationDbContextInitializer(ILogger logger, ApplicationDbContext context) { - private readonly ApplicationDbContext context; - private readonly ILogger logger; - private readonly RoleManager roleManager; - private readonly UserManager userManager; - - public ApplicationDbContextInitializer( - ILogger logger, - ApplicationDbContext context, - UserManager userManager, - RoleManager roleManager - ) - { - this.logger = logger; - this.context = context; - this.userManager = userManager; - this.roleManager = roleManager; - } - public async Task InitialiseAsync() { try @@ -48,117 +20,4 @@ public async Task InitialiseAsync() throw; } } - - public async Task SeedAsync() - { - try - { - await TrySeedAsync(); - context.ChangeTracker.Clear(); - } - catch (Exception ex) - { - logger.LogError(ex, "An error occurred while seeding the database"); - throw; - } - } - - private async Task TrySeedAsync() - { - await SeedTenants(); - await SeedContracts(); - await SeedLocations(); - await SeedDictionaries(); - - // Default roles - var administratorRole = new ApplicationRole(RoleName.Admin) { Description = "Admin Group" }; - var basicRole = new ApplicationRole(RoleName.Basic) { Description = "Basic User Group" }; - - var permissions = Permissions.GetRegisteredPermissions(); - - if (roleManager.Roles.All(r => r.Name != administratorRole.Name)) - { - await roleManager.CreateAsync(administratorRole); - - foreach (var permission in permissions) - { - await roleManager.AddClaimAsync( - administratorRole, - new Claim(ApplicationClaimTypes.Permission, permission) - ); - } - } - - if (roleManager.Roles.All(r => r.Name != basicRole.Name)) - { - await roleManager.CreateAsync(basicRole); - foreach (var permission in permissions.Where(p => p.EndsWith(".View"))) - { - await roleManager.AddClaimAsync(basicRole, new Claim(ApplicationClaimTypes.Permission, permission)); - } - } - - var defaultUser = new ApplicationUser() - { - UserName = "support.worker@justice.gov.uk", - Provider = "Local", - IsActive = true, - TenantId = context.Tenants.First().Id, - TenantName = context.Tenants.First().Name, - DisplayName = "Support Worker", - Email = "support.worker@justice.gov.uk", - EmailConfirmed = true, - ProfilePictureDataUrl = - "https://avatars.githubusercontent.com/u/9332472?s=400&u=73c208bf07ba967d5407aae9068580539cfc80a2&v=4", - TwoFactorEnabled = false - }; - - if (userManager.Users.All(u => u.UserName != "support.worker@justice.gov.uk")) - { - await userManager.CreateAsync(defaultUser, "Password123!"); - await userManager.AddToRolesAsync(defaultUser, new[] { administratorRole.Name! }); - } - } - private async Task SeedDictionaries() - { - if (await context.KeyValues.AnyAsync() == false) - { - var kvps = SeedingData.GetDictionaries(); - context.KeyValues.AddRange(kvps); - await context.SaveChangesAsync(); - } - } - - private async Task SeedLocations() - { - if (await context.Locations.AnyAsync() == false) - { - var locations = SeedingData.GetLocations(); - context.Locations.AddRange(locations); - await context.SaveChangesAsync(); - - } - } - - private async Task SeedTenants() - { - if (await context.Tenants.OrderBy(r => r.Id).Select(e => e.Id).FirstOrDefaultAsync() == null) - { - var tenants = SeedingData.GetTenants(); - context.Tenants.AddRange(tenants); - await context.SaveChangesAsync(); - } - } - - private async Task SeedContracts() - { - if (await context.Contracts.OrderBy(r => r.Id).Select(e => e.Id).FirstOrDefaultAsync() is null) - { - var contracts = SeedingData.GetContracts(); - context.Contracts.AddRange(contracts); - await context.SaveChangesAsync(); - } - } - - } diff --git a/src/Infrastructure/Persistence/DataSeeds/Development/Locations.json b/src/Infrastructure/Persistence/DataSeeds/Development/Locations.json deleted file mode 100644 index 0352ab07..00000000 --- a/src/Infrastructure/Persistence/DataSeeds/Development/Locations.json +++ /dev/null @@ -1,91 +0,0 @@ -[ - {"contractId": "Evolution1", "name": "Risley", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Lancaster", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Forest Bank", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Altcourse", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Preston", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Buckley Hall", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Liverpool", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Manchester", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Thorn Cross", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Haverigg", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Hindley", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Kirkham", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Wymott", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution1", "name": "Styal", "locationType": "Unspecified", "genderProvision": "Female"}, - {"contractId": "Evolution2", "name": "Holme House", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution2", "name": "Northumberland", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution2", "name": "Durham", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution2", "name": "Kirklevington Grange", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution2", "name": "Low Newton", "locationType": "Unspecified", "genderProvision": "Female"}, - {"contractId": "Evolution3", "name": "Wealstun", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution3", "name": "Moorland", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution3", "name": "Humber", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution3", "name": "Doncaster", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution3", "name": "Leeds", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution3", "name": "Hull", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution3", "name": "Full Sutton", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution3", "name": "Hatfield", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution3", "name": "Lindholme", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution3", "name": "Askham Grange", "locationType": "Unspecified", "genderProvision": "Female"}, - {"contractId": "Evolution3", "name": "New Hall", "locationType": "Unspecified", "genderProvision": "Female"}, - {"contractId": "Evolution4", "name": "Featherstone", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution4", "name": "Drake Hall", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution4", "name": "Birmingham", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution4", "name": "Brinsford", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution4", "name": "Dovegate", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution4", "name": "Hewell", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution4", "name": "Oakwood", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution4", "name": "Stoke Heath", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution4", "name": "Swinfen Hall", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution5", "name": "Ranby", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution5", "name": "Nottingham", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution5", "name": "Five Wells", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution5", "name": "Lincoln", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution5", "name": "North Sea Camp", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution5", "name": "Onley", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution5", "name": "Stocken", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution5", "name": "Whatton", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution5", "name": "Foston Hall", "locationType": "Unspecified", "genderProvision": "Female"}, - {"contractId": "Evolution6", "name": "The Mount", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution6", "name": "Peterborough (M)", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution6", "name": "Bedford", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution6", "name": "Chelmsford", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution6", "name": "Highpoint", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution6", "name": "Hollesley Bay", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution6", "name": "Littlehey", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution6", "name": "Norwich", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution6", "name": "Wayland", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution6", "name": "Peterborough (F)", "locationType": "Unspecified", "genderProvision": "Female"}, - {"contractId": "Evolution7", "name": "High Down", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution7", "name": "Wandsworth", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution7", "name": "Thameside", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution7", "name": "Brixton", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution7", "name": "Feltham", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution7", "name": "Isis", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution7", "name": "Pentonville", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution7", "name": "Bronzefield", "locationType": "Unspecified", "genderProvision": "Female"}, - {"contractId": "Evolution7", "name": "Downview", "locationType": "Unspecified", "genderProvision": "Female"}, - {"contractId": "Evolution8", "name": "Portland", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution8", "name": "Exeter", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution8", "name": "Bristol", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution8", "name": "Channings Wood", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution8", "name": "Dartmoor", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution8", "name": "Leyhill", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution8", "name": "Guys Marsh", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution8", "name": "The Verne", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution8", "name": "Eastwood Park", "locationType": "Unspecified", "genderProvision": "Female"}, - {"contractId": "Evolution9", "name": "Rochester", "locationType": "Wing", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Elmley", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Lewes", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Winchester", "locationType": "Feeder", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Aylesbury", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Bullingdon", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Ford", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Springhill", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Stanford Hill", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Swaleside", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Woodhill", "locationType": "Outlying", "genderProvision": "Male"}, - {"contractId": "Evolution9", "name": "Send", "locationType": "Unspecified", "genderProvision": "Female"}, - {"contractId": "Evolution9", "name": "East Sutton Park", "locationType": "Unspecified", "genderProvision": "Female"} -] diff --git a/src/Infrastructure/Persistence/DataSeeds/Development/Users.json b/src/Infrastructure/Persistence/DataSeeds/Development/Users.json deleted file mode 100644 index 9a8454fb..00000000 --- a/src/Infrastructure/Persistence/DataSeeds/Development/Users.json +++ /dev/null @@ -1,30 +0,0 @@ - [ - { - "FirstName": "Internal", - "LastName": "Admin", - "Email": "Internal.Admin@creatingfutureopportunities.gov.uk", - "Roles": [ - "Internal", - "Administrator" - ], - "Password": "Pass@word1", - "TenantId": "1." - }, - { - "FirstName": "Internal", - "LastName": "User", - "Email": "Internal@creatingfutureopportunities.gov.uk", - "Roles": [ - "Internal" - ], - "Password": "Pass@word2", - "TenantId": "1." - }, - { - "FirstName": "Regular", - "LastName": "User", - "Email": "User@creatingfutureopportunities.gov.uk", - "Password": "Pass@word3", - "TenantId": "1." - } -] \ No newline at end of file diff --git a/src/Infrastructure/Persistence/Initializers/SeedingData.cs b/src/Infrastructure/Persistence/Initializers/SeedingData.cs deleted file mode 100644 index 4cdb74af..00000000 --- a/src/Infrastructure/Persistence/Initializers/SeedingData.cs +++ /dev/null @@ -1,161 +0,0 @@ -using System.Text.Json; -using Cfo.Cats.Application.Common.Exceptions; -using Cfo.Cats.Domain.Common.Enums; -using Cfo.Cats.Domain.Entities.Administration; -using Cfo.Cats.Domain.Identity; -using Polly; - -namespace Cfo.Cats.Infrastructure.Persistence.Initializers; - -public static class SeedingData -{ - - public static IEnumerable GetTenants() - { - yield return Tenant.Create("1.", "CFO", "Root tenant for Creating Future Opportunities"); - yield return Tenant.Create("1.1.", "CFO Evolution", "Top level tenant for Evolution Programme"); - yield return Tenant.Create("1.1.1.", "Alpha", "Alpha"); - yield return Tenant.Create("1.1.2.", "Bravo", "Top level tenant for provider Bravo"); - yield return Tenant.Create("1.1.2.1.", "Bravo (A)", "Bravo (A)"); - yield return Tenant.Create("1.1.2.2.", "Bravo (B)", "Bravo (B)"); - yield return Tenant.Create("1.1.2.3.", "Bravo (C)", "Bravo (C)"); - yield return Tenant.Create("1.1.3.", "Charlie", "Charlie"); - yield return Tenant.Create("1.1.4.", "Delta", "Top level tenant for Delta"); - yield return Tenant.Create("1.1.4.1.", "Delta (A)", "Delta (A)"); - yield return Tenant.Create("1.1.4.2.", "Delta (B)", "Delta (B)"); - yield return Tenant.Create("1.1.5.", "Echo", "Echo"); - yield return Tenant.Create("1.1.6.", "Foxtrot", "Foxtrot"); - } - - public static IEnumerable GetContracts() - { - yield return Contract.Create("Evolution1", 1, "North West", "1.", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Contract.Create("Evolution2", 2, "North East", "1.", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Contract.Create("Evolution3", 3, "Yorkshire and Humberside", "1.", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Contract.Create("Evolution4", 4, "West Midlands", "1.", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Contract.Create("Evolution5", 5, "East Midlands", "1.", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Contract.Create("Evolution6", 6, "East Of England", "1.", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Contract.Create("Evolution7", 7, "London", "1.", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Contract.Create("Evolution8", 8, "South West", "1.", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Contract.Create("Evolution9", 9, "South East", "1.", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - } - - public static IEnumerable GetLocations() - { - yield return Location.Create("Risley", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Lancaster", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Forest Bank", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Altcourse", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Preston", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Buckley Hall", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Liverpool", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Manchester", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Thorn Cross", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Haverigg", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Hindley", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Kirkham", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Wymott", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Styal", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution1", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Holme House", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution2", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Northumberland", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution2", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Durham", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution2", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Kirklevington Grange", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution2", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Low Newton", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution2", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Wealstun", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Moorland", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Humber", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Doncaster", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Leeds", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Hull", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Full Sutton", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Hatfield", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Lindholme", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Askham Grange", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("New Hall", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution3", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Featherstone", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution4", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Drake Hall", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution4", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Birmingham", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution4", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Brinsford", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution4", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Dovegate", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution4", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Hewell", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution4", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Oakwood", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution4", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Stoke Heath", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution4", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Swinfen Hall", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution4", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Ranby", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution5", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Nottingham", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution5", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Five Wells", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution5", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Lincoln", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution5", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("North Sea Camp", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution5", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Onley", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution5", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Stocken", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution5", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Whatton", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution5", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Foston Hall", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution5", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("The Mount", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution6", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Peterborough (M)", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution6", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Bedford", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution6", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Chelmsford", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution6", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Highpoint", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution6", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Hollesley Bay", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution6", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Littlehey", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution6", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Norwich", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution6", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Wayland", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution6", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Peterborough (F)", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution6", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("High Down", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution7", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Wandsworth", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution7", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Thameside", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution7", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Brixton", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution7", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Feltham", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution7", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Isis", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution7", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Pentonville", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution7", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Bronzefield", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution7", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Downview", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution7", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Portland", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution8", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Exeter", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution8", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Bristol", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution8", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Channings Wood", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution8", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Dartmoor", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution8", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Leyhill", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution8", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Guys Marsh", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution8", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("The Verne", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution8", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Eastwood Park", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution8", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Rochester", GenderProvision.FromName("Male"), LocationType.FromName("Wing"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Elmley", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Lewes", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Winchester", GenderProvision.FromName("Male"), LocationType.FromName("Feeder"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Aylesbury", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Bullingdon", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Ford", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Springhill", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Stanford Hill", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Swaleside", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Woodhill", GenderProvision.FromName("Male"), LocationType.FromName("Outlying"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("Send", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - yield return Location.Create("East Sutton Park", GenderProvision.FromName("Female"), LocationType.FromName("Unspecified"), "Evolution9", new DateTime(2024, 5, 1), new DateTime(2029, 03, 31, 23, 59, 59)); - } - - public static IEnumerable GetDictionaries() - { - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "CFO Evolution Provider", Text = "CFO Evolution Provider", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Probation", Text = "Probation", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Approved Premises", Text = "Approved Premises", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "CAS2", Text = "CAS2", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "CAS3", Text = "CAS3", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Custodial Family Services", Text = "Custodial Family Services", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "CRS - Women", Text = "CRS- Women", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "CRS - Personal Wellbeing", Text = "CRS- Personal Wellbeing", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "CRS - Dependency & Recovery", Text = "CRS- Dependency & Recovery", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "CRS - Accommodation", Text = "CRS- Accommodation", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Custody staff", Text = "Custody staff", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "New Futures Network", Text = "New Futures Network", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Prison Education Provider", Text = "Prison Education Provider", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "DWP", Text = "DWP", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Healthcare", Text = "Healthcare", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Community / Voluntary Sector organisation", Text = "Community / Voluntary Sector organisation", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Local Authority", Text = "Local Authority", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Courts", Text = "Courts", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Self-referral", Text = "Self-referral", Description = "A referral source" }; - yield return new KeyValue { Name = Picklist.ReferralSource, Value = "Other", Text = "Other", Description = "A referral source (please state)" }; - - } - -} \ No newline at end of file diff --git a/src/Server.UI/Program.cs b/src/Server.UI/Program.cs index 3de44722..862f7db7 100644 --- a/src/Server.UI/Program.cs +++ b/src/Server.UI/Program.cs @@ -25,7 +25,6 @@ using var scope = app.Services.CreateScope(); var initializer = scope.ServiceProvider.GetRequiredService(); await initializer.InitialiseAsync(); - await initializer.SeedAsync(); } await app.RunAsync(); From 223f05b7d5d3561da328eed322dc516fce91d55d Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Fri, 31 May 2024 17:30:14 +0100 Subject: [PATCH 06/11] CFODEV-456: Remove hardcoded database name from insert script --- db/seed/001_development_seed.sql | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/db/seed/001_development_seed.sql b/db/seed/001_development_seed.sql index 51a4dfc8..e3be75b0 100644 --- a/db/seed/001_development_seed.sql +++ b/db/seed/001_development_seed.sql @@ -1,17 +1,17 @@ -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.', N'CFO', N'Root tenant for Creating Future Opportunities', N'2024-05-31 12:30:38.3849332', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.', N'CFO Evolution', N'Top level tenant for Evolution Programme', N'2024-05-31 12:30:38.3850497', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.1.', N'Alpha', N'Alpha', N'2024-05-31 12:30:38.3850635', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.', N'Bravo', N'Top level tenant for provider Bravo', N'2024-05-31 12:30:38.3850637', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.1.', N'Bravo (A)', N'Bravo (A)', N'2024-05-31 12:30:38.3850640', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.2.', N'Bravo (B)', N'Bravo (B)', N'2024-05-31 12:30:38.3850641', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.3.', N'Bravo (C)', N'Bravo (C)', N'2024-05-31 12:30:38.3850643', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.3.', N'Charlie', N'Charlie', N'2024-05-31 12:30:38.3850645', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.', N'Delta', N'Top level tenant for Delta', N'2024-05-31 12:30:38.3850647', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.1.', N'Delta (A)', N'Delta (A)', N'2024-05-31 12:30:38.3850648', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.2.', N'Delta (B)', N'Delta (B)', N'2024-05-31 12:30:38.3850650', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.5.', N'Echo', N'Echo', N'2024-05-31 12:30:38.3850651', null, null, null); -INSERT INTO CatsDb.dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.6.', N'Foxtrot', N'Foxtrot', N'2024-05-31 12:30:38.3850653', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.', N'CFO', N'Root tenant for Creating Future Opportunities', N'2024-05-31 12:30:38.3849332', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.', N'CFO Evolution', N'Top level tenant for Evolution Programme', N'2024-05-31 12:30:38.3850497', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.1.', N'Alpha', N'Alpha', N'2024-05-31 12:30:38.3850635', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.', N'Bravo', N'Top level tenant for provider Bravo', N'2024-05-31 12:30:38.3850637', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.1.', N'Bravo (A)', N'Bravo (A)', N'2024-05-31 12:30:38.3850640', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.2.', N'Bravo (B)', N'Bravo (B)', N'2024-05-31 12:30:38.3850641', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.3.', N'Bravo (C)', N'Bravo (C)', N'2024-05-31 12:30:38.3850643', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.3.', N'Charlie', N'Charlie', N'2024-05-31 12:30:38.3850645', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.', N'Delta', N'Top level tenant for Delta', N'2024-05-31 12:30:38.3850647', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.1.', N'Delta (A)', N'Delta (A)', N'2024-05-31 12:30:38.3850648', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.2.', N'Delta (B)', N'Delta (B)', N'2024-05-31 12:30:38.3850650', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.5.', N'Echo', N'Echo', N'2024-05-31 12:30:38.3850651', null, null, null); +INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.6.', N'Foxtrot', N'Foxtrot', N'2024-05-31 12:30:38.3850653', null, null, null); GO From ae95558b7a0228ada6a525e2a04f8624553aef1e Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Sat, 1 Jun 2024 16:19:38 +0100 Subject: [PATCH 07/11] Include custody locations (and their parent relationships) in the data seed. --- db/seed/001_development_seed.sql | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/db/seed/001_development_seed.sql b/db/seed/001_development_seed.sql index e3be75b0..8e0a267a 100644 --- a/db/seed/001_development_seed.sql +++ b/db/seed/001_development_seed.sql @@ -143,6 +143,7 @@ GO SET IDENTITY_INSERT Location ON; +-- Insert Custody Locations INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (1, N'Risley', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888014', null, null, null); INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (2, N'Lancaster', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 0, N'2024-05-31 12:30:39.5888012', null, null, null); INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (3, N'Forest Bank', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 0, 1, N'2024-05-31 12:30:39.5888009', null, null, null); @@ -233,4 +234,49 @@ INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, Pare INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (88, N'Send', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888253', null, null, null); INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (89, N'East Sutton Park', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', null, 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +-- Community Locations +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (90, N'North West Community', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (91, N'North East Community', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (92, N'Yorkshire and Humberside Community', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (93, N'West Midlands Community', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (94, N'East Midlands Community', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (95, N'East Of England Community', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (96, N'London Community', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (97, N'South West Community', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (98, N'South East Community', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (99, N'Manchester', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (100, N'Liverpool', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (101, N'Warrington', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 100 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (102, N'Blackpool', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (103, N'Preston', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 102 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (104, N'Blackburn', N'Evolution1', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 102 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (105, N'Durham', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (106, N'Middlesbrough', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 105 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (107, N'Darlington', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 105 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (108, N'Sunderland', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (109, N'Newcastle', N'Evolution2', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 108 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (110, N'Leeds', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (111, N'Bradford', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 110 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (112, N'Huddersfield', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 110 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (113, N'Doncaster', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (114, N'Sheffield', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 113 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (115, N'Hull', N'Evolution3', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (116, N'Birmingham', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (117, N'Wolverhampton', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (118, N'Stoke', N'Evolution4', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 117 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (119, N'Nottingham', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (120, N'Leicester', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 119 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (121, N'Derby', N'Evolution5', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 119 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (122, N'Peterborough', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (123, N'Luton', N'Evolution6', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 122 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (124, N'Croydon', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (125, N'Lambeth', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 124 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (126, N'Lewisham', N'Evolution7', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 124 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (127, N'Bristol', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (128, N'Plymouth', N'Evolution8', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 127 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (129, N'Medway', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', NULL , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (130, N'Southampton', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 129 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); +INSERT INTO dbo.Location (Id, Name, ContractId, LifetimeStart, LifetimeEnd, ParentLocationId, GenderProvisionId, LocationTypeId, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (131, N'Portsmouth', N'Evolution9', N'2024-05-01 00:00:00.0000000', N'2029-03-31 23:59:59.0000000', 129 , 1, 3, N'2024-05-31 12:30:39.5888312', null, null, null); + + SET IDENTITY_INSERT Location OFF; \ No newline at end of file From 685b9762880f54a6457a002ff83e4269cd616937 Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Sat, 1 Jun 2024 16:33:26 +0100 Subject: [PATCH 08/11] Remove the sub tenants. Let's not assume the providers are going to automatically require them --- db/seed/001_development_seed.sql | 5 ----- 1 file changed, 5 deletions(-) diff --git a/db/seed/001_development_seed.sql b/db/seed/001_development_seed.sql index 8e0a267a..d7be3a32 100644 --- a/db/seed/001_development_seed.sql +++ b/db/seed/001_development_seed.sql @@ -3,13 +3,8 @@ INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.', N'CFO Evolution', N'Top level tenant for Evolution Programme', N'2024-05-31 12:30:38.3850497', null, null, null); INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.1.', N'Alpha', N'Alpha', N'2024-05-31 12:30:38.3850635', null, null, null); INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.', N'Bravo', N'Top level tenant for provider Bravo', N'2024-05-31 12:30:38.3850637', null, null, null); -INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.1.', N'Bravo (A)', N'Bravo (A)', N'2024-05-31 12:30:38.3850640', null, null, null); -INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.2.', N'Bravo (B)', N'Bravo (B)', N'2024-05-31 12:30:38.3850641', null, null, null); -INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.2.3.', N'Bravo (C)', N'Bravo (C)', N'2024-05-31 12:30:38.3850643', null, null, null); INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.3.', N'Charlie', N'Charlie', N'2024-05-31 12:30:38.3850645', null, null, null); INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.', N'Delta', N'Top level tenant for Delta', N'2024-05-31 12:30:38.3850647', null, null, null); -INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.1.', N'Delta (A)', N'Delta (A)', N'2024-05-31 12:30:38.3850648', null, null, null); -INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.4.2.', N'Delta (B)', N'Delta (B)', N'2024-05-31 12:30:38.3850650', null, null, null); INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.5.', N'Echo', N'Echo', N'2024-05-31 12:30:38.3850651', null, null, null); INSERT INTO dbo.Tenant (Id, Name, Description, Created, CreatedBy, LastModified, LastModifiedBy) VALUES (N'1.1.6.', N'Foxtrot', N'Foxtrot', N'2024-05-31 12:30:38.3850653', null, null, null); From 9a16fd35016346ecd1c5dac961a966d66042837f Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Sun, 2 Jun 2024 16:59:59 +0100 Subject: [PATCH 09/11] CFODEV-473 : fix tests after merge. Also remove the exclusion for audittrail --- src/Domain/Common/Contracts/IEntity.cs | 2 +- src/Domain/Entities/AuditTrail.cs | 43 ++++++++++++++----- src/Domain/Entities/KeyValue.cs | 6 ++- .../AuditibleEntityInterceptor.cs | 24 ++++------- test/Domain.ArchitectureTests/EntityTests.cs | 5 --- 5 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/Domain/Common/Contracts/IEntity.cs b/src/Domain/Common/Contracts/IEntity.cs index 6f9012fe..35fc4df7 100644 --- a/src/Domain/Common/Contracts/IEntity.cs +++ b/src/Domain/Common/Contracts/IEntity.cs @@ -8,5 +8,5 @@ public interface IEntity public interface IEntity : IEntity { - TId Id { get; set; } + TId Id { get; } } diff --git a/src/Domain/Entities/AuditTrail.cs b/src/Domain/Entities/AuditTrail.cs index 7c67a5dc..21781b68 100644 --- a/src/Domain/Entities/AuditTrail.cs +++ b/src/Domain/Entities/AuditTrail.cs @@ -10,23 +10,44 @@ namespace Cfo.Cats.Domain.Entities; public class AuditTrail : IEntity { - public int Id { get; set; } - public int? UserId { get; set; } - public virtual ApplicationUser? Owner { get; set; } - public AuditType AuditType { get; set; } - public string? TableName { get; set; } - public DateTime DateTime { get; set; } - public Dictionary? OldValues { get; set; } - public Dictionary? NewValues { get; set; } - public List? AffectedColumns { get; set; } - public Dictionary PrimaryKey { get; set; } = new(); - public List TemporaryProperties { get; } = new(); + private AuditTrail() + { + } + + public static AuditTrail Create(string tableName, int? userId, AuditType auditType) + { + return new AuditTrail() + { + TableName = tableName, + UserId = userId, + DateTime = DateTime.UtcNow, + AuditType = auditType, + AffectedColumns = new List(), + NewValues = new Dictionary(), + OldValues = new Dictionary() + }; + } + + + public int Id { get; private set; } + public int? UserId { get; private set; } + public virtual ApplicationUser? Owner { get; private set; } + public AuditType AuditType { get; private set; } + public string? TableName { get; private set; } + public DateTime DateTime { get; private set; } + public Dictionary? OldValues { get; private set; } + public Dictionary? NewValues { get; private set; } + public List? AffectedColumns { get; private set; } + public Dictionary PrimaryKey { get; private set; } = new(); + public List TemporaryProperties { get; private set; } = new(); public bool HasTemporaryProperties => TemporaryProperties.Any(); [NotMapped] public IReadOnlyCollection DomainEvents => new List().AsReadOnly(); public void ClearDomainEvents() { } + + } public enum AuditType diff --git a/src/Domain/Entities/KeyValue.cs b/src/Domain/Entities/KeyValue.cs index 12e73298..6ec63ab2 100644 --- a/src/Domain/Entities/KeyValue.cs +++ b/src/Domain/Entities/KeyValue.cs @@ -7,7 +7,11 @@ namespace Cfo.Cats.Domain.Entities { public class KeyValue : BaseAuditableEntity, IAuditTrial { - + + private KeyValue() + { + } + public Picklist Name { get; set; } = Picklist.ReferralSource; public string? Value { get; set; } public string? Text { get; set; } diff --git a/src/Infrastructure/Persistence/Interceptors/AuditibleEntityInterceptor.cs b/src/Infrastructure/Persistence/Interceptors/AuditibleEntityInterceptor.cs index 41752543..625e4934 100644 --- a/src/Infrastructure/Persistence/Interceptors/AuditibleEntityInterceptor.cs +++ b/src/Infrastructure/Persistence/Interceptors/AuditibleEntityInterceptor.cs @@ -105,24 +105,21 @@ private List TryInsertTemporaryAuditTrail( var temporaryAuditEntries = new List(); foreach (var entry in context.ChangeTracker.Entries()) { - if ( - entry.Entity is AuditTrail - || entry.State == EntityState.Detached - || entry.State == EntityState.Unchanged - ) + if (entry.State is EntityState.Detached or EntityState.Unchanged) { continue; } - var auditEntry = new AuditTrail + AuditType auditType = entry.State switch { - TableName = entry.Entity.GetType().Name, - UserId = userId, - DateTime = dateTime.Now, - AffectedColumns = new List(), - NewValues = new Dictionary(), - OldValues = new Dictionary() + EntityState.Deleted => AuditType.Delete, + EntityState.Modified => AuditType.Update, + EntityState.Added => AuditType.Create, + _ => throw new ArgumentOutOfRangeException($"No audit setup for {entry.State}") }; + + var auditEntry = AuditTrail.Create(entry.Entity.GetType().Name, userId, auditType); + foreach (var property in entry.Properties) { if (property.IsTemporary) @@ -141,7 +138,6 @@ entry.Entity is AuditTrail switch (entry.State) { case EntityState.Added: - auditEntry.AuditType = AuditType.Create; if (property.CurrentValue is not null) { auditEntry.NewValues[propertyName] = property.CurrentValue; @@ -150,7 +146,6 @@ entry.Entity is AuditTrail break; case EntityState.Deleted: - auditEntry.AuditType = AuditType.Delete; if (property.OriginalValue is not null) { auditEntry.OldValues[propertyName] = property.OriginalValue; @@ -171,7 +166,6 @@ property.OriginalValue is not null ) ): auditEntry.AffectedColumns.Add(propertyName); - auditEntry.AuditType = AuditType.Update; auditEntry.OldValues[propertyName] = property.OriginalValue; if (property.CurrentValue is not null) { diff --git a/test/Domain.ArchitectureTests/EntityTests.cs b/test/Domain.ArchitectureTests/EntityTests.cs index 30e48a0d..91a0d338 100644 --- a/test/Domain.ArchitectureTests/EntityTests.cs +++ b/test/Domain.ArchitectureTests/EntityTests.cs @@ -23,11 +23,6 @@ public void Entities_Should_HavePrivateParameterlessConstructor() foreach (var type in entityTypes) { - if (type == typeof(AuditTrail)) - { - continue; - } - var constructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance); if (constructors.Any(c => c.IsPrivate && c.GetParameters().Length == 0) == false) From 21b9ffe2ed880d475dc068c82343ad976149d941 Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Sun, 2 Jun 2024 17:22:32 +0100 Subject: [PATCH 10/11] CFODEV-471: make sure configurations are named correctly --- cats.sln | 9 +---- .../Application.ArchitectureTests.csproj | 29 -------------- test/Application.ArchitectureTests/Class1.cs | 6 --- .../ArchitectureTests.csproj} | 2 + .../AssemblyExtensions.cs | 0 .../DomainEventTests.cs | 0 .../EntityTests.cs | 0 .../EntityTypeConfigurationTests.cs | 39 +++++++++++++++++++ 8 files changed, 42 insertions(+), 43 deletions(-) delete mode 100644 test/Application.ArchitectureTests/Application.ArchitectureTests.csproj delete mode 100644 test/Application.ArchitectureTests/Class1.cs rename test/{Domain.ArchitectureTests/Domain.ArchitectureTests.csproj => ArchitectureTests/ArchitectureTests.csproj} (86%) rename test/{Domain.ArchitectureTests => ArchitectureTests}/AssemblyExtensions.cs (100%) rename test/{Domain.ArchitectureTests => ArchitectureTests}/DomainEventTests.cs (100%) rename test/{Domain.ArchitectureTests => ArchitectureTests}/EntityTests.cs (100%) create mode 100644 test/ArchitectureTests/InfrastructureTests/EntityTypeConfigurationTests.cs diff --git a/cats.sln b/cats.sln index 43c99225..2aed50b5 100644 --- a/cats.sln +++ b/cats.sln @@ -37,9 +37,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{62ABFE2F-D EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application.UnitTests", "test\Application.UnitTests\Application.UnitTests.csproj", "{2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain.ArchitectureTests", "test\Domain.ArchitectureTests\Domain.ArchitectureTests.csproj", "{386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application.ArchitectureTests", "test\Application.ArchitectureTests\Application.ArchitectureTests.csproj", "{7602C41E-1A8C-448D-B29C-CDF8F1E89CEB}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchitectureTests", "test\ArchitectureTests\ArchitectureTests.csproj", "{386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -87,10 +85,6 @@ Global {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}.Debug|Any CPU.Build.0 = Debug|Any CPU {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}.Release|Any CPU.ActiveCfg = Release|Any CPU {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6}.Release|Any CPU.Build.0 = Release|Any CPU - {7602C41E-1A8C-448D-B29C-CDF8F1E89CEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7602C41E-1A8C-448D-B29C-CDF8F1E89CEB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7602C41E-1A8C-448D-B29C-CDF8F1E89CEB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7602C41E-1A8C-448D-B29C-CDF8F1E89CEB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -106,7 +100,6 @@ Global {50485EFF-8E12-4F8A-A087-A9882D2C31C7} = {28581377-5421-47F6-A678-9510117A7791} {2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E} = {62ABFE2F-D4F3-4E44-AA07-20D679B04CF3} {386B9FE9-E2C6-443A-A8EE-D1DC79E867C6} = {62ABFE2F-D4F3-4E44-AA07-20D679B04CF3} - {7602C41E-1A8C-448D-B29C-CDF8F1E89CEB} = {62ABFE2F-D4F3-4E44-AA07-20D679B04CF3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {916B96E7-FFB9-4D43-A9BD-88CB137B2783} diff --git a/test/Application.ArchitectureTests/Application.ArchitectureTests.csproj b/test/Application.ArchitectureTests/Application.ArchitectureTests.csproj deleted file mode 100644 index ea071819..00000000 --- a/test/Application.ArchitectureTests/Application.ArchitectureTests.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - - net8.0 - Cfo.Cats.Application.ArchitectureTests - Cfo.Cats.Application.ArchitectureTests - false - default - - - - - - - - - - - - - - - - - - - - - diff --git a/test/Application.ArchitectureTests/Class1.cs b/test/Application.ArchitectureTests/Class1.cs deleted file mode 100644 index f620e2fe..00000000 --- a/test/Application.ArchitectureTests/Class1.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Application.ArchitectureTests; - -public class Class1 -{ - -} diff --git a/test/Domain.ArchitectureTests/Domain.ArchitectureTests.csproj b/test/ArchitectureTests/ArchitectureTests.csproj similarity index 86% rename from test/Domain.ArchitectureTests/Domain.ArchitectureTests.csproj rename to test/ArchitectureTests/ArchitectureTests.csproj index 0b1f944c..48a5bc50 100644 --- a/test/Domain.ArchitectureTests/Domain.ArchitectureTests.csproj +++ b/test/ArchitectureTests/ArchitectureTests.csproj @@ -22,7 +22,9 @@ + + diff --git a/test/Domain.ArchitectureTests/AssemblyExtensions.cs b/test/ArchitectureTests/AssemblyExtensions.cs similarity index 100% rename from test/Domain.ArchitectureTests/AssemblyExtensions.cs rename to test/ArchitectureTests/AssemblyExtensions.cs diff --git a/test/Domain.ArchitectureTests/DomainEventTests.cs b/test/ArchitectureTests/DomainEventTests.cs similarity index 100% rename from test/Domain.ArchitectureTests/DomainEventTests.cs rename to test/ArchitectureTests/DomainEventTests.cs diff --git a/test/Domain.ArchitectureTests/EntityTests.cs b/test/ArchitectureTests/EntityTests.cs similarity index 100% rename from test/Domain.ArchitectureTests/EntityTests.cs rename to test/ArchitectureTests/EntityTests.cs diff --git a/test/ArchitectureTests/InfrastructureTests/EntityTypeConfigurationTests.cs b/test/ArchitectureTests/InfrastructureTests/EntityTypeConfigurationTests.cs new file mode 100644 index 00000000..708cbced --- /dev/null +++ b/test/ArchitectureTests/InfrastructureTests/EntityTypeConfigurationTests.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Cfo.Cats.Application.Pipeline; +using FluentAssertions; +using Microsoft.EntityFrameworkCore; +using NUnit.Framework; + +namespace Cfo.Cats.Domain.ArchitectureTests.InfrastructureTests; + +public class EntityConfigurationTests +{ + private static readonly Assembly InfrastructureAssembly = typeof(Infrastructure.DependencyInjection).Assembly; + + [Test] + public void EntityConfigurations_Should_HaveConfigurationPostfix() + { + var types = InfrastructureAssembly.GetTypes() + .Where(type => !type.IsAbstract && !type.IsInterface) + .Where(type => type.GetInterfaces() + .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>))) + .ToList(); + + var failingTypes = new List(); + + foreach (var type in types) + { + if (type.Name.EndsWith("Configuration") == false) + { + failingTypes.Add(type); + } + } + + failingTypes.Should().BeEmpty(); + + } + +} \ No newline at end of file From 2a5ce9eb24621f2c24a2f4edccc1f8a4a4190de0 Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Sun, 2 Jun 2024 20:22:44 +0100 Subject: [PATCH 11/11] CFODEV-472 throw an exception if not authorize attribute exists (or we do not explicitly allow anonymous). Tests added to break the build if these are detected at run time. (breaks the build as we have not yet added the authorise test to any command) --- .../Security/AllowAnonymousAttribute.cs | 6 + .../Security/RequestAuthorizeAttribute.cs | 3 +- .../Pipeline/AuthorizationBehaviour.cs | 103 ++++++++++-------- .../ApplicationTests/RequestTests.cs | 47 ++++++++ 4 files changed, 112 insertions(+), 47 deletions(-) create mode 100644 src/Application/Common/Security/AllowAnonymousAttribute.cs create mode 100644 test/ArchitectureTests/ApplicationTests/RequestTests.cs diff --git a/src/Application/Common/Security/AllowAnonymousAttribute.cs b/src/Application/Common/Security/AllowAnonymousAttribute.cs new file mode 100644 index 00000000..2279b055 --- /dev/null +++ b/src/Application/Common/Security/AllowAnonymousAttribute.cs @@ -0,0 +1,6 @@ +namespace Cfo.Cats.Application.Common.Security; + +[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] +public class AllowAnonymousAttribute : Attribute +{ +} \ No newline at end of file diff --git a/src/Application/Common/Security/RequestAuthorizeAttribute.cs b/src/Application/Common/Security/RequestAuthorizeAttribute.cs index 55f6cfd3..c5552982 100644 --- a/src/Application/Common/Security/RequestAuthorizeAttribute.cs +++ b/src/Application/Common/Security/RequestAuthorizeAttribute.cs @@ -2,6 +2,7 @@ namespace Cfo.Cats.Application.Common.Security; + public class RequestAuthorizeAttribute : Attribute { /// @@ -18,4 +19,4 @@ public RequestAuthorizeAttribute() { } /// Gets or sets the policy name that determines access to the resource. /// public string Policy { get; set; } = string.Empty; -} +} \ No newline at end of file diff --git a/src/Application/Pipeline/AuthorizationBehaviour.cs b/src/Application/Pipeline/AuthorizationBehaviour.cs index c03d786e..76e74b52 100644 --- a/src/Application/Pipeline/AuthorizationBehaviour.cs +++ b/src/Application/Pipeline/AuthorizationBehaviour.cs @@ -29,68 +29,79 @@ CancellationToken cancellationToken .GetType() .GetCustomAttributes() .ToArray(); - if (authorizeAttributes.Any()) + + if (authorizeAttributes.Any() == false) { - // Must be authenticated user - var userId = currentUserService.UserId; - if (userId is null or 0) + // if we have no authorization attribute, then we must explicitly allow all or error + var anyUserAttributes = request.GetType() + .GetCustomAttributes() + .SingleOrDefault(); + + if (anyUserAttributes == null) { - throw new UnauthorizedAccessException(); + throw new UnauthorizedAccessException("Invalid authorization configuration."); } + } - // DefaultRole-based authorization - var authorizeAttributesWithRoles = authorizeAttributes - .Where(a => !string.IsNullOrWhiteSpace(a.Roles)) - .ToArray(); + // Must be authenticated user + var userId = currentUserService.UserId; + if (userId is null or 0) + { + throw new UnauthorizedAccessException(); + } - if (authorizeAttributesWithRoles.Any()) - { - var authorized = false; + // DefaultRole-based authorization + var authorizeAttributesWithRoles = authorizeAttributes + .Where(a => !string.IsNullOrWhiteSpace(a.Roles)) + .ToArray(); + + if (authorizeAttributesWithRoles.Any()) + { + var authorized = false; - foreach (var roles in authorizeAttributesWithRoles.Select(a => a.Roles.Split(','))) + foreach (var roles in authorizeAttributesWithRoles.Select(a => a.Roles.Split(','))) + { + foreach (var role in roles) { - foreach (var role in roles) + var isInRole = await identityService.IsInRoleAsync( + userId.Value, + role.Trim(), + cancellationToken + ); + if (isInRole) { - var isInRole = await identityService.IsInRoleAsync( - userId.Value, - role.Trim(), - cancellationToken - ); - if (isInRole) - { - authorized = true; - break; - } + authorized = true; + break; } } + } - // Must be a member of at least one role in roles - if (!authorized) - { - throw new ForbiddenException("You are not authorized to access this resource."); - } + // Must be a member of at least one role in roles + if (!authorized) + { + throw new ForbiddenException("You are not authorized to access this resource."); } + } - // Policy-based authorization - var authorizeAttributesWithPolicies = authorizeAttributes - .Where(a => !string.IsNullOrWhiteSpace(a.Policy)) - .ToArray(); - if (authorizeAttributesWithPolicies.Any()) + // Policy-based authorization + var authorizeAttributesWithPolicies = authorizeAttributes + .Where(a => !string.IsNullOrWhiteSpace(a.Policy)) + .ToArray(); + if (authorizeAttributesWithPolicies.Any()) + { + foreach (var policy in authorizeAttributesWithPolicies.Select(a => a.Policy)) { - foreach (var policy in authorizeAttributesWithPolicies.Select(a => a.Policy)) + var authorized = await identityService.AuthorizeAsync( + userId.Value, + policy, + cancellationToken + ); + + if (!authorized) { - var authorized = await identityService.AuthorizeAsync( - userId.Value, - policy, - cancellationToken + throw new ForbiddenException( + "You are not authorized to access this resource." ); - - if (!authorized) - { - throw new ForbiddenException( - "You are not authorized to access this resource." - ); - } } } } diff --git a/test/ArchitectureTests/ApplicationTests/RequestTests.cs b/test/ArchitectureTests/ApplicationTests/RequestTests.cs new file mode 100644 index 00000000..fce091dc --- /dev/null +++ b/test/ArchitectureTests/ApplicationTests/RequestTests.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Cfo.Cats.Application.Common.Interfaces.Caching; +using Cfo.Cats.Application.Common.Security; +using Cfo.Cats.Domain.Common; +using FluentAssertions; +using MediatR; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; +using NetArchTest.Rules; +using NUnit.Framework; + +namespace Cfo.Cats.Domain.ArchitectureTests.ApplicationTests; + +public class RequestTests +{ + private static readonly Assembly ApplicationAssembly = typeof(Application.DependencyInjection).Assembly; + + [Test] + public void Commands_Should_HaveAuthorizeAttribute() + { + var result = Types.InAssembly(ApplicationAssembly) + .That() + .ImplementInterface(typeof(IRequest<>)) + .Or() + .ImplementInterface(typeof(ICacheableRequest<>)) + .Or() + .ImplementInterface(typeof(ICacheInvalidatorRequest<>)) + .Should() + .HaveCustomAttribute(typeof(AuthorAttribute)) + .Or() + .HaveCustomAttribute(typeof(AllowAnonymousAttribute)) + .GetResult(); + + var failedTypes = result.FailingTypes?.Select(t => t.FullName).ToList(); + + var formattedFailedTypes = failedTypes == null ? "None" : string.Join("\n", failedTypes); + + result.IsSuccessful + .Should() + .BeTrue($"The following types failed the test:\n {formattedFailedTypes}"); + + } + + +} \ No newline at end of file