Skip to content

Commit 64b9a63

Browse files
fix: sonar issues.
1 parent 0d68d3b commit 64b9a63

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/Liquid.Dataverse/DataverseClientFactory.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ public class DataverseClientFactory : IDataverseClientFactory
1616
/// <exception cref="ArgumentNullException"></exception>
1717
public DataverseClientFactory(IOptions<DataverseSettings> options)
1818
{
19-
if (options is null)
20-
{
21-
throw new ArgumentNullException(nameof(options));
22-
}
19+
ArgumentNullException.ThrowIfNull(options);
2320

2421
_options = options;
2522
}
2623

24+
///<inheritdoc/>
2725
[ExcludeFromCodeCoverage]
28-
///<inheritdoc/>
2926
public IOrganizationServiceAsync GetClient()
3027
{
3128
var settings = _options.Value;

src/Liquid.Dataverse/DataverseEntityMapper.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ public DataverseEntityMapper(ILiquidDataverse adapter) : base(nameof(DataverseEn
3030
///<inheritdoc/>
3131
protected override async Task<Entity> MapImpl(string jsonString, string? entityName = null)
3232
{
33-
if (entityName == null) { throw new ArgumentNullException(nameof(entityName)); }
33+
ArgumentNullException.ThrowIfNull(entityName);
3434

3535
var entityAttributes = await GetEntityAttributes(entityName);
3636

37+
if (entityAttributes == null)
38+
throw new ArgumentNullException(nameof(entityAttributes), $"Entity {entityName} not found.");
39+
3740
var entity = JsonToEntity(entityAttributes, jsonString);
3841

3942
return entity;
4043
}
4144

42-
private async Task<List<AttributeMetadata>> GetEntityAttributes(string entityName, List<string>? noMappingFields = null)
45+
private async Task<List<AttributeMetadata>?> GetEntityAttributes(string entityName, List<string>? noMappingFields = null)
4346
{
4447
var entityMetadata = _entitiesMetadata.FirstOrDefault(x => x.Key == entityName).Value;
4548

@@ -67,15 +70,21 @@ private async Task<List<AttributeMetadata>> GetEntityAttributes(string entityNam
6770

6871
return listAttributes;
6972
}
70-
private Entity JsonToEntity(List<AttributeMetadata> attributes, string values)
73+
private static Entity JsonToEntity(List<AttributeMetadata> attributes, string values)
7174
{
7275
var entidade = new Entity();
7376
var valuesObject = JsonConvert.DeserializeObject<JObject>(values);
77+
if (valuesObject == null)
78+
return entidade;
7479

7580
foreach (var atrribute in attributes)
7681
{
7782
var logicalName = atrribute.LogicalName.ToUpper();
78-
if (valuesObject[logicalName] != null && valuesObject[logicalName].ToString() != "")
83+
84+
if (valuesObject[logicalName] == null)
85+
continue;
86+
87+
if (valuesObject[logicalName].ToString() != "")
7988
{
8089

8190
switch (atrribute.AttributeType.ToString())

0 commit comments

Comments
 (0)