Skip to content
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
@@ -1,12 +1,11 @@
using Azure;
using System.Net;
using System.Net;
using System.Text;

namespace UKHO.PeriodicOutputService.Common.UnitTests.Handler
{
public class FakeHttpMessageHandler : HttpMessageHandler
public class FakeHttpMessageHandler(HttpResponseMessage response) : HttpMessageHandler
{
private readonly HttpResponseMessage response;
private readonly HttpResponseMessage _response = response;

public static HttpMessageHandler GetHttpMessageHandler(string content, HttpStatusCode httpStatusCode)
{
Expand All @@ -21,16 +20,11 @@ public static HttpMessageHandler GetHttpMessageHandler(string content, HttpStatu
return messageHandler;
}

public FakeHttpMessageHandler(HttpResponseMessage response)
{
this.response = response;
}

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var tcs = new TaskCompletionSource<HttpResponseMessage>();

tcs.SetResult(response);
tcs.SetResult(_response);

return tcs.Task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,19 @@ public void IsAio_BatchType(Batch batchType, bool expectedResult)
{
Assert.That(batchType.IsAio(), Is.EqualTo(expectedResult));
}

[Test]
public void CheckMethodReturns_CorrectBase64EncodedCredentials()
{
var user1Credentials = CommonHelper.GetBase64EncodedCredentials("User1", "Password1");
Assert.That(user1Credentials, Is.EqualTo("VXNlcjE6UGFzc3dvcmQx"));
}

[Test]
public void CheckMethodReturns_CorrectExtractAccessToken()
{
var extractedAccessToken = CommonHelper.ExtractAccessToken("{\"token\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6I1234212CJ9.VLSE9fRk1234.fd73LguLf_6VBefVQqu0nj8j3dovfUNVeqZDYGZ1234\",\"expiration\":\"2022-06-15T16:02:52Z\"}");
Assert.That(extractedAccessToken, Is.EqualTo("eyJhbGciOiJIUzI1NiIsInR5cCI6I1234212CJ9.VLSE9fRk1234.fd73LguLf_6VBefVQqu0nj8j3dovfUNVeqZDYGZ1234"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
using Newtonsoft.Json;
using UKHO.PeriodicOutputService.Common.Helpers;
using UKHO.PeriodicOutputService.Common.Models.Ess.Response;
using UKHO.PeriodicOutputService.Fulfilment.UnitTests.Handler;
using UKHO.PeriodicOutputService.Common.UnitTests.Handler;

namespace UKHO.PeriodicOutputService.Fulfilment.UnitTests.Helpers
namespace UKHO.PeriodicOutputService.Common.UnitTests.Helpers
{
[TestFixture]
public class EssApiClientTests
{
private IEssApiClient? _essApiClient;
private EssApiClient? _essApiClient;
private IHttpClientFactory _fakeHttpClientFactory;

[SetUp]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using UKHO.PeriodicOutputService.Common.Models.Pks;
using UKHO.PeriodicOutputService.Common.Utilities;

namespace UKHO.PeriodicOutputService.Fulfilment.UnitTests.Helpers
namespace UKHO.PeriodicOutputService.Common.UnitTests.Helpers
{
public class FileSystemHelperTests
{
Expand Down Expand Up @@ -89,12 +89,12 @@ public void Does_GetFileMD5_Returns_FileDetails_With_Hash()
{
IEnumerable<string> fileNames = new List<string> { fileName };

IFileInfo fileInfo = _fakefileSystem.FileInfo.New(fileName);
var fileInfo = _fakefileSystem.FileInfo.New(fileName);
A.CallTo(() => fileInfo.Name).Returns(fileName);
A.CallTo(() => fileInfo.OpenRead()).Returns(new MockFileSystemStream(new MemoryStream(new byte[10]), "Test", default));
A.CallTo(() => _fakefileSystem.FileInfo.New(A<string>.Ignored)).Returns(fileInfo);

List<FileDetail>? result = _fileSystemHelper.GetFileMD5(fileNames);
var result = _fileSystemHelper.GetFileMD5(fileNames);

Assert.Multiple(() =>
{
Expand Down Expand Up @@ -132,7 +132,7 @@ public void Does_CreateIsoAndSha1_Executes_Successfully()
[Test]
public void Does_CreateXmlFile_Executes_Successfully()
{
byte[] byteContent = new byte[100];
var byteContent = new byte[100];

_fileSystemHelper.CreateXmlFile(byteContent, filePath);

Expand Down Expand Up @@ -188,7 +188,7 @@ public void Does_GetFileInBytes_Returns_Bytes_Passing_Stream()

A.CallTo(() => _fakeFileInfo.Open(A<FileMode>.Ignored, A<FileAccess>.Ignored, A<FileShare>.Ignored)).Returns(new MockFileSystemStream(stream, "Test", default));

byte[] result = _fileSystemHelper.GetFileInBytes(GetUploadFileBlockRequestModel());
var result = _fileSystemHelper.GetFileInBytes(GetUploadFileBlockRequestModel());

Assert.That(result, Has.Length.EqualTo(100000));
}
Expand All @@ -199,7 +199,7 @@ public void Does_GetFileInfo_Executes_Successfully()
A.CallTo(() => _fakefileSystem.FileInfo.New(filePath)).Returns(_fakeFileInfo);
A.CallTo(() => _fakeFileInfo.Name).Returns(fileName);

IFileInfo result = _fileSystemHelper.GetFileInfo(filePath);
var result = _fileSystemHelper.GetFileInfo(filePath);

Assert.Multiple(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using FakeItEasy;
using Newtonsoft.Json;
using UKHO.PeriodicOutputService.Common.Helpers;
using UKHO.PeriodicOutputService.Fulfilment.UnitTests.Handler;
using UKHO.PeriodicOutputService.Common.UnitTests.Handler;

namespace UKHO.PeriodicOutputService.Fulfilment.UnitTests.Helpers
namespace UKHO.PeriodicOutputService.Common.UnitTests.Helpers
{
[TestFixture]
public class FleetManagerClientTests
Expand All @@ -21,7 +21,7 @@ public void Setup()
[Test]
public void DoesGetJwtAuthUnpToken_Returns_OK()
{
string AuthToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjJaUXBKM1VwYmpBWVh";
var AuthToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjJaUXBKM1VwYmpBWVh";

var messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
AuthToken, HttpStatusCode.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using System.Text;
using FakeItEasy;
using UKHO.PeriodicOutputService.Common.Helpers;
using UKHO.PeriodicOutputService.Fulfilment.UnitTests.Handler;
using UKHO.PeriodicOutputService.Common.UnitTests.Handler;

namespace UKHO.PeriodicOutputService.Fulfilment.UnitTests.Helpers
namespace UKHO.PeriodicOutputService.Common.UnitTests.Helpers
{
[TestFixture]
public class FssApiClientTests
{
private IFssApiClient? _fakeFssApiClient;
private FssApiClient? _fakeFssApiClient;
private IHttpClientFactory _fakeHttpClientFactory;
private readonly string _authToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjJaUXBKM1VwYmpBWVh";

Expand All @@ -19,7 +19,7 @@ public class FssApiClientTests
[Test]
public void DoesGetBatchStatusAsync_Returns_OK()
{
HttpMessageHandler messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
var messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
_authToken, HttpStatusCode.OK);

var httpClient = new HttpClient(messageHandler)
Expand All @@ -31,7 +31,7 @@ public void DoesGetBatchStatusAsync_Returns_OK()

_fakeFssApiClient = new FssApiClient(_fakeHttpClientFactory);

Task<HttpResponseMessage> result = _fakeFssApiClient.GetBatchStatusAsync("http://test.com", _authToken);
var result = _fakeFssApiClient.GetBatchStatusAsync("http://test.com", _authToken);

Assert.Multiple(() =>
{
Expand All @@ -44,9 +44,9 @@ public void DoesGetBatchStatusAsync_Returns_OK()
[Test]
public void DoesCreateBatchAsync_Returns_OK()
{
string content = "";
var content = "";

HttpMessageHandler messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
var messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
content, HttpStatusCode.OK);

var httpClient = new HttpClient(messageHandler)
Expand All @@ -58,7 +58,7 @@ public void DoesCreateBatchAsync_Returns_OK()

_fakeFssApiClient = new FssApiClient(_fakeHttpClientFactory);

Task<HttpResponseMessage> result = _fakeFssApiClient.CreateBatchAsync("http://test.com", content, _authToken);
var result = _fakeFssApiClient.CreateBatchAsync("http://test.com", content, _authToken);

Assert.Multiple(() =>
{
Expand All @@ -70,9 +70,9 @@ public void DoesCreateBatchAsync_Returns_OK()
[Test]
public void DoesAddFileInBatchAsync_Returns_OK()
{
string content = "";
var content = "";

HttpMessageHandler messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
var messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
content, HttpStatusCode.OK);

var httpClient = new HttpClient(messageHandler)
Expand All @@ -84,7 +84,7 @@ public void DoesAddFileInBatchAsync_Returns_OK()

_fakeFssApiClient = new FssApiClient(_fakeHttpClientFactory);

Task<HttpResponseMessage> result = _fakeFssApiClient.AddFileToBatchAsync("http://test.com", content, _authToken, 1231231, "application/octet-stream");
var result = _fakeFssApiClient.AddFileToBatchAsync("http://test.com", content, _authToken, 1231231, "application/octet-stream");

Assert.Multiple(() =>
{
Expand All @@ -96,9 +96,9 @@ public void DoesAddFileInBatchAsync_Returns_OK()
[Test]
public void DoesUploadFileBlockAsync_Returns_OK()
{
string content = "";
var content = "";

HttpMessageHandler messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
var messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
content, HttpStatusCode.OK);

var httpClient = new HttpClient(messageHandler)
Expand All @@ -110,7 +110,7 @@ public void DoesUploadFileBlockAsync_Returns_OK()

_fakeFssApiClient = new FssApiClient(_fakeHttpClientFactory);

Task<HttpResponseMessage> result = _fakeFssApiClient.UploadFileBlockAsync("http://test.com", Encoding.UTF8.GetBytes("whatever"), Encoding.UTF8.GetBytes("whatever"), _authToken, "application/octet-stream");
var result = _fakeFssApiClient.UploadFileBlockAsync("http://test.com", Encoding.UTF8.GetBytes("whatever"), Encoding.UTF8.GetBytes("whatever"), _authToken, "application/octet-stream");

Assert.Multiple(() =>
{
Expand All @@ -122,9 +122,9 @@ public void DoesUploadFileBlockAsync_Returns_OK()
[Test]
public void DoesWriteBlockInFileAsync_Returns_OK()
{
string content = "";
var content = "";

HttpMessageHandler messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
var messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
content, HttpStatusCode.OK);

var httpClient = new HttpClient(messageHandler)
Expand All @@ -136,7 +136,7 @@ public void DoesWriteBlockInFileAsync_Returns_OK()

_fakeFssApiClient = new FssApiClient(_fakeHttpClientFactory);

Task<HttpResponseMessage> result = _fakeFssApiClient.WriteBlockInFileAsync("http://test.com", content, _authToken, "application/octet-stream");
var result = _fakeFssApiClient.WriteBlockInFileAsync("http://test.com", content, _authToken, "application/octet-stream");

Assert.Multiple(() =>
{
Expand All @@ -148,9 +148,9 @@ public void DoesWriteBlockInFileAsync_Returns_OK()
[Test]
public void DoesCommitBatchAsync_Returns_OK()
{
string content = "";
var content = "";

HttpMessageHandler messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
var messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
content, HttpStatusCode.OK);

var httpClient = new HttpClient(messageHandler)
Expand All @@ -162,7 +162,7 @@ public void DoesCommitBatchAsync_Returns_OK()

_fakeFssApiClient = new FssApiClient(_fakeHttpClientFactory);

Task<HttpResponseMessage> result = _fakeFssApiClient.CommitBatchAsync("http://test.com", content, _authToken);
var result = _fakeFssApiClient.CommitBatchAsync("http://test.com", content, _authToken);

Assert.Multiple(() =>
{
Expand All @@ -174,9 +174,9 @@ public void DoesCommitBatchAsync_Returns_OK()
[Test]
public void DoesDownloadFile_Returns_OK()
{
string content = "";
var content = "";

HttpMessageHandler messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
var messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
content, HttpStatusCode.OK);

var httpClient = new HttpClient(messageHandler)
Expand All @@ -188,7 +188,7 @@ public void DoesDownloadFile_Returns_OK()

_fakeFssApiClient = new FssApiClient(_fakeHttpClientFactory);

Task<HttpResponseMessage> result = _fakeFssApiClient.DownloadFile("http://test.com", _authToken, "bytes=1-1024");
var result = _fakeFssApiClient.DownloadFile("http://test.com", _authToken, "bytes=1-1024");

Assert.Multiple(() =>
{
Expand All @@ -200,9 +200,9 @@ public void DoesDownloadFile_Returns_OK()
[Test]
public void DoesDownloadFile_With_Client_That_Allow_Redirect_As_False_Returns_OK()
{
string content = "";
var content = "";

HttpMessageHandler messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
var messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
content, HttpStatusCode.OK);

var httpClient = new HttpClient(messageHandler)
Expand All @@ -214,17 +214,17 @@ public void DoesDownloadFile_With_Client_That_Allow_Redirect_As_False_Returns_OK

_fakeFssApiClient = new FssApiClient(_fakeHttpClientFactory);

Task<HttpResponseMessage> result = _fakeFssApiClient.DownloadFile("http://test.com", _authToken);
var result = _fakeFssApiClient.DownloadFile("http://test.com", _authToken);

Assert.That(result.Result.StatusCode, Is.EqualTo(HttpStatusCode.OK));
}

[Test]
public void DoesGetBatchDetailsAsync_Returns_OK()
{
string content = "";
var content = "";

HttpMessageHandler messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
var messageHandler = FakeHttpMessageHandler.GetHttpMessageHandler(
content, HttpStatusCode.OK);

var httpClient = new HttpClient(messageHandler)
Expand All @@ -236,7 +236,7 @@ public void DoesGetBatchDetailsAsync_Returns_OK()

_fakeFssApiClient = new FssApiClient(_fakeHttpClientFactory);

Task<HttpResponseMessage> result = _fakeFssApiClient.GetBatchDetailsAsync("http://test.com", _authToken);
var result = _fakeFssApiClient.GetBatchDetailsAsync("http://test.com", _authToken);

Assert.Multiple(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
using UKHO.PeriodicOutputService.Common.Configuration;
using UKHO.PeriodicOutputService.Common.Helpers;
using UKHO.PeriodicOutputService.Common.Logging;
using UKHO.PeriodicOutputService.Common.Models.Fm.Response;
using UKHO.PeriodicOutputService.Common.Services;

namespace UKHO.PeriodicOutputService.Fulfilment.UnitTests.Services
namespace UKHO.PeriodicOutputService.Common.UnitTests.Services
{
[TestFixture]
public class FleetManagerServiceTests
Expand All @@ -21,7 +20,7 @@ public class FleetManagerServiceTests
private IFileSystemHelper _fakefileSystemHelper;
private IConfiguration _fakeconfiguration;

private IFleetManagerService _fleetManagerService;
private FleetManagerService _fleetManagerService;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -49,7 +48,7 @@ public async Task DoesGetJwtAuthUnpToken_Returns_Token_WhenValidCredentialsPasse
Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes("{\"token\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6I1234212CJ9.VLSE9fRk0ifQ.fd73LguLf_6VBefVQqu0nj8j3dovfUNVeqZDYGZ1234\",\"expiration\":\"2022-06-15T16:02:52Z\"}")))
});

FleetMangerGetAuthTokenResponseModel result = await _fleetManagerService.GetJwtAuthUnpToken();
var result = await _fleetManagerService.GetJwtAuthUnpToken();

Assert.Multiple(() =>
{
Expand Down Expand Up @@ -105,7 +104,7 @@ public async Task DoesGetCatalogue_Returns_200_WhenValidAccessTokenPassed()
.Returns(response);
A.CallTo(() => _fakefileSystemHelper.CreateXmlFile(response.Content.ReadAsByteArrayAsync().Result, Path.Combine(_fakeconfiguration["HOME"], _fakeconfiguration["AVCSCatalogFileName"])));

FleetManagerGetCatalogueResponseModel result = await _fleetManagerService.GetCatalogue("JwtAuthJwtAccessToken");
var result = await _fleetManagerService.GetCatalogue("JwtAuthJwtAccessToken");
Assert.Multiple(() =>
{
Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK));
Expand Down
Loading