Skip to content

Commit 4d53e7e

Browse files
authored
Exposing the field mappings helpers through interface. (#1965)
## Why make this change? We use the ISqlMetadataProvider to interact with the metadataprovider of a class. This method helps get access to the field mappings for an entity. With the current code, it is not possible to access field mappings of an entity. ## What is this change? Add interface definitions in the ISqlMetadataProvider class. ## How was this tested? Current tests should cover this
1 parent 95549b1 commit 4d53e7e

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

src/Core/Services/MetadataProviders/CosmosSqlMetadataProvider.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,5 +351,15 @@ public bool IsDevelopmentMode()
351351
{
352352
return _runtimeConfig.IsDevelopmentMode();
353353
}
354+
355+
public bool TryGetExposedFieldToBackingFieldMap(string entityName, [NotNullWhen(true)] out IReadOnlyDictionary<string, string>? mappings)
356+
{
357+
throw new NotImplementedException();
358+
}
359+
360+
public bool TryGetBackingFieldToExposedFieldMap(string entityName, [NotNullWhen(true)] out IReadOnlyDictionary<string, string>? mappings)
361+
{
362+
throw new NotImplementedException();
363+
}
354364
}
355365
}

src/Core/Services/MetadataProviders/ISqlMetadataProvider.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ bool VerifyForeignKeyExistsInDB(
123123
/// <returns></returns>
124124
public IReadOnlyDictionary<string, DatabaseObject> GetEntityNamesAndDbObjects();
125125

126+
/// <summary>
127+
/// Given entity name, gets the map of exposed field to backing field mappings.
128+
/// </summary>
129+
public bool TryGetExposedFieldToBackingFieldMap(string entityName, [NotNullWhen(true)] out IReadOnlyDictionary<string, string>? mappings);
130+
131+
/// <summary>
132+
/// Given entity name, gets the map of backing field to exposed field mappings.
133+
/// </summary>
134+
public bool TryGetBackingFieldToExposedFieldMap(string entityName, [NotNullWhen(true)] out IReadOnlyDictionary<string, string>? mappings);
135+
126136
/// <summary>
127137
/// Gets Partition Key Path of a database container.
128138
/// </summary>

src/Core/Services/MetadataProviders/SqlMetadataProvider.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,8 @@ public async Task InitializeAsync()
284284
_logger.LogTrace($"Done inferring Sql database schema in {timer.ElapsedMilliseconds}ms.");
285285
}
286286

287-
/// <summary>
288-
/// Given entity name, gets the entity to column mappings if present.
289-
/// </summary>
290-
public bool TryGetEntityToColumnMappings(string entityName, [NotNullWhen(true)] out IReadOnlyDictionary<string, string>? mappings)
287+
/// <inheritdoc/>
288+
public bool TryGetExposedFieldToBackingFieldMap(string entityName, [NotNullWhen(true)] out IReadOnlyDictionary<string, string>? mappings)
291289
{
292290
Dictionary<string, string>? entityToColumnMappings;
293291
mappings = null;
@@ -300,10 +298,8 @@ public bool TryGetEntityToColumnMappings(string entityName, [NotNullWhen(true)]
300298
return false;
301299
}
302300

303-
/// <summary>
304-
/// Given entity name, gets the column to entity mappings if present.
305-
/// </summary>
306-
public bool TryGetColumnToEntityMappings(string entityName, [NotNullWhen(true)] out IReadOnlyDictionary<string, string>? mappings)
301+
/// <inheritdoc/>
302+
public bool TryGetBackingFieldToExposedFieldMap(string entityName, [NotNullWhen(true)] out IReadOnlyDictionary<string, string>? mappings)
307303
{
308304
Dictionary<string, string>? columntoEntityMappings;
309305
mappings = null;

src/Service.Tests/Unittests/SqlMetadataProviderUnitTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ public async Task CheckGetFieldMappings()
250250
await _sqlMetadataProvider.InitializeAsync();
251251

252252
MsSqlMetadataProvider metadataProvider = (MsSqlMetadataProvider)_sqlMetadataProvider;
253-
Assert.IsFalse(metadataProvider.TryGetColumnToEntityMappings("InvalidEntity", out _), "Column to entity mappings should not exist for invalid entity.");
254-
Assert.IsFalse(metadataProvider.TryGetEntityToColumnMappings("invalidEntity", out _), "Entity to column mappings should not exist for invalid entity.");
255-
Assert.IsTrue(metadataProvider.TryGetEntityToColumnMappings("Publisher", out IReadOnlyDictionary<string, string> _), "Entity to column mappings should exist for valid entity.");
256-
Assert.IsTrue(metadataProvider.TryGetColumnToEntityMappings("Publisher", out IReadOnlyDictionary<string, string> _), "Column to entity mappings should exist for valid entity.");
253+
Assert.IsFalse(metadataProvider.TryGetBackingFieldToExposedFieldMap("InvalidEntity", out _), "Column to entity mappings should not exist for invalid entity.");
254+
Assert.IsFalse(metadataProvider.TryGetExposedFieldToBackingFieldMap("invalidEntity", out _), "Entity to column mappings should not exist for invalid entity.");
255+
Assert.IsTrue(metadataProvider.TryGetExposedFieldToBackingFieldMap("Publisher", out IReadOnlyDictionary<string, string> _), "Entity to column mappings should exist for valid entity.");
256+
Assert.IsTrue(metadataProvider.TryGetBackingFieldToExposedFieldMap("Publisher", out IReadOnlyDictionary<string, string> _), "Column to entity mappings should exist for valid entity.");
257257

258258
TestHelper.UnsetAllDABEnvironmentVariables();
259259
}

0 commit comments

Comments
 (0)