-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/DP-689-request-to-join-notify
- Loading branch information
Showing
17 changed files
with
3,171 additions
and
19 deletions.
There are no files selected for viewing
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
35 changes: 32 additions & 3 deletions
35
Services/CO.CDP.DataSharing.WebApi.Tests/AutoMapper/AutoMapperFixture.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 |
---|---|---|
@@ -1,13 +1,42 @@ | ||
using AutoMapper; | ||
using CO.CDP.DataSharing.WebApi.AutoMapper; | ||
using CO.CDP.Localization; | ||
using Microsoft.AspNetCore.Mvc.Localization; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
|
||
namespace CO.CDP.DataSharing.WebApi.Tests.AutoMapper; | ||
|
||
public class AutoMapperFixture | ||
{ | ||
public IMapper Mapper => Configuration.CreateMapper(); | ||
|
||
public readonly MapperConfiguration Configuration = new( | ||
config => config.AddProfile<DataSharingProfile>() | ||
); | ||
} | ||
|
||
public IMapper Mapper { get; } | ||
|
||
public AutoMapperFixture() | ||
{ | ||
var localizerMock = new Mock<IHtmlLocalizer<FormsEngineResource>>(); | ||
|
||
localizerMock.Setup(l => l[It.IsAny<string>()]) | ||
.Returns((string key) => | ||
{ | ||
if (key == "FinancialInformation_SectionTitle") | ||
{ | ||
return new LocalizedHtmlString("FinancialInformation_SectionTitle", "Financial Information"); | ||
} | ||
|
||
return new LocalizedHtmlString(key, key); | ||
}); | ||
|
||
var services = new ServiceCollection(); | ||
services.AddSingleton<IHtmlLocalizer<FormsEngineResource>>(localizerMock.Object); | ||
services.AddTransient(typeof(NullableLocalizedPropertyResolver<,>)); | ||
services.AddTransient(typeof(LocalizedPropertyResolver<,>)); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
Mapper = Configuration.CreateMapper(type => serviceProvider.GetService(type) ?? Activator.CreateInstance(type)); | ||
} | ||
} |
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
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
40 changes: 40 additions & 0 deletions
40
Services/CO.CDP.DataSharing.WebApi/AutoMapper/LocalizedPropertyResolver.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,40 @@ | ||
using AutoMapper; | ||
using CO.CDP.Localization; | ||
using Microsoft.AspNetCore.Mvc.Localization; | ||
|
||
namespace CO.CDP.DataSharing.WebApi.AutoMapper; | ||
|
||
public class LocalizedPropertyResolver<TSource, TDestination> : IMemberValueResolver<TSource, TDestination, string, string> | ||
{ | ||
private readonly IHtmlLocalizer<FormsEngineResource> _localizer; | ||
|
||
public LocalizedPropertyResolver(IHtmlLocalizer<FormsEngineResource> localizer) | ||
{ | ||
_localizer = localizer; | ||
} | ||
|
||
public string Resolve(TSource source, TDestination destination, string sourceMember, string destMember, ResolutionContext context) | ||
{ | ||
return _localizer[sourceMember].Value; | ||
} | ||
} | ||
|
||
public class NullableLocalizedPropertyResolver<TSource, TDestination> : IMemberValueResolver<TSource, TDestination, string?, string?> | ||
{ | ||
private readonly IHtmlLocalizer<FormsEngineResource> _localizer; | ||
|
||
public NullableLocalizedPropertyResolver(IHtmlLocalizer<FormsEngineResource> localizer) | ||
{ | ||
_localizer = localizer; | ||
} | ||
|
||
public string? Resolve(TSource? source, TDestination? destination, string? sourceMember, string? destMember, ResolutionContext context) | ||
{ | ||
if (sourceMember == null) | ||
{ | ||
return null; | ||
} | ||
|
||
return _localizer[sourceMember].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
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
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
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.