33using System . Linq ;
44using System . Text ;
55using System . Threading . Tasks ;
6+ using FileProcessor . Models ;
7+ using SimpleResults ;
68
79namespace FileProcessor . BusinessLogic . Tests
810{
@@ -11,7 +13,7 @@ namespace FileProcessor.BusinessLogic.Tests
1113 using EstateManagement . Database . Contexts ;
1214 using EstateManagement . Database . Entities ;
1315 using FileAggregate ;
14- using FIleProcessor . Models ;
16+ using FileProcessor . Models ;
1517 using Managers ;
1618 using Microsoft . EntityFrameworkCore ;
1719 using Microsoft . EntityFrameworkCore . Diagnostics ;
@@ -23,8 +25,8 @@ namespace FileProcessor.BusinessLogic.Tests
2325 using Shouldly ;
2426 using Testing ;
2527 using Xunit ;
26- using FileImportLog = FIleProcessor . Models . FileImportLog ;
27- using FileLine = FIleProcessor . Models . FileLine ;
28+ using FileImportLog = FileProcessor . Models . FileImportLog ;
29+ using FileLine = FileProcessor . Models . FileLine ;
2830
2931 public class FileProcessingManagerTests
3032 {
@@ -40,7 +42,8 @@ public async Task FileProcessingManager_GetAllFileProfiles_AllFileProfilesReturn
4042
4143 var allFileProfiles = await manager . GetAllFileProfiles ( CancellationToken . None ) ;
4244 allFileProfiles . ShouldNotBeNull ( ) ;
43- allFileProfiles . ShouldNotBeEmpty ( ) ;
45+ allFileProfiles . IsSuccess . ShouldBeTrue ( ) ;
46+ allFileProfiles . Data . ShouldNotBeEmpty ( ) ;
4447 }
4548
4649 [ Fact ]
@@ -55,7 +58,8 @@ public async Task FileProcessingManager_GetFileProfile_FIleProfileReturned()
5558
5659 var fileProfile = await manager . GetFileProfile ( TestData . SafaricomFileProfileId , CancellationToken . None ) ;
5760 fileProfile . ShouldNotBeNull ( ) ;
58- fileProfile . FileProfileId . ShouldBe ( TestData . SafaricomFileProfileId ) ;
61+ fileProfile . IsSuccess . ShouldBeTrue ( ) ;
62+ fileProfile . Data . FileProfileId . ShouldBe ( TestData . SafaricomFileProfileId ) ;
5963 }
6064
6165 [ Fact ]
@@ -161,15 +165,16 @@ public async Task FileProcessingManager_GetFile_FileReturned()
161165
162166 Mock < IAggregateRepository < FileAggregate , DomainEvent > > fileAggregateRepository =
163167 new Mock < IAggregateRepository < FileAggregate , DomainEvent > > ( ) ;
164- fileAggregateRepository . Setup ( f => f . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . GetFileAggregateWithLines ) ;
168+ fileAggregateRepository . Setup ( f => f . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( Result . Success ( TestData . GetFileAggregateWithLines ( ) ) ) ;
165169 FileProcessorManager manager = new FileProcessorManager ( fileProfiles , contextFactory . Object , modelFactory , fileAggregateRepository . Object ) ;
166170
167- var fileDetails = await manager . GetFile ( TestData . FileId , TestData . EstateId , CancellationToken . None ) ;
171+ Result < FileDetails > fileDetails = await manager . GetFile ( TestData . FileId , TestData . EstateId , CancellationToken . None ) ;
168172
173+ fileDetails . IsSuccess . ShouldBeTrue ( ) ;
169174 this . VerifyFile ( TestData . GetFileAggregateWithLines ( ) , fileDetails ) ;
170- fileDetails . MerchantName . ShouldBeNull ( ) ;
171- fileDetails . UserEmailAddress . ShouldBeNull ( ) ;
172- fileDetails . FileProfileName . ShouldBeNull ( ) ;
175+ fileDetails . Data . MerchantName . ShouldBeNull ( ) ;
176+ fileDetails . Data . UserEmailAddress . ShouldBeNull ( ) ;
177+ fileDetails . Data . FileProfileName . ShouldBeNull ( ) ;
173178 }
174179
175180 [ Fact ]
@@ -191,13 +196,14 @@ public async Task FileProcessingManager_GetFile_FileReturnedWithMerchantName()
191196
192197 Mock < IAggregateRepository < FileAggregate , DomainEvent > > fileAggregateRepository =
193198 new Mock < IAggregateRepository < FileAggregate , DomainEvent > > ( ) ;
194- fileAggregateRepository . Setup ( f => f . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . GetFileAggregateWithLines ) ;
199+ fileAggregateRepository . Setup ( f => f . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( Result . Success ( TestData . GetFileAggregateWithLines ( ) ) ) ;
195200 FileProcessorManager manager = new FileProcessorManager ( fileProfiles , contextFactory . Object , modelFactory , fileAggregateRepository . Object ) ;
196201
197202 var fileDetails = await manager . GetFile ( TestData . FileId , TestData . EstateId , CancellationToken . None ) ;
203+ fileDetails . IsSuccess . ShouldBeTrue ( ) ;
198204
199205 this . VerifyFile ( TestData . GetFileAggregateWithLines ( ) , fileDetails ) ;
200- fileDetails . MerchantName . ShouldBe ( TestData . MerchantName ) ;
206+ fileDetails . Data . MerchantName . ShouldBe ( TestData . MerchantName ) ;
201207 }
202208
203209 [ Fact ]
@@ -218,13 +224,13 @@ public async Task FileProcessingManager_GetFile_FileReturnedWithUserEmailAddress
218224
219225 Mock < IAggregateRepository < FileAggregate , DomainEvent > > fileAggregateRepository =
220226 new Mock < IAggregateRepository < FileAggregate , DomainEvent > > ( ) ;
221- fileAggregateRepository . Setup ( f => f . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . GetFileAggregateWithLines ) ;
227+ fileAggregateRepository . Setup ( f => f . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( Result . Success ( TestData . GetFileAggregateWithLines ( ) ) ) ;
222228 FileProcessorManager manager = new FileProcessorManager ( fileProfiles , contextFactory . Object , modelFactory , fileAggregateRepository . Object ) ;
223229
224230 var fileDetails = await manager . GetFile ( TestData . FileId , TestData . EstateId , CancellationToken . None ) ;
225-
231+ fileDetails . IsSuccess . ShouldBeTrue ( ) ;
226232 this . VerifyFile ( TestData . GetFileAggregateWithLines ( ) , fileDetails ) ;
227- fileDetails . UserEmailAddress . ShouldBe ( TestData . UserEmailAddress ) ;
233+ fileDetails . Data . UserEmailAddress . ShouldBe ( TestData . UserEmailAddress ) ;
228234 }
229235
230236 [ Fact ]
@@ -254,13 +260,13 @@ public async Task FileProcessingManager_GetFile_FileReturnedWithFileProfileName(
254260
255261 Mock < IAggregateRepository < FileAggregate , DomainEvent > > fileAggregateRepository =
256262 new Mock < IAggregateRepository < FileAggregate , DomainEvent > > ( ) ;
257- fileAggregateRepository . Setup ( f => f . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . GetFileAggregateWithLines ) ;
263+ fileAggregateRepository . Setup ( f => f . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( Result . Success ( TestData . GetFileAggregateWithLines ( ) ) ) ;
258264 FileProcessorManager manager = new FileProcessorManager ( fileProfiles , contextFactory . Object , modelFactory , fileAggregateRepository . Object ) ;
259265
260266 var fileDetails = await manager . GetFile ( TestData . FileId , TestData . EstateId , CancellationToken . None ) ;
261-
267+ fileDetails . IsSuccess . ShouldBeTrue ( ) ;
262268 this . VerifyFile ( TestData . GetFileAggregateWithLines ( ) , fileDetails ) ;
263- fileDetails . FileProfileName . ShouldBe ( TestData . SafaricomProfileName ) ;
269+ fileDetails . Data . FileProfileName . ShouldBe ( TestData . SafaricomProfileName ) ;
264270 }
265271
266272 [ Fact ]
@@ -274,73 +280,71 @@ public async Task FileProcessingManager_GetFile_FileNotFound_ErrorThrown()
274280
275281 Mock < IAggregateRepository < FileAggregate , DomainEvent > > fileAggregateRepository =
276282 new Mock < IAggregateRepository < FileAggregate , DomainEvent > > ( ) ;
277- fileAggregateRepository . Setup ( f => f . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . GetEmptyFileAggregate ) ;
283+ fileAggregateRepository . Setup ( f => f . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( Result . Success ( TestData . GetEmptyFileAggregate ( ) ) ) ;
278284 FileProcessorManager manager = new FileProcessorManager ( fileProfiles , contextFactory . Object , modelFactory , fileAggregateRepository . Object ) ;
279285
280- Should . Throw < NotFoundException > ( async ( ) =>
281- {
282- await manager . GetFile ( TestData . FileId , TestData . EstateId , CancellationToken . None ) ;
283- } ) ;
286+ var result = await manager . GetFile ( TestData . FileId , TestData . EstateId , CancellationToken . None ) ;
287+ result . IsFailed . ShouldBeTrue ( ) ;
288+ result . Status . ShouldBe ( ResultStatus . NotFound ) ;
284289 }
285290
286291
287- private void VerifyFile ( FileAggregate source , FileDetails fileDetails )
292+ private void VerifyFile ( FileAggregate source , Result < FileDetails > fileDetails )
288293 {
289294 var fileModel = source . GetFile ( ) ;
290295
291- fileDetails . FileId . ShouldBe ( fileModel . FileId ) ;
292- fileDetails . FileImportLogId . ShouldBe ( fileModel . FileImportLogId ) ;
293- fileDetails . FileLocation . ShouldBe ( fileModel . FileLocation ) ;
294- fileDetails . FileProfileId . ShouldBe ( fileModel . FileProfileId ) ;
295- fileDetails . MerchantId . ShouldBe ( fileModel . MerchantId ) ;
296- fileDetails . ProcessingCompleted . ShouldBe ( fileModel . ProcessingCompleted ) ;
297- fileDetails . UserId . ShouldBe ( fileModel . UserId ) ;
298- fileDetails . EstateId . ShouldBe ( fileModel . EstateId ) ;
299-
300- fileDetails . ProcessingSummary . ShouldNotBeNull ( ) ;
301- fileDetails . ProcessingSummary . FailedLines . ShouldBe ( fileModel . ProcessingSummary . FailedLines ) ;
302- fileDetails . ProcessingSummary . IgnoredLines . ShouldBe ( fileModel . ProcessingSummary . IgnoredLines ) ;
303- fileDetails . ProcessingSummary . NotProcessedLines . ShouldBe ( fileModel . ProcessingSummary . NotProcessedLines ) ;
304- fileDetails . ProcessingSummary . SuccessfullyProcessedLines . ShouldBe ( fileModel . ProcessingSummary . SuccessfullyProcessedLines ) ;
305- fileDetails . ProcessingSummary . TotalLines . ShouldBe ( fileModel . ProcessingSummary . TotalLines ) ;
296+ fileDetails . Data . FileId . ShouldBe ( fileModel . FileId ) ;
297+ fileDetails . Data . FileImportLogId . ShouldBe ( fileModel . FileImportLogId ) ;
298+ fileDetails . Data . FileLocation . ShouldBe ( fileModel . FileLocation ) ;
299+ fileDetails . Data . FileProfileId . ShouldBe ( fileModel . FileProfileId ) ;
300+ fileDetails . Data . MerchantId . ShouldBe ( fileModel . MerchantId ) ;
301+ fileDetails . Data . ProcessingCompleted . ShouldBe ( fileModel . ProcessingCompleted ) ;
302+ fileDetails . Data . UserId . ShouldBe ( fileModel . UserId ) ;
303+ fileDetails . Data . EstateId . ShouldBe ( fileModel . EstateId ) ;
304+
305+ fileDetails . Data . ProcessingSummary . ShouldNotBeNull ( ) ;
306+ fileDetails . Data . ProcessingSummary . FailedLines . ShouldBe ( fileModel . ProcessingSummary . FailedLines ) ;
307+ fileDetails . Data . ProcessingSummary . IgnoredLines . ShouldBe ( fileModel . ProcessingSummary . IgnoredLines ) ;
308+ fileDetails . Data . ProcessingSummary . NotProcessedLines . ShouldBe ( fileModel . ProcessingSummary . NotProcessedLines ) ;
309+ fileDetails . Data . ProcessingSummary . SuccessfullyProcessedLines . ShouldBe ( fileModel . ProcessingSummary . SuccessfullyProcessedLines ) ;
310+ fileDetails . Data . ProcessingSummary . TotalLines . ShouldBe ( fileModel . ProcessingSummary . TotalLines ) ;
306311
307312 foreach ( FileLine fileModelFileLine in fileModel . FileLines )
308313 {
309- FileLine ? fileLineToVerify = fileDetails . FileLines . SingleOrDefault ( f => f . LineNumber == fileModelFileLine . LineNumber ) ;
314+ FileLine ? fileLineToVerify = fileDetails . Data . FileLines . SingleOrDefault ( f => f . LineNumber == fileModelFileLine . LineNumber ) ;
310315 fileLineToVerify . ShouldNotBeNull ( ) ;
311316 fileLineToVerify . LineData . ShouldBe ( fileModelFileLine . LineData ) ;
312317 fileLineToVerify . TransactionId . ShouldBe ( fileModelFileLine . TransactionId ) ;
313318 fileLineToVerify . ProcessingResult . ShouldBe ( fileModelFileLine . ProcessingResult ) ;
314319 }
315320 }
316321
317- private void VerifyImportLogs ( List < EstateManagement . Database . Entities . FileImportLog > source , List < FIleProcessor . Models . FileImportLog > importLogs , Guid ? merchantId = null )
322+ private void VerifyImportLogs ( List < EstateManagement . Database . Entities . FileImportLog > source , Result < List < FileProcessor . Models . FileImportLog > > importLogs , Guid ? merchantId = null )
318323 {
319- importLogs . ShouldNotBeNull ( ) ;
320- importLogs . ShouldNotBeEmpty ( ) ;
321- importLogs . Count . ShouldBe ( TestData . FileImportLogs . Count ) ;
324+ importLogs . Data . ShouldNotBeNull ( ) ;
325+ importLogs . Data . ShouldNotBeEmpty ( ) ;
326+ importLogs . Data . Count . ShouldBe ( TestData . FileImportLogs . Count ) ;
322327 foreach ( EstateManagement . Database . Entities . FileImportLog fileImportLog in source )
323328 {
324- var importLog = importLogs . SingleOrDefault ( i => i . FileImportLogId == fileImportLog . FileImportLogId ) ;
329+ var importLog = importLogs . Data . SingleOrDefault ( i => i . FileImportLogId == fileImportLog . FileImportLogId ) ;
325330 VerifyImportLog ( fileImportLog , importLog , merchantId ) ;
326331 }
327332 }
328333
329- private void VerifyImportLog ( EstateManagement . Database . Entities . FileImportLog source , FIleProcessor . Models . FileImportLog importLog , Guid ? merchantId = null )
334+ private void VerifyImportLog ( EstateManagement . Database . Entities . FileImportLog source , Result < FileProcessor . Models . FileImportLog > importLog , Guid ? merchantId = null )
330335 {
331- importLog . ShouldNotBeNull ( ) ;
332- importLog . FileImportLogDateTime . ShouldBe ( source . ImportLogDateTime ) ;
333- importLog . Files . Count . ShouldBe ( importLog . Files . Count ) ;
334-
335- List < ImportLogFile > filesToVerify = importLog . Files ;
336+ importLog . Data . ShouldNotBeNull ( ) ;
337+ importLog . Data . FileImportLogDateTime . ShouldBe ( source . ImportLogDateTime ) ;
338+
339+ List < ImportLogFile > filesToVerify = importLog . Data . Files ;
336340 if ( merchantId . HasValue )
337341 {
338342 filesToVerify = filesToVerify . Where ( f => f . MerchantId == merchantId . Value ) . ToList ( ) ;
339343 }
340344
341345 foreach ( ImportLogFile importLogFile in filesToVerify )
342346 {
343- var file = importLog . Files . SingleOrDefault ( impfile => impfile . FileId == importLogFile . FileId ) ;
347+ var file = importLog . Data . Files . SingleOrDefault ( impfile => impfile . FileId == importLogFile . FileId ) ;
344348 file . ShouldNotBeNull ( ) ;
345349 file . MerchantId . ShouldBe ( importLogFile . MerchantId ) ;
346350 file . FilePath . ShouldBe ( importLogFile . FilePath ) ;
0 commit comments