Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/191269 change grant comms #757

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading