Skip to content

Commit ff91173

Browse files
Fix to request validation
1 parent 899afab commit ff91173

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

FileProcessor.BusinessLogic.Tests/FileProcessorDomainServiceTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,42 @@ public async Task FileRequestHandler_UploadFileRequest_RequestIsHandled()
9494
});
9595
}
9696

97+
[Fact]
98+
public async Task FileRequestHandler_UploadFileRequest_MerchantIdNotProvided_ErrorThrown()
99+
{
100+
UploadFileRequest uploadFileRequest =
101+
new UploadFileRequest(TestData.EstateId, Guid.Empty, TestData.UserId, TestData.FilePathWithName, TestData.FileProfileId, TestData.FileUploadedDateTime);
102+
103+
Should.Throw<InvalidDataException>(async () =>
104+
{
105+
await this.FileProcessorDomainService.UploadFile(uploadFileRequest, CancellationToken.None);
106+
});
107+
}
108+
109+
[Fact]
110+
public async Task FileRequestHandler_UploadFileRequest_FileProfileIdNotProvided_ErrorThrown()
111+
{
112+
UploadFileRequest uploadFileRequest =
113+
new UploadFileRequest(TestData.EstateId, TestData.MerchantId, TestData.UserId, TestData.FilePathWithName, Guid.Empty, TestData.FileUploadedDateTime);
114+
115+
Should.Throw<InvalidDataException>(async () =>
116+
{
117+
await this.FileProcessorDomainService.UploadFile(uploadFileRequest, CancellationToken.None);
118+
});
119+
}
120+
121+
[Fact]
122+
public async Task FileRequestHandler_UploadFileRequest_UserIdNotProvided_ErrorThrown()
123+
{
124+
UploadFileRequest uploadFileRequest =
125+
new UploadFileRequest(TestData.EstateId, TestData.MerchantId, Guid.Empty, TestData.FilePathWithName, TestData.FileProfileId, TestData.FileUploadedDateTime);
126+
127+
Should.Throw<InvalidDataException>(async () =>
128+
{
129+
await this.FileProcessorDomainService.UploadFile(uploadFileRequest, CancellationToken.None);
130+
});
131+
}
132+
97133
[Fact]
98134
public async Task FileRequestHandler_UploadFileRequest_ImportLogAlreadyCreated_RequestIsHandled()
99135
{

FileProcessor.BusinessLogic/Services/FileProcessorDomainService.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public async Task<Guid> UploadFile(UploadFileRequest request,
6969
CancellationToken cancellationToken) {
7070
DateTime importLogDateTime = request.FileUploadedDateTime;
7171

72+
this.ValidateRequest(request);
73+
7274
// This will now create the import log and add an event for the file being uploaded
7375
Guid importLogId = Helpers.CalculateFileImportLogAggregateId(importLogDateTime.Date, request.EstateId);
7476

@@ -129,6 +131,22 @@ public async Task<Guid> UploadFile(UploadFileRequest request,
129131
return fileId;
130132
}
131133

134+
private void ValidateRequest(UploadFileRequest request){
135+
if (request.UserId == Guid.Empty){
136+
throw new InvalidDataException("No User Id provided with file upload");
137+
}
138+
139+
if (request.MerchantId == Guid.Empty)
140+
{
141+
throw new InvalidDataException("No Merchant Id provided with file upload");
142+
}
143+
144+
if (request.FileProfileId == Guid.Empty)
145+
{
146+
throw new InvalidDataException("No File Profile Id provided with file upload");
147+
}
148+
}
149+
132150
public async Task ProcessUploadedFile(ProcessUploadedFileRequest request,
133151
CancellationToken cancellationToken) {
134152
// TODO: Should the file id be generated from the file uploaded to protect against duplicate files???

0 commit comments

Comments
 (0)