Skip to content

Commit ef08bb5

Browse files
...
1 parent c030cb0 commit ef08bb5

1 file changed

Lines changed: 24 additions & 27 deletions

File tree

FileProcessor.IntegrationTests/Features/SharedSteps.cs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace FileProcessor.IntegrationTests.Features
1212
using System.Net.Http.Headers;
1313
using System.Threading;
1414
using Common;
15+
using DataTransferObjects;
1516
using Shared.IntegrationTesting;
1617
using Shouldly;
1718
using TechTalk.SpecFlow;
@@ -41,21 +42,21 @@ public void GivenIHaveAFileNamedWithTheFollowingContents(String fileName, Table
4142
[Given(@"I upload this file for processing")]
4243
public async Task GivenIUploadThisFileForProcessing(Table table)
4344
{
44-
var response = await this.UploadFile(table);
45+
var fileId = await this.UploadFile(table);
4546

46-
response.StatusCode.ShouldBe(HttpStatusCode.Accepted);
47+
fileId.ShouldNotBe(Guid.Empty);
4748
}
4849

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

58-
private async Task<HttpResponseMessage> UploadFile(Table table)
59+
private async Task<Guid> UploadFile(Table table)
5960
{
6061
var row = table.Rows.First();
6162
String merchantName = SpecflowTableHelper.GetStringRowValue(row, "MerchantName");
@@ -66,30 +67,26 @@ private async Task<HttpResponseMessage> UploadFile(Table table)
6667
Guid estateId = estate.EstateId;
6768
var merchantId = estate.GetMerchantId(merchantName);
6869
String filePath = this.TestingContext.UploadFile;
69-
70-
var client = new HttpClient();
71-
var formData = new MultipartFormDataContent();
72-
73-
var fileContent = new ByteArrayContent(await File.ReadAllBytesAsync(filePath));
74-
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
75-
formData.Add(fileContent, "file", Path.GetFileName(filePath));
76-
formData.Add(new StringContent(estateId.ToString()), "request.EstateId");
77-
formData.Add(new StringContent(merchantId.ToString()), "request.MerchantId");
78-
formData.Add(new StringContent(fileProfileId), "request.FileProfileId");
79-
formData.Add(new StringContent(userId), "request.UserId");
80-
81-
var request = new HttpRequestMessage(HttpMethod.Post, $"http://127.0.0.1:{this.TestingContext.DockerHelper.FileProcessorPort}/api/files")
82-
{
83-
Content = formData
84-
};
85-
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", this.TestingContext.AccessToken);
86-
87-
var response = await client.SendAsync(request);
70+
var fileData = await File.ReadAllBytesAsync(filePath);
71+
72+
UploadFileRequest uploadFileRequest = new UploadFileRequest
73+
{
74+
EstateId = estateId,
75+
FileProfileId = Guid.Parse(fileProfileId),
76+
MerchantId = merchantId,
77+
UserId = Guid.Parse(userId)
78+
};
79+
80+
var fileId = await this.TestingContext.DockerHelper.FileProcessorClient.UploadFile(this.TestingContext.AccessToken,
81+
Path.GetFileName(filePath),
82+
fileData,
83+
uploadFileRequest,
84+
CancellationToken.None);
8885

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

92-
return response;
89+
return fileId;
9390
}
9491

9592

0 commit comments

Comments
 (0)