-
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 #757 from DFE-Digital/feature/191269-change-grant-…
…comms Feature/191269 change grant comms
- Loading branch information
Showing
21 changed files
with
374 additions
and
114 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
Dfe.Academies.External.Web.UnitTest/FeatureManagement/ConversionGrantExpiryFeatureTests.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,87 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using Dfe.Academies.External.Web.FeatureManagement; | ||
using Dfe.Academies.External.Web.UnitTest.MockSetUp; | ||
using Microsoft.FeatureManagement; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace Dfe.Academies.External.Web.UnitTest.FeatureManagement | ||
{ | ||
[TestFixture] | ||
public class ConversionGrantExpiryFeatureTests | ||
{ | ||
private Mock<IFeatureManager> _mockFeatureManager = null!; | ||
private static readonly Fixture Fixture = new(); | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_mockFeatureManager = new Mock<IFeatureManager>(); | ||
} | ||
|
||
[TestCase(false, "3024-11-10T09:13:00Z")] | ||
[TestCase(false, "")] | ||
public async Task IsEnabledAsync_NotExpired_ReturnsFalseAsync(bool isConversionGrantExpired,string conversionGrantExpiry) | ||
{ | ||
//Arrange | ||
var inMemorySettings = new Dictionary<string, string> | ||
{ | ||
{ "FeatureManagement:IsConversionGrantExpired", isConversionGrantExpired.ToString() }, | ||
{ "FeatureManagement:ConversionGrantExpiry", conversionGrantExpiry } | ||
}; | ||
_mockFeatureManager.Setup(x => x.IsEnabledAsync("IsConversionGrantExpired")).ReturnsAsync(isConversionGrantExpired); | ||
|
||
var feature = new ConversionGrantExpiryFeature(ConfigurationMock.GetMockedConfiguration(inMemorySettings), _mockFeatureManager.Object); | ||
|
||
//Action | ||
var result = await feature.IsEnabledAsync(); | ||
|
||
//Assert | ||
Assert.That(result, Is.False); | ||
} | ||
|
||
[TestCase(true, "3024-11-10T09:13:00Z")] | ||
[TestCase(false, "2024-11-10T09:13:00Z")] | ||
public async Task IsEnabledAsync_Expired_ReturnsTrueAsync(bool isConversionGrantExpired, string conversionGrantExpiry) | ||
{ | ||
//Arrange | ||
var inMemorySettings = new Dictionary<string, string> | ||
{ | ||
{ "FeatureManagement:IsConversionGrantExpired", isConversionGrantExpired.ToString() }, | ||
{ "FeatureManagement:ConversionGrantExpiry", conversionGrantExpiry } | ||
}; | ||
_mockFeatureManager.Setup(x => x.IsEnabledAsync("IsConversionGrantExpired")).ReturnsAsync(isConversionGrantExpired); | ||
|
||
var feature = new ConversionGrantExpiryFeature(ConfigurationMock.GetMockedConfiguration(inMemorySettings), _mockFeatureManager.Object); | ||
|
||
//Action | ||
var result = await feature.IsEnabledAsync(); | ||
|
||
//Assert | ||
Assert.That(result, Is.True); | ||
} | ||
|
||
[TestCase("2024-11-13T09:13:00Z", "2024-11-10T09:13:00Z", true)] | ||
[TestCase("2024-11-09T09:13:00Z", "2024-11-10T09:13:00Z", false)] | ||
[TestCase("2024-11-09T09:13:00Z", "", false)] | ||
public void IsNewApplication_Expired_Returns_CorrectResponse(string applicationCreatedOn, string conversionGrantExpiry, bool expectedResult) | ||
{ | ||
//Arrange | ||
var inMemorySettings = new Dictionary<string, string> | ||
{ | ||
{ "FeatureManagement:ConversionGrantExpiry", conversionGrantExpiry } | ||
}; | ||
|
||
var feature = new ConversionGrantExpiryFeature(ConfigurationMock.GetMockedConfiguration(inMemorySettings), _mockFeatureManager.Object); | ||
DateTime.TryParse(applicationCreatedOn, out DateTime applicationCreatedDateTime); | ||
|
||
//Action | ||
var result = feature.IsNewApplication(applicationCreatedDateTime); | ||
|
||
//Assert | ||
Assert.That(result, Is.EqualTo(expectedResult)); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Dfe.Academies.External.Web.UnitTest/MockSetUp/ConfigurationMock.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,16 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Dfe.Academies.External.Web.UnitTest.MockSetUp | ||
{ | ||
public class ConfigurationMock | ||
{ | ||
public static IConfiguration GetMockedConfiguration(Dictionary<string, string> settings) | ||
{ | ||
var configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(settings!) | ||
.Build(); | ||
return configuration; | ||
} | ||
} | ||
} |
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.