Skip to content

Commit

Permalink
Merge pull request #757 from DFE-Digital/feature/191269-change-grant-…
Browse files Browse the repository at this point in the history
…comms

Feature/191269 change grant comms
  • Loading branch information
mshakirdfe authored Dec 10, 2024
2 parents e3cd565 + eec8141 commit e174a28
Show file tree
Hide file tree
Showing 21 changed files with 374 additions and 114 deletions.
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 Dfe.Academies.External.Web.UnitTest/MockSetUp/ConfigurationMock.cs
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using AutoFixture;
using Dfe.Academies.External.Web.Dtos;
using Dfe.Academies.External.Web.FeatureManagement;
using Dfe.Academies.External.Web.Models;
using Dfe.Academies.External.Web.Services;
using Dfe.Academies.External.Web.UnitTest.Factories;
Expand Down Expand Up @@ -98,7 +99,8 @@ public async Task AddSchoolToApplication___ApiReturns200___Ok()
var mockLoggerCreationService = new Mock<ILogger<ConversionApplicationService>>();
var mockLoggerRetrievalService = new Mock<ILogger<ConversionApplicationRetrievalService>>();
var mockFileUploadService = new Mock<IFileUploadService>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()));
var mockConversionGrantExpiryFeature = new Mock<IConversionGrantExpiryFeature>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()), mockConversionGrantExpiryFeature.Object);

// act
var conversionApplicationCreationService = new ConversionApplicationService(mockCreationHttpClientFactory.Object,
Expand Down Expand Up @@ -130,7 +132,8 @@ public async Task AddSchoolToApplication___ApiReturns500___InternalServerError()
var mockLoggerCreationService = new Mock<ILogger<ConversionApplicationService>>();
var mockLoggerRetrievalService = new Mock<ILogger<ConversionApplicationRetrievalService>>();
var mockFileUploadService = new Mock<IFileUploadService>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()));
var mockConversionGrantExpiryFeature = new Mock<IConversionGrantExpiryFeature>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()), mockConversionGrantExpiryFeature.Object);

// act
var conversionApplicationCreationService = new ConversionApplicationService(mockCreationHttpClientFactory.Object,
Expand Down Expand Up @@ -159,7 +162,8 @@ public async Task AddSchoolToApplication___InvalidApplicationId___ArgumentExcept
var mockLoggerCreationService = new Mock<ILogger<ConversionApplicationService>>();
var mockLoggerRetrievalService = new Mock<ILogger<ConversionApplicationRetrievalService>>();
var mockFileUploadService = new Mock<IFileUploadService>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()));
var mockConversionGrantExpiryFeature = new Mock<IConversionGrantExpiryFeature>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()), mockConversionGrantExpiryFeature.Object);

// act
var conversionApplicationCreationService = new ConversionApplicationService(mockCreationHttpClientFactory.Object,
Expand Down Expand Up @@ -275,7 +279,8 @@ public async Task ApplicationSchoolNextFinancialYear___ApiReturns200___Ok()
var mockLoggerCreationService = new Mock<ILogger<ConversionApplicationService>>();
var mockLoggerRetrievalService = new Mock<ILogger<ConversionApplicationRetrievalService>>();
var mockFileUploadService = new Mock<IFileUploadService>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()));
var mockConversionGrantExpiryFeature = new Mock<IConversionGrantExpiryFeature>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()), mockConversionGrantExpiryFeature.Object);

// act
var conversionApplicationCreationService = new ConversionApplicationService(mockCreationHttpClientFactory.Object,
Expand Down Expand Up @@ -307,7 +312,8 @@ public async Task ApplicationSchoolNextFinancialYear__ApiReturns500___InternalSe
var mockLoggerCreationService = new Mock<ILogger<ConversionApplicationService>>();
var mockLoggerRetrievalService = new Mock<ILogger<ConversionApplicationRetrievalService>>();
var mockFileUploadService = new Mock<IFileUploadService>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()));
var mockConversionGrantExpiryFeature = new Mock<IConversionGrantExpiryFeature>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()), mockConversionGrantExpiryFeature.Object);

// act
var conversionApplicationCreationService = new ConversionApplicationService(mockCreationHttpClientFactory.Object,
Expand Down Expand Up @@ -341,7 +347,8 @@ public async Task ApplicationSchoolPreviousFinancialYear___ApiReturns200___Ok()
var mockLoggerCreationService = new Mock<ILogger<ConversionApplicationService>>();
var mockLoggerRetrievalService = new Mock<ILogger<ConversionApplicationRetrievalService>>();
var mockFileUploadService = new Mock<IFileUploadService>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()));
var mockConversionGrantExpiryFeature = new Mock<IConversionGrantExpiryFeature>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()), mockConversionGrantExpiryFeature.Object);

// act
var conversionApplicationCreationService = new ConversionApplicationService(mockCreationHttpClientFactory.Object,
Expand Down Expand Up @@ -373,7 +380,8 @@ public async Task ApplicationSchoolPreviousFinancialYear__ApiReturns500___Intern
var mockLoggerCreationService = new Mock<ILogger<ConversionApplicationService>>();
var mockLoggerRetrievalService = new Mock<ILogger<ConversionApplicationRetrievalService>>();
var mockFileUploadService = new Mock<IFileUploadService>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()));
var mockConversionGrantExpiryFeature = new Mock<IConversionGrantExpiryFeature>();
var mockConversionApplicationRetrievalService = new ConversionApplicationRetrievalService(mockRetrievalHttpClientFactory.Object, mockLoggerRetrievalService.Object, mockFileUploadService.Object, Mock.Of<ICorrelationContext>(x => x.CorrelationId == Guid.NewGuid()), mockConversionGrantExpiryFeature.Object);

// act
var conversionApplicationCreationService = new ConversionApplicationService(mockCreationHttpClientFactory.Object,
Expand Down
Loading

0 comments on commit e174a28

Please sign in to comment.