-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from DFE-Digital/113209-fam-invite-a-contributor
Refactored email service and added join a mat templating
- Loading branch information
Showing
22 changed files
with
313 additions
and
75 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Dfe.Academies.External.Web.UnitTest/AutoPopulatedMoqPropertiesCustomization.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using AutoFixture; | ||
using AutoFixture.AutoMoq; | ||
using AutoFixture.Kernel; | ||
|
||
namespace Dfe.Academies.External.Web.UnitTest; | ||
|
||
public class AutoPopulatedMoqPropertiesCustomization : ICustomization | ||
{ | ||
public void Customize(IFixture fixture) | ||
{ | ||
fixture.Customizations.Add( | ||
new PropertiesPostprocessor( | ||
new MockPostprocessor( | ||
new MethodInvoker( | ||
new MockConstructorQuery())))); | ||
fixture.ResidueCollectors.Add(new MockRelay()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Dfe.Academies.External.Web.UnitTest/Automapper/AutoMapperSetupTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using AutoFixture; | ||
using AutoMapper; | ||
using AutoMapper.Internal; | ||
using Dfe.Academies.External.Web.AutoMapper; | ||
using Dfe.Academies.External.Web.Dtos; | ||
using Dfe.Academies.External.Web.Models.EmailTemplates; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace Dfe.Academies.External.Web.UnitTest.Automapper | ||
{ | ||
public class AutoMapperSetupTests | ||
{ | ||
private Fixture _fixture = new Fixture(); | ||
private IMapper _mapper; | ||
public AutoMapperSetupTests() | ||
{ | ||
_fixture.Customize(new AutoPopulatedMoqPropertiesCustomization()); | ||
|
||
var mapperConfig = new MapperConfiguration(cfg => | ||
{ | ||
cfg.AddProfile<AutoMapperProfile>(); | ||
}); | ||
|
||
mapperConfig.AssertConfigurationIsValid(); | ||
_mapper = new Mapper(mapperConfig); | ||
} | ||
|
||
[Test] | ||
public void Map_WhenGivenEmailVariablesDto_ReturnsDictionary() | ||
{ | ||
var emailTemplate = _fixture.Create<EmailVariablesDto>(); | ||
var result = _mapper.Map<IDictionary<string, dynamic>>(emailTemplate); | ||
foreach (var propertyInfo in emailTemplate.GetType().GetProperties()) | ||
{ | ||
var value = propertyInfo.GetValue(emailTemplate, null); | ||
result.Values.Should().Contain(value); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Dfe.Academies.External.Web.UnitTest/PropertiesPostprocessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using AutoFixture.Kernel; | ||
|
||
namespace Dfe.Academies.External.Web.UnitTest; | ||
|
||
public class PropertiesPostprocessor : ISpecimenBuilder | ||
{ | ||
private readonly ISpecimenBuilder builder; | ||
|
||
public PropertiesPostprocessor(ISpecimenBuilder builder) | ||
{ | ||
this.builder = builder; | ||
} | ||
|
||
public object Create(object request, ISpecimenContext context) | ||
{ | ||
dynamic s = this.builder.Create(request, context); | ||
if (s is NoSpecimen) | ||
return s; | ||
|
||
s.SetupAllProperties(); | ||
return s; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using AutoMapper; | ||
|
||
namespace Dfe.Academies.External.Web.AutoMapper; | ||
|
||
public class AutoMapperProfile : Profile | ||
{ | ||
public AutoMapperProfile() => AutoMapperSetup.AddMappings(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using AutoMapper; | ||
using Dfe.Academies.External.Web.Dtos; | ||
|
||
namespace Dfe.Academies.External.Web.AutoMapper; | ||
|
||
public static class AutoMapperSetup | ||
{ | ||
public static void AddMappings(Profile profile) | ||
{ | ||
profile.CreateMap<EmailVariablesDto, Dictionary<string, dynamic>>() | ||
.ConvertUsing(x => new Dictionary<string, dynamic> | ||
{ | ||
{"invitee_name", x.ContributorName}, | ||
{"school", x.SchoolName}, | ||
{"inviting_contributor", x.InvitingUsername} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Dfe.Academies.External.Web.Dtos; | ||
|
||
public record EmailVariablesDto | ||
{ | ||
public string ContributorName { get; set; } | ||
public string SchoolName { get; set; } | ||
public string InvitingUsername { get; set; } | ||
} |
19 changes: 19 additions & 0 deletions
19
Dfe.Academies.External.Web/Factories/ContributorNotifyTemplateFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Dfe.Academies.External.Web.Enums; | ||
using Dfe.Academies.External.Web.Models.EmailTemplates; | ||
|
||
namespace Dfe.Academies.External.Web.Factories; | ||
|
||
public class ContributorNotifyTemplateFactory : IContributorNotifyTemplateFactory | ||
{ | ||
private readonly List<IContributorTemplate> _emailTemplates; | ||
|
||
public ContributorNotifyTemplateFactory(IEnumerable<IContributorTemplate> emailTemplates) | ||
{ | ||
_emailTemplates = emailTemplates.ToList(); | ||
} | ||
public IContributorTemplate Get(ApplicationTypes applicationType, SchoolRoles schoolRole) | ||
{ | ||
return _emailTemplates.First(x => | ||
x.ApplicationType == applicationType && x.SchoolRole == schoolRole); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Dfe.Academies.External.Web/Factories/IContributorNotifyTemplateFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Dfe.Academies.External.Web.Enums; | ||
using Dfe.Academies.External.Web.Models.EmailTemplates; | ||
|
||
namespace Dfe.Academies.External.Web.Factories | ||
{ | ||
public interface IContributorNotifyTemplateFactory | ||
{ | ||
IContributorTemplate Get(ApplicationTypes applicationType, SchoolRoles schoolRole); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Dfe.Academies.External.Web/Helpers/NotifyTemplateSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Dfe.Academies.External.Web.Helpers | ||
{ | ||
public class NotifyTemplateSettings | ||
{ | ||
public string JamChairTemplateId { get; set; } | ||
public string JamNonChairTemplateId { get; set; } | ||
public string FamChairTemplateId { get; set; } | ||
public string FamNonChairTemplateId { get; set; } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Dfe.Academies.External.Web/Models/EmailTemplates/FormAMatChairContributor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Dynamic; | ||
using Dfe.Academies.External.Web.Enums; | ||
using Dfe.Academies.External.Web.Helpers; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Dfe.Academies.External.Web.Models.EmailTemplates | ||
{ | ||
public class FormAMatChairContributor : IContributorTemplate | ||
{ | ||
public ApplicationTypes ApplicationType => ApplicationTypes.FormAMat; | ||
public SchoolRoles SchoolRole => SchoolRoles.ChairOfGovernors; | ||
public string TemplateId { get; } | ||
|
||
public FormAMatChairContributor(IOptions<NotifyTemplateSettings> notifyTemplateSettings) | ||
{ | ||
TemplateId = notifyTemplateSettings.Value.FamChairTemplateId; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Dfe.Academies.External.Web/Models/EmailTemplates/FormAMatNonChairContributor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Dfe.Academies.External.Web.Enums; | ||
using Dfe.Academies.External.Web.Helpers; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Dfe.Academies.External.Web.Models.EmailTemplates | ||
{ | ||
public class FormAMatNonChairContributor : IContributorTemplate | ||
{ | ||
public ApplicationTypes ApplicationType => ApplicationTypes.FormAMat; | ||
public SchoolRoles SchoolRole => SchoolRoles.Other; | ||
public string TemplateId { get; } | ||
|
||
public FormAMatNonChairContributor(IOptions<NotifyTemplateSettings> notifyTemplateSettings) | ||
{ | ||
TemplateId = notifyTemplateSettings.Value.FamNonChairTemplateId; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Dfe.Academies.External.Web/Models/EmailTemplates/IContributorTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Dfe.Academies.External.Web.Enums; | ||
|
||
namespace Dfe.Academies.External.Web.Models.EmailTemplates | ||
{ | ||
public interface IContributorTemplate : IEmailTemplate | ||
{ | ||
public SchoolRoles SchoolRole { get; } | ||
public ApplicationTypes ApplicationType { get; } | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Dfe.Academies.External.Web/Models/EmailTemplates/IEmailTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Dfe.Academies.External.Web.Models.EmailTemplates; | ||
|
||
public interface IEmailTemplate | ||
{ | ||
public string TemplateId { get; } | ||
} |
19 changes: 19 additions & 0 deletions
19
Dfe.Academies.External.Web/Models/EmailTemplates/JoinAMatChairContributor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Dynamic; | ||
using Dfe.Academies.External.Web.Enums; | ||
using Dfe.Academies.External.Web.Helpers; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Dfe.Academies.External.Web.Models.EmailTemplates | ||
{ | ||
public class JoinAMatChairContributor : IContributorTemplate | ||
{ | ||
public ApplicationTypes ApplicationType => ApplicationTypes.JoinAMat; | ||
public SchoolRoles SchoolRole => SchoolRoles.ChairOfGovernors; | ||
public string TemplateId { get; } | ||
|
||
public JoinAMatChairContributor(IOptions<NotifyTemplateSettings> notifyTemplateSettings) | ||
{ | ||
TemplateId = notifyTemplateSettings.Value.JamChairTemplateId; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Dfe.Academies.External.Web/Models/EmailTemplates/JoinAMatNonChairContributor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Dynamic; | ||
using Dfe.Academies.External.Web.Enums; | ||
using Dfe.Academies.External.Web.Helpers; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Dfe.Academies.External.Web.Models.EmailTemplates | ||
{ | ||
public class JoinAMatNonChairContributor : IContributorTemplate | ||
{ | ||
public ApplicationTypes ApplicationType => ApplicationTypes.JoinAMat; | ||
public SchoolRoles SchoolRole => SchoolRoles.Other; | ||
public string TemplateId { get; } | ||
|
||
public JoinAMatNonChairContributor(IOptions<NotifyTemplateSettings> notifyTemplateSettings) | ||
{ | ||
TemplateId = notifyTemplateSettings.Value.JamNonChairTemplateId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.