Skip to content

Commit

Permalink
General refactoring - On behalf of Trilok
Browse files Browse the repository at this point in the history
  • Loading branch information
udaydefra committed Nov 22, 2024
1 parent fca6b03 commit d29e2be
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Diagnostics.CodeAnalysis;

namespace EPR.Calculator.Service.Common.UnitTests.AzureSynapse
{
using System;
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Threading.Tasks;
using Azure;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace EPR.Calculator.Service.Common.AzureSynapse
{
using Azure.Identity;
using System.Text;
using System.Text.Json;
using Azure.Identity;

/// <summary>
/// Runs Azure Synapse pipelines.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Azure.Analytics.Synapse.Artifacts;
using Azure.Core;

namespace EPR.Calculator.Service.Common.AzureSynapse
namespace EPR.Calculator.Service.Common.AzureSynapse
{
using Azure.Analytics.Synapse.Artifacts;
using Azure.Core;

public interface IPipelineClientFactory
{
public PipelineClient GetPipelineClient(Uri pipelineUrl, TokenCredential tokenCredential);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace EPR.Calculator.Service.Function.UnitTests.Services
{
using System.Net;
using AutoFixture;
using EPR.Calculator.Service.Common;
using EPR.Calculator.Service.Common.AzureSynapse;
Expand All @@ -8,7 +9,6 @@ namespace EPR.Calculator.Service.Function.UnitTests.Services
using Microsoft.Extensions.Logging;
using Moq;
using Moq.Protected;
using System.Net;

[TestClass]
public class CalculatorRunServiceTests
Expand All @@ -32,7 +32,7 @@ public CalculatorRunServiceTests()

var httpClient = new HttpClient(this.MockStatusUpdateHandler.Object)
{
BaseAddress = new Uri("http://test.com")
BaseAddress = new Uri("http://test.com"),
};

this.PipelineClientFactory = new Mock<PipelineClientFactory>();
Expand Down Expand Up @@ -66,7 +66,7 @@ public CalculatorRunServiceTests()
/// Checks that the service calls the Azure Synapse runner and passes the correct parameters to it.
/// </summary>
/// <param name="pipelineNameKey">Which pipeline to test - The service should call the synapse runner twice

public async Task StartProcessCallsAzureSynapseRunnerIfOrgPipelineisUnsuccessful()
{
// Arrange
Expand Down Expand Up @@ -299,5 +299,72 @@ public async Task StartProcessCallsAzureSynapseRunnerSuccessful()
Times.Never);
Assert.IsTrue(true);
}

/// <summary>
/// Checks that the service calls the Azure Synapse runner and passes the correct parameters to it.
/// </summary>
[TestMethod]
public async Task StartProcessCallsAzureSynapseRunnerRPDPipelineFalse()
{
// Arrange
var id = this.Fixture.Create<int>();
var financialYear = "2024-25";
var user = this.Fixture.Create<string>();

var checkInterval = 5;
Environment.SetEnvironmentVariable(
EnvironmentVariableKeys.CheckInterval,
checkInterval.ToString());

var maxChecks = 10;
Environment.SetEnvironmentVariable(
EnvironmentVariableKeys.MaxCheckCount,
maxChecks.ToString());

var pipelineUrl = this.Fixture.Create<Uri>(); ;
Environment.SetEnvironmentVariable(EnvironmentVariableKeys.PipelineUrl, pipelineUrl.ToString());

var orgpipelineName = "test";
Environment.SetEnvironmentVariable(EnvironmentVariableKeys.OrgDataPipelineName, orgpipelineName.ToString());

var pompipelineName = "pomtest";
Environment.SetEnvironmentVariable(EnvironmentVariableKeys.PomDataPipelineName, pompipelineName.ToString());

var runRPDPipeline = false;
Environment.SetEnvironmentVariable(
EnvironmentVariableKeys.ExecuteRPDPipeline,
runRPDPipeline.ToString());

var statusUpdateEndpoint = this.Fixture.Create<Uri>();
Environment.SetEnvironmentVariable(
EnvironmentVariableKeys.StatusUpdateEndpoint,
statusUpdateEndpoint.ToString());

var calculatorRunParameters = new CalculatorRunParameter
{
Id = id,
FinancialYear = financialYear,
User = user,
};

// The values that the service is expected to pass to the pipeline runner.
var expectedParameters = new AzureSynapseRunnerParameters
{
CalculatorRunId = id,
CheckInterval = checkInterval,
FinancialYear = financialYear,
MaxChecks = maxChecks,
PipelineUrl = pipelineUrl,
PipelineName = orgpipelineName,
StatusUpdateEndpoint = statusUpdateEndpoint,
};

this.AzureSynapseRunner.Setup(t => t.Process(It.IsAny<AzureSynapseRunnerParameters>())).ReturnsAsync(true);

// Act
var result = await this.CalculatorRunService.StartProcess(calculatorRunParameters);

Assert.IsTrue(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace EPR.Calculator.Service.Function.Interface
{
using EPR.Calculator.Service.Common;
using EPR.Calculator.Service.Common.AzureSynapse;
using System.Threading.Tasks;
using EPR.Calculator.Service.Common;

public interface ICalculatorRunService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
namespace EPR.Calculator.Service.Function.Services
{
using EPR.Calculator.Service.Common;
using EPR.Calculator.Service.Common.AzureSynapse;
using EPR.Calculator.Service.Common.Utils;
using EPR.Calculator.Service.Function.Interface;
using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using EPR.Calculator.Service.Common;
using EPR.Calculator.Service.Common.AzureSynapse;
using EPR.Calculator.Service.Function.Interface;
using Microsoft.Extensions.Logging;

public class CalculatorRunService : ICalculatorRunService
{
private readonly IAzureSynapseRunner azureSynapseRunner;
private readonly ILogger logger;
private readonly IPipelineClientFactory pipelineClientFactory;

public CalculatorRunService(IAzureSynapseRunner azureSynapseRunner, ILogger<CalculatorRunService> logger, IPipelineClientFactory pipelineClientFactory)
#pragma warning disable SA1600
public CalculatorRunService(IAzureSynapseRunner azureSynapseRunner, ILogger<CalculatorRunService> logger,
#pragma warning restore SA1600
#pragma warning disable SA1117
IPipelineClientFactory pipelineClientFactory)
#pragma warning restore SA1117
{
this.logger = logger;
this.azureSynapseRunner = azureSynapseRunner;
Expand All @@ -30,8 +34,8 @@ public async Task<bool> StartProcess(CalculatorRunParameter calculatorRunParamet
{
this.logger.LogInformation("Process started");
bool isPomSuccessful = false;

if (bool.Parse(Configuration.ExecuteRPDPipeline))
bool runRpdPipeline = bool.Parse(Configuration.ExecuteRPDPipeline);
if (runRpdPipeline)
{
var orgPipelineConfiguration = GetAzureSynapseConfiguration(
calculatorRunParameter,
Expand Down

0 comments on commit d29e2be

Please sign in to comment.