Skip to content

Commit 5eb6042

Browse files
committed
Mock GetConfiguration for IPxFileConfigurationService
Add explicit setups for GetConfiguration() on IPxFileConfigurationService mocks in PXDataSourceTest.cs to ensure consistent return of PxFileConfigurationOptions during tests. Also add a private Mock<T>() stub for future use. Improves test reliability and configuration mocking.
1 parent 0122586 commit 5eb6042

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

PxWeb.UnitTests/DataSource/PXDataSourceTest.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public void ShouldReturnMenu()
6464
var memorymock = new Mock<IPxCache>();
6565
var configMock = new Mock<IPxApiConfigurationService>();
6666
var configServiceMock = new Mock<IPxFileConfigurationService>();
67+
configServiceMock.Setup(x => x.GetConfiguration()).Returns(new PxFileConfigurationOptions());
6768
var hostingEnvironmentMock = new Mock<IPxHost>();
6869
var loggerMock = new Mock<ILogger<TablePathResolverPxFile>>();
6970
var codelistMapperMock = new Mock<ICodelistMapper>();
@@ -150,6 +151,7 @@ public void TableExistPxFileShouldReturnTrue()
150151
var memorymock = new Mock<IPxCache>();
151152
var configMock = new Mock<IPxApiConfigurationService>();
152153
var configServiceMock = new Mock<IPxFileConfigurationService>();
154+
configServiceMock.Setup(x => x.GetConfiguration()).Returns(new PxFileConfigurationOptions());
153155
var hostingEnvironmentMock = new Mock<IPxHost>();
154156
var loggerMock = new Mock<ILogger<TablePathResolverPxFile>>();
155157
var codelistMapperMock = new Mock<ICodelistMapper>();
@@ -186,13 +188,16 @@ public void TableExistPXFileShouldNotReturnTrue()
186188
var memorymock = new Mock<IPxCache>();
187189
var configMock = new Mock<IPxApiConfigurationService>();
188190
var configServiceMock = new Mock<IPxFileConfigurationService>();
191+
configServiceMock.Setup(x => x.GetConfiguration()).Returns(new PxFileConfigurationOptions());
189192
var hostingEnvironmentMock = new Mock<IPxHost>();
190193
var loggerMock = new Mock<ILogger<TablePathResolverPxFile>>();
191194
var codelistMapperMock = new Mock<ICodelistMapper>();
192195

193196
var config = testFactory.GetPxApiConfiguration();
194197
configMock.Setup(x => x.GetConfiguration()).Returns(config);
195198

199+
configServiceMock.Setup(x => x.GetConfiguration()).Returns(new PxFileConfigurationOptions());
200+
196201
var itemLoggerMock = new Mock<ILogger<ItemSelectorResolverPxFactory>>();
197202
var pcAxisFactory = new ItemSelectorResolverPxFactory(configServiceMock.Object, hostingEnvironmentMock.Object, itemLoggerMock.Object);
198203

@@ -246,8 +251,12 @@ public void GetTablesPublishedBetween_WhenCalled_ReturnNonNull()
246251
.Setup(m => m.RootPath)
247252
.Returns(wwwPath);
248253

254+
255+
var configService = new Mock<IPxFileConfigurationService>();
256+
configService.Setup(x => x.GetConfiguration()).Returns(new PxFileConfigurationOptions());
257+
249258
var dataSource = new PxFileDataSource(
250-
new Mock<IPxFileConfigurationService>().Object,
259+
configService.Object,
251260
new Mock<IItemSelectionResolver>().Object,
252261
new Mock<ITablePathResolver>().Object,
253262
hostingEnvironmentMock.Object,
@@ -259,6 +268,11 @@ public void GetTablesPublishedBetween_WhenCalled_ReturnNonNull()
259268

260269
}
261270

271+
private object Mock<T>()
272+
{
273+
throw new NotImplementedException();
274+
}
275+
262276
private TablePathResolverPxFile GetTablePathResolver()
263277
{
264278
var testFactory = new TestFactory();
@@ -305,6 +319,7 @@ public void ShouldReturnMappingOfTableLanguages()
305319
var memorymock = new Mock<IPxCache>();
306320
var configMock = new Mock<IPxApiConfigurationService>();
307321
var configServiceMock = new Mock<IPxFileConfigurationService>();
322+
configServiceMock.Setup(x => x.GetConfiguration()).Returns(new PxFileConfigurationOptions());
308323
var hostingEnvironmentMock = new Mock<IPxHost>();
309324
var loggerMock = new Mock<ILogger<TablePathResolverPxFile>>();
310325
var codelistMapperMock = new Mock<ICodelistMapper>();
@@ -342,6 +357,7 @@ public void LoadDatabaseStructure_ShouldNotHaveDatabaseInId()
342357
var memorymock = new Mock<IPxCache>();
343358
var configMock = new Mock<IPxApiConfigurationService>();
344359
var configServiceMock = new Mock<IPxFileConfigurationService>();
360+
configServiceMock.Setup(x => x.GetConfiguration()).Returns(new PxFileConfigurationOptions());
345361
var hostingEnvironmentMock = new Mock<IPxHost>();
346362
var loggerMock = new Mock<ILogger<TablePathResolverPxFile>>();
347363
var codelistMapperMock = new Mock<ICodelistMapper>();

0 commit comments

Comments
 (0)