-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60fdf10
commit 4859b0f
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/Altinn.Notifications.Core/Services/ApplicationOwnerConfigService.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,36 @@ | ||
using Altinn.Notifications.Core.Models; | ||
using Altinn.Notifications.Core.Repository.Interfaces; | ||
using Altinn.Notifications.Core.Services.Interfaces; | ||
|
||
namespace Altinn.Notifications.Core.Services; | ||
|
||
/// <summary> | ||
/// An implementation of <see cref="IApplicationOwnerConfigService"/> with the necessary business logic | ||
/// to handle application owner specific configuration in the Notifications application. | ||
/// </summary> | ||
public class ApplicationOwnerConfigService : IApplicationOwnerConfigService | ||
{ | ||
private readonly IApplicationOwnerConfigRepository _applicationOwnerConfigRepository; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ApplicationOwnerConfigService"/> class. | ||
/// </summary> | ||
/// <param name="applicationOwnerConfigRepository">A repository implementation</param> | ||
public ApplicationOwnerConfigService(IApplicationOwnerConfigRepository applicationOwnerConfigRepository) | ||
{ | ||
_applicationOwnerConfigRepository = applicationOwnerConfigRepository; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task<ApplicationOwnerConfig> GetApplicationOwnerConfig(string orgId) | ||
{ | ||
return await _applicationOwnerConfigRepository.GetApplicationOwnerConfig(orgId) | ||
?? new ApplicationOwnerConfig(orgId); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task WriteApplicationOwnerConfig(ApplicationOwnerConfig applicationOwnerConfig) | ||
{ | ||
await _applicationOwnerConfigRepository.WriteApplicationOwnerConfig(applicationOwnerConfig); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Altinn.Notifications.Core/Services/Interfaces/IApplicationOwnerConfigService.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,25 @@ | ||
using Altinn.Notifications.Core.Models; | ||
|
||
namespace Altinn.Notifications.Core.Services.Interfaces; | ||
|
||
/// <summary> | ||
/// This interface is a description of an application owner configuration service implementation. | ||
/// Such a service will be required to have methods needed to register, change and retrieve application | ||
/// owner configuration. | ||
/// </summary> | ||
public interface IApplicationOwnerConfigService | ||
{ | ||
/// <summary> | ||
/// Get the full set of configuration options for a specified application owner. | ||
/// </summary> | ||
/// <param name="orgId">The unique id of an application owner.</param> | ||
/// <returns>A <see cref="Task{ApplicationOwnerConfig}"/> representing the result of the asynchronous operation.</returns> | ||
Task<ApplicationOwnerConfig> GetApplicationOwnerConfig(string orgId); | ||
|
||
/// <summary> | ||
/// Write a full <see cref="ApplicationOwnerConfig"/> object to storage. | ||
/// </summary> | ||
/// <param name="applicationOwnerConfig">The configuration object to write to storage.</param> | ||
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns> | ||
Task WriteApplicationOwnerConfig(ApplicationOwnerConfig applicationOwnerConfig); | ||
} |
74 changes: 74 additions & 0 deletions
74
...ifications.Tests/Notifications.Core/TestingServices/ApplicationOwnerConfigServiceTests.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,74 @@ | ||
using System.Threading.Tasks; | ||
|
||
using Altinn.Notifications.Core.Models; | ||
using Altinn.Notifications.Core.Repository.Interfaces; | ||
using Altinn.Notifications.Core.Services; | ||
|
||
using Moq; | ||
|
||
using Xunit; | ||
|
||
namespace Altinn.Notifications.Tests.Notifications.Core.TestingServices; | ||
|
||
public class ApplicationOwnerConfigServiceTests | ||
{ | ||
[Fact] | ||
public async Task GetApplicationOwnerConfigTest_Repository_returns_found_config_Service_returns_found_config() | ||
{ | ||
// Arrange | ||
const string OrgId = "exists"; | ||
|
||
Mock<IApplicationOwnerConfigRepository> repositoryMock = new(); | ||
repositoryMock.Setup(a => a.GetApplicationOwnerConfig(It.Is<string>(o => o == OrgId))) | ||
.ReturnsAsync(new ApplicationOwnerConfig(OrgId)); | ||
|
||
ApplicationOwnerConfigService target = new ApplicationOwnerConfigService(repositoryMock.Object); | ||
|
||
// Act | ||
var actual = await target.GetApplicationOwnerConfig(OrgId); | ||
|
||
// Assert | ||
repositoryMock.VerifyAll(); | ||
|
||
Assert.NotNull(actual); | ||
} | ||
|
||
[Fact] | ||
public async Task GetApplicationOwnerConfigTest_Repository_returns_null_Service_returns_empty_config() | ||
{ | ||
// Arrange | ||
const string OrgId = "wrong"; | ||
|
||
Mock<IApplicationOwnerConfigRepository> repositoryMock = new(); | ||
repositoryMock.Setup(a => a.GetApplicationOwnerConfig(It.Is<string>(o => o == OrgId))) | ||
.ReturnsAsync((ApplicationOwnerConfig?)null); | ||
|
||
ApplicationOwnerConfigService target = new ApplicationOwnerConfigService(repositoryMock.Object); | ||
|
||
// Act | ||
var actual = await target.GetApplicationOwnerConfig(OrgId); | ||
|
||
// Assert | ||
repositoryMock.VerifyAll(); | ||
|
||
Assert.NotNull(actual); | ||
} | ||
|
||
[Fact] | ||
public async Task WriteApplicationOwnerConfigTest_Repository_returns_null_Service_returns_empty_config() | ||
{ | ||
// Arrange | ||
const string OrgId = "exists"; | ||
|
||
Mock<IApplicationOwnerConfigRepository> repositoryMock = new(); | ||
repositoryMock.Setup(a => a.WriteApplicationOwnerConfig(It.Is<ApplicationOwnerConfig>(c => c.OrgId == OrgId))); | ||
|
||
ApplicationOwnerConfigService target = new ApplicationOwnerConfigService(repositoryMock.Object); | ||
|
||
// Act | ||
await target.WriteApplicationOwnerConfig(new ApplicationOwnerConfig(OrgId)); | ||
|
||
// Assert | ||
repositoryMock.VerifyAll(); | ||
} | ||
} |