@@ -67,7 +67,7 @@ public async Task FileProcessingManager_GetFileImportLogs_NoMerchantId_ImportLog
6767
6868 var importLogs = await manager . GetFileImportLogs ( TestData . EstateId , TestData . ImportLogStartDate , TestData . ImportLogEndDate , null , CancellationToken . None ) ;
6969
70- this . VerifyImportLogs ( importLogs ) ;
70+ this . VerifyImportLogs ( TestData . FileImportLogs , importLogs ) ;
7171 }
7272
7373 [ Fact ]
@@ -88,57 +88,87 @@ public async Task FileProcessingManager_GetFileImportLogs_WithMerchantId_ImportL
8888
8989 var importLogs = await manager . GetFileImportLogs ( TestData . EstateId , TestData . ImportLogStartDate , TestData . ImportLogEndDate , TestData . MerchantId , CancellationToken . None ) ;
9090
91- this . VerifyImportLogs ( importLogs , TestData . MerchantId ) ;
91+ this . VerifyImportLogs ( TestData . FileImportLogs , importLogs , TestData . MerchantId ) ;
9292 }
9393
94- private void VerifyImportLogs ( List < FIleProcessor . Models . FileImportLog > importLogs , Guid ? merchantId = null )
94+ [ Fact ]
95+ public async Task FileProcessingManager_GetFileImportLog_NoMerchantId_ImportLogReturned ( )
96+ {
97+ var fileProfiles = TestData . FileProfiles ;
98+ var context = await this . GetContext ( Guid . NewGuid ( ) . ToString ( "N" ) ) ;
99+ var contextFactory = this . CreateMockContextFactory ( ) ;
100+ contextFactory . Setup ( c => c . GetContext ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( context ) ;
101+ IModelFactory modelFactory = new ModelFactory ( ) ;
102+
103+ context . FileImportLogs . AddRange ( TestData . FileImportLogs ) ;
104+ context . FileImportLogFiles . AddRange ( TestData . FileImportLog1Files ) ;
105+ context . FileImportLogFiles . AddRange ( TestData . FileImportLog2Files ) ;
106+ context . SaveChanges ( ) ;
107+
108+ FileProcessorManager manager = new FileProcessorManager ( fileProfiles , contextFactory . Object , modelFactory ) ;
109+
110+ var importLog = await manager . GetFileImportLog ( TestData . FileImportLogId1 , TestData . EstateId , null , CancellationToken . None ) ;
111+
112+ this . VerifyImportLog ( TestData . FileImportLogs . First ( ) , importLog ) ;
113+ }
114+
115+ [ Fact ]
116+ public async Task FileProcessingManager_GetFileImportLog_WithMerchantId_ImportLogReturned ( )
117+ {
118+ var fileProfiles = TestData . FileProfiles ;
119+ var context = await this . GetContext ( Guid . NewGuid ( ) . ToString ( "N" ) ) ;
120+ var contextFactory = this . CreateMockContextFactory ( ) ;
121+ contextFactory . Setup ( c => c . GetContext ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( context ) ;
122+ IModelFactory modelFactory = new ModelFactory ( ) ;
123+
124+ context . FileImportLogs . AddRange ( TestData . FileImportLogs ) ;
125+ context . FileImportLogFiles . AddRange ( TestData . FileImportLog1Files ) ;
126+ context . FileImportLogFiles . AddRange ( TestData . FileImportLog2Files ) ;
127+ context . SaveChanges ( ) ;
128+
129+ FileProcessorManager manager = new FileProcessorManager ( fileProfiles , contextFactory . Object , modelFactory ) ;
130+
131+ var importLog = await manager . GetFileImportLog ( TestData . FileImportLogId1 , TestData . EstateId , TestData . MerchantId , CancellationToken . None ) ;
132+
133+ this . VerifyImportLog ( TestData . FileImportLogs . First ( ) , importLog , TestData . MerchantId ) ;
134+ }
135+
136+ private void VerifyImportLogs ( List < FileImportLog > source , List < FIleProcessor . Models . FileImportLog > importLogs , Guid ? merchantId = null )
95137 {
96138 importLogs . ShouldNotBeNull ( ) ;
97139 importLogs . ShouldNotBeEmpty ( ) ;
98140 importLogs . Count . ShouldBe ( TestData . FileImportLogs . Count ) ;
99- foreach ( FileImportLog fileImportLog in TestData . FileImportLogs )
141+ foreach ( FileImportLog fileImportLog in source )
100142 {
101143 var importLog = importLogs . SingleOrDefault ( i => i . FileImportLogId == fileImportLog . FileImportLogId ) ;
102- importLog . ShouldNotBeNull ( ) ;
103- importLog . FileImportLogDateTime . ShouldBe ( fileImportLog . ImportLogDateTime ) ;
104- importLog . Files . Count . ShouldBe ( importLog . Files . Count ) ;
105-
106- List < ImportLogFile > filesToVerify = importLog . Files ;
107- if ( merchantId . HasValue )
108- {
109- filesToVerify = filesToVerify . Where ( f => f . MerchantId == merchantId . Value ) . ToList ( ) ;
110- }
111-
112- foreach ( ImportLogFile importLogFile in filesToVerify )
113- {
114- var file = importLog . Files . SingleOrDefault ( impfile => impfile . FileId == importLogFile . FileId ) ;
115- file . ShouldNotBeNull ( ) ;
116- file . MerchantId . ShouldBe ( importLogFile . MerchantId ) ;
117- file . FilePath . ShouldBe ( importLogFile . FilePath ) ;
118- file . FileProfileId . ShouldBe ( importLogFile . FileProfileId ) ;
119- file . OriginalFileName . ShouldBe ( importLogFile . OriginalFileName ) ;
120- file . UserId . ShouldBe ( importLogFile . UserId ) ;
121- }
144+ VerifyImportLog ( fileImportLog , importLog , merchantId ) ;
122145 }
123146 }
124147
125- //[Fact]
126- //public async Task FileProcessingManager_GetFileImportLogs_WithMerchantId_ImportLogsReturned()
127- //{
128- // var fileProfiles = TestData.FileProfiles;
129- // var contextFactory = this.CreateMockContextFactory();
130- // IModelFactory modelFactory = new ModelFactory();
131- // FileProcessorManager manager = new FileProcessorManager(fileProfiles, contextFactory.Object, modelFactory);
132-
133- // var importLogs = await manager.GetFileImportLogs(TestData.EstateId, TestData.ImportLogStartDate, TestData.ImportLogEndDate, TestData.MerchantId, CancellationToken.None);
134-
135- // importLogs.ShouldNotBeNull();
136- // importLogs.ShouldNotBeEmpty();
137- // importLogs.Count.ShouldBe(2);
138-
148+ private void VerifyImportLog ( FileImportLog source , FIleProcessor . Models . FileImportLog importLog , Guid ? merchantId = null )
149+ {
150+ importLog . ShouldNotBeNull ( ) ;
151+ importLog . FileImportLogDateTime . ShouldBe ( source . ImportLogDateTime ) ;
152+ importLog . Files . Count . ShouldBe ( importLog . Files . Count ) ;
139153
140- //}
154+ List < ImportLogFile > filesToVerify = importLog . Files ;
155+ if ( merchantId . HasValue )
156+ {
157+ filesToVerify = filesToVerify . Where ( f => f . MerchantId == merchantId . Value ) . ToList ( ) ;
158+ }
141159
160+ foreach ( ImportLogFile importLogFile in filesToVerify )
161+ {
162+ var file = importLog . Files . SingleOrDefault ( impfile => impfile . FileId == importLogFile . FileId ) ;
163+ file . ShouldNotBeNull ( ) ;
164+ file . MerchantId . ShouldBe ( importLogFile . MerchantId ) ;
165+ file . FilePath . ShouldBe ( importLogFile . FilePath ) ;
166+ file . FileProfileId . ShouldBe ( importLogFile . FileProfileId ) ;
167+ file . OriginalFileName . ShouldBe ( importLogFile . OriginalFileName ) ;
168+ file . UserId . ShouldBe ( importLogFile . UserId ) ;
169+ }
170+ }
171+
142172 private Mock < Shared . EntityFramework . IDbContextFactory < EstateReportingContext > > CreateMockContextFactory ( )
143173 {
144174 return new Mock < Shared . EntityFramework . IDbContextFactory < EstateReportingContext > > ( ) ;
0 commit comments