Skip to content

Commit

Permalink
fix: ConvertSingleEntity skip nullable properties with no value
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeStevens318 committed May 18, 2021
1 parent 07eb475 commit fba6a00
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Core/Requests/RequestDataConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ internal object ConvertSingleEntity(ExpandoObject dynamicObject, object dto)
_logger.LogDebug("Have target prop? '{0}' with name: '{1}' and actual value: '{2}'", targetProp != null,
dynamicProp.Key, dynamicValue);

// skip any nullable properties with a empty value
if (Nullable.GetUnderlyingType(targetProp.PropertyType) != null && string.IsNullOrEmpty(dynamicValue.ToString()))
continue;

targetProp?.SetValue(dto, dynamicValue.GetType() == targetProp.PropertyType
? dynamicValue
: Convert.ChangeType(dynamicValue, Nullable.GetUnderlyingType(targetProp.PropertyType) ?? targetProp.PropertyType));
Expand Down
48 changes: 46 additions & 2 deletions test/integration/Deal/HubSpotDealClientIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,58 @@ public async Task List()
var deals =
await _client.ListAsync<DealListHubSpotEntity<DealHubSpotEntity>>(new DealListRequestOptions
{
PropertiesToInclude = new List<string> { "dealname", "amount" },
PropertiesToInclude = new List<string> { "dealname", "amount", "hubspot_owner_id" },
NumberOfDealsToReturn = 2
});

Assert.NotNull(deals);
Assert.NotNull(deals.Deals);
Assert.NotEmpty(deals.Deals);
Assert.True(deals.Deals.Count > 1, "contacts.Deals.Count > 1");
Assert.True(deals.Deals.Count > 1, "deals.Deals.Count > 1");
}

[Fact]
public async Task ListAll()
{
if (_isAppVeyorEnv)
{
Output.WriteLine("Skipping test as we're in AppVeyor, demo account does return 3 results");
Assert.True(true);
return;
}

var deals = new List<DealHubSpotEntity>();
var moreResults = true;
long offset = 0;

while (moreResults)
{
var pagedDeals = await _client.ListAsync<DealListHubSpotEntity<DealHubSpotEntity>>(new DealListRequestOptions
{
PropertiesToInclude = new List<string>
{
"dealname",
"dealstage",
"pipeline",
"hubspot_owner_id",
"closedate",
"amount",
"dealtype"
},
NumberOfDealsToReturn = 150,
DealOffset = offset
});

deals.AddRange(pagedDeals.Deals);

moreResults = pagedDeals.MoreResultsAvailable;
if (moreResults)
offset = pagedDeals.ContinuationOffset;
}

Assert.NotNull(deals);
Assert.NotEmpty(deals);
Assert.True(deals.Count > 1, "deals.Count > 1");
}


Expand Down

0 comments on commit fba6a00

Please sign in to comment.