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
2 changes: 1 addition & 1 deletion FileProcessor.Client/FileProcessorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public async Task<Guid> UploadFile(String accessToken,
Guid response = Guid.Empty;
try
{
String requestUri = this.BuildRequestUrl("api/files");
String requestUri = this.BuildRequestUrl("/api/files");

HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Post, requestUri);
MultipartFormDataContent formData = new MultipartFormDataContent();
Expand Down
10 changes: 6 additions & 4 deletions FileProcessor.IntegrationTests/Common/DockerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace FileProcessor.IntegrationTests.Common
using System.Net;
using System.Net.Http;
using System.Threading;
using Client;
using Ductus.FluentDocker.Builders;
using Ductus.FluentDocker.Common;
using Ductus.FluentDocker.Model.Builders;
Expand Down Expand Up @@ -43,7 +44,10 @@ public class DockerHelper : global::Shared.IntegrationTesting.DockerHelper
/// </summary>
public ISecurityServiceClient SecurityServiceClient;

public HttpClient FileProcessorClient;
/// <summary>
/// The file processor client
/// </summary>
public IFileProcessorClient FileProcessorClient;

/// <summary>
/// The test identifier
Expand Down Expand Up @@ -360,9 +364,7 @@ await Retry.For(async () =>
this.EstateClient = new EstateClient(EstateManagementBaseAddressResolver, httpClient);
this.SecurityServiceClient = new SecurityServiceClient(SecurityServiceBaseAddressResolver, httpClient);
this.EstateReportingClient = new EstateReportingClient(EstateReportingBaseAddressResolver, httpClient);
//this.TransactionProcessorClient = new TransactionProcessorClient(TransactionProcessorBaseAddressResolver, httpClient);
this.FileProcessorClient = new HttpClient();
this.FileProcessorClient.BaseAddress = new Uri(FileProcessorBaseAddressResolver(null));
this.FileProcessorClient = new FileProcessorClient(FileProcessorBaseAddressResolver, httpClient);

await this.LoadEventStoreProjections().ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace FileProcessor.IntegrationTests.Features
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using Common;
using DataTransferObjects.Responses;
using Newtonsoft.Json;
Expand All @@ -36,7 +37,7 @@ public GetFileImportDetailsSteps(ScenarioContext scenarioContext,
[When(@"I get the '(.*)' import logs between '(.*)' and '(.*)' the following data is returned")]
public async Task WhenIGetTheImportLogsBetweenAndTheFollowingDataIsReturned(string estateName, string startDate, string endDate, Table table)
{
FileImportLogList importLogList = await this.GetFileImportLogList(estateName, startDate, endDate);
FileImportLogList importLogList = await this.GetFileImportLogList(estateName, startDate, endDate, CancellationToken.None);

foreach (TableRow tableRow in table.Rows)
{
Expand All @@ -50,88 +51,65 @@ public async Task WhenIGetTheImportLogsBetweenAndTheFollowingDataIsReturned(stri
}
}

private async Task<FileDetails> GetFile(String estateName, Guid fileId)
private async Task<FileDetails> GetFile(String estateName, Guid fileId, CancellationToken cancellationToken)
{
var estateDetails = this.TestingContext.GetEstateDetails(estateName);

String requestUri =
$"{this.TestingContext.DockerHelper.FileProcessorClient.BaseAddress}api/files/{fileId}?estateId={estateDetails.EstateId}";
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri);
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", this.TestingContext.AccessToken);

var responseMessage = await this.TestingContext.DockerHelper.FileProcessorClient.SendAsync(requestMessage);

responseMessage.StatusCode.ShouldBe(HttpStatusCode.OK);
var content = await responseMessage.Content.ReadAsStringAsync();
content.ShouldNotBeNull();
content.ShouldNotBeEmpty();

var fileDetails = JsonConvert.DeserializeObject<FileDetails>(content);

var fileDetails = await this.TestingContext.DockerHelper.FileProcessorClient.GetFile(this.TestingContext.AccessToken, estateDetails.EstateId, fileId, cancellationToken);
fileDetails.ShouldNotBeNull();

return fileDetails;
}

private async Task<FileImportLogList> GetFileImportLogList(String estateName,
String startDate,
String endDate)
String endDate,
CancellationToken cancellationToken)
{
var queryStartDate = SpecflowTableHelper.GetDateForDateString(startDate, DateTime.Now);
var queryEndDate = SpecflowTableHelper.GetDateForDateString(endDate, DateTime.Now);
var estateDetails = this.TestingContext.GetEstateDetails(estateName);

String requestUri =
$"{this.TestingContext.DockerHelper.FileProcessorClient.BaseAddress}api/fileImportLogs?estateId={estateDetails.EstateId}&startDate={queryStartDate.Date:yyyy-MM-dd}&endDate={queryEndDate.Date:yyyy-MM-dd}";
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri);
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", this.TestingContext.AccessToken);

var responseMessage = await this.TestingContext.DockerHelper.FileProcessorClient.SendAsync(requestMessage);

responseMessage.StatusCode.ShouldBe(HttpStatusCode.OK);
var content = await responseMessage.Content.ReadAsStringAsync();
content.ShouldNotBeNull();
content.ShouldNotBeEmpty();

var importLogList = JsonConvert.DeserializeObject<FileImportLogList>(content);
var importLogList = await this.TestingContext.DockerHelper.FileProcessorClient.GetFileImportLogs(this.TestingContext.AccessToken,
estateDetails.EstateId,
queryStartDate,
queryEndDate,
null,
cancellationToken);
importLogList.ShouldNotBeNull();
importLogList.FileImportLogs.ShouldNotBeNull();
importLogList.FileImportLogs.ShouldNotBeEmpty();

return importLogList;
}

private async Task<FileImportLog> GetFileImportLog(String estateName,
Guid fileImportLogId)
Guid fileImportLogId,
CancellationToken cancellationToken)
{
var estateDetails = this.TestingContext.GetEstateDetails(estateName);

String requestUri =
$"{this.TestingContext.DockerHelper.FileProcessorClient.BaseAddress}api/fileImportLogs/{fileImportLogId}?estateId={estateDetails.EstateId}";
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri);
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", this.TestingContext.AccessToken);

var responseMessage = await this.TestingContext.DockerHelper.FileProcessorClient.SendAsync(requestMessage);

responseMessage.StatusCode.ShouldBe(HttpStatusCode.OK);
var content = await responseMessage.Content.ReadAsStringAsync();
content.ShouldNotBeNull();
content.ShouldNotBeEmpty();

var fileImportLog = JsonConvert.DeserializeObject<FileImportLog>(content);
var fileImportLog = await this.TestingContext.DockerHelper.FileProcessorClient.GetFileImportLog(this.TestingContext.AccessToken,
fileImportLogId,
estateDetails.EstateId,
null,
cancellationToken);
fileImportLog.ShouldNotBeNull();
fileImportLog.Files.ShouldNotBeNull();
fileImportLog.Files.ShouldNotBeEmpty();

return fileImportLog;
}

[When(@"I get the '(.*)' import log for '(.*)' the following file information is returned")]
public async Task WhenIGetTheImportLogForTheFollowingFileInformationIsReturned(string estateName, string startDate, Table table)
{
EstateDetails estateDetails = this.TestingContext.GetEstateDetails(estateName);
FileImportLogList importLogList = await this.GetFileImportLogList(estateName, startDate, startDate);
FileImportLogList importLogList = await this.GetFileImportLogList(estateName, startDate, startDate, CancellationToken.None);

importLogList.FileImportLogs.ShouldHaveSingleItem();

var fileImportLog = await this.GetFileImportLog(estateName, importLogList.FileImportLogs.Single().FileImportLogId);
var fileImportLog = await this.GetFileImportLog(estateName, importLogList.FileImportLogs.Single().FileImportLogId, CancellationToken.None);

foreach (TableRow tableRow in table.Rows)
{
Expand Down Expand Up @@ -167,7 +145,7 @@ public async Task WhenIGetTheFileForEstateTheFollowingFileInformationIsReturned(

await Retry.For(async () =>
{
var fileDetails = await this.GetFile(estateName, fileId);
var fileDetails = await this.GetFile(estateName, fileId, CancellationToken.None);
fileDetails.ProcessingCompleted.ShouldBe(processingCompleted);
fileDetails.FileLines.Count.ShouldBe(numberOfLines);
fileDetails.ProcessingSummary.TotalLines.ShouldBe(totaLines);
Expand All @@ -185,7 +163,7 @@ public async Task WhenIGetTheFileForEstateTheFollowingFileLinesAreReturned(strin

Guid fileId = estateDetails.GetFileId(fileName);

var fileDetails = await this.GetFile(estateName, fileId);
var fileDetails = await this.GetFile(estateName, fileId, CancellationToken.None);

foreach (TableRow tableRow in table.Rows)
{
Expand Down
51 changes: 24 additions & 27 deletions FileProcessor.IntegrationTests/Features/SharedSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace FileProcessor.IntegrationTests.Features
using System.Net.Http.Headers;
using System.Threading;
using Common;
using DataTransferObjects;
using Shared.IntegrationTesting;
using Shouldly;
using TechTalk.SpecFlow;
Expand Down Expand Up @@ -41,21 +42,21 @@ public void GivenIHaveAFileNamedWithTheFollowingContents(String fileName, Table
[Given(@"I upload this file for processing")]
public async Task GivenIUploadThisFileForProcessing(Table table)
{
var response = await this.UploadFile(table);
var fileId = await this.UploadFile(table);

response.StatusCode.ShouldBe(HttpStatusCode.Accepted);
fileId.ShouldNotBe(Guid.Empty);
}

[Given(@"I upload this file for processing an error should be returned indicating the file is a duplicate")]
public async Task GivenIUploadThisFileForProcessingAnErrorShouldBeReturnedIndicatingTheFileIsADuplicate(Table table)
{
var response = await this.UploadFile(table);
response.StatusCode.ShouldBe(HttpStatusCode.BadRequest);
var responseContent = await response.Content.ReadAsStringAsync(CancellationToken.None);
responseContent.ShouldContain("Duplicate file", Case.Insensitive);
Should.Throw<Exception>(async () =>
{
await this.UploadFile(table);
});
}

private async Task<HttpResponseMessage> UploadFile(Table table)
private async Task<Guid> UploadFile(Table table)
{
var row = table.Rows.First();
String merchantName = SpecflowTableHelper.GetStringRowValue(row, "MerchantName");
Expand All @@ -66,30 +67,26 @@ private async Task<HttpResponseMessage> UploadFile(Table table)
Guid estateId = estate.EstateId;
var merchantId = estate.GetMerchantId(merchantName);
String filePath = this.TestingContext.UploadFile;

var client = new HttpClient();
var formData = new MultipartFormDataContent();

var fileContent = new ByteArrayContent(await File.ReadAllBytesAsync(filePath));
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
formData.Add(fileContent, "file", Path.GetFileName(filePath));
formData.Add(new StringContent(estateId.ToString()), "request.EstateId");
formData.Add(new StringContent(merchantId.ToString()), "request.MerchantId");
formData.Add(new StringContent(fileProfileId), "request.FileProfileId");
formData.Add(new StringContent(userId), "request.UserId");

var request = new HttpRequestMessage(HttpMethod.Post, $"http://127.0.0.1:{this.TestingContext.DockerHelper.FileProcessorPort}/api/files")
{
Content = formData
};
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", this.TestingContext.AccessToken);

var response = await client.SendAsync(request);
var fileData = await File.ReadAllBytesAsync(filePath);

UploadFileRequest uploadFileRequest = new UploadFileRequest
{
EstateId = estateId,
FileProfileId = Guid.Parse(fileProfileId),
MerchantId = merchantId,
UserId = Guid.Parse(userId)
};

var fileId = await this.TestingContext.DockerHelper.FileProcessorClient.UploadFile(this.TestingContext.AccessToken,
Path.GetFileName(filePath),
fileData,
uploadFileRequest,
CancellationToken.None);

// Now we need to wait some time to let the file be processed
await Task.Delay(TimeSpan.FromMinutes(1));

return response;
return fileId;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FileProcessor.DataTransferObjects\FileProcessor.DataTransferObjects.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Features\ProcessTopupCSV.feature.cs">
<DesignTime>True</DesignTime>
Expand All @@ -59,4 +55,9 @@
<Folder Include="Steps\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FileProcessor.Client\FileProcessor.Client.csproj" />
<ProjectReference Include="..\FileProcessor.DataTransferObjects\FileProcessor.DataTransferObjects.csproj" />
</ItemGroup>

</Project>