Skip to content

Commit

Permalink
Add compatibility tests for Table extension (#26038)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym authored Dec 28, 2021
1 parent abcb757 commit 1ac7d4c
Show file tree
Hide file tree
Showing 4 changed files with 586 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ protected override void Set<T>(TableEntity destination, T value, BoundMemberInfo
}
else
{
// TODO: this is new. Who handled this before?
// TODO: indented?
destination[memberInfo.Name] = JsonConvert.SerializeObject(value, Formatting.Indented);
}
}
Expand Down Expand Up @@ -112,14 +110,6 @@ protected override bool TryGet<T>(BoundMemberInfo memberInfo, TableEntity source
{
value = (T)(object) source.GetInt64(key);
}
else if (typeof(T) == typeof(ulong))
{
value = (T)(object) source.GetInt64(key);
}
else if (typeof(T) == typeof(ulong?))
{
value = (T)(object) source.GetInt64(key);
}
else if (typeof(T) == typeof(double))
{
value = (T) Convert.ChangeType(propertyValue, typeof(double), CultureInfo.InvariantCulture);
Expand Down Expand Up @@ -187,9 +177,8 @@ protected override bool TryGet<T>(BoundMemberInfo memberInfo, TableEntity source
{
value = (T)(object) new ETag(source.GetString(key));
}
else if (typeof(T) == typeof(TimeSpan))
else
{
// TODO: this is new. Who handled this before?
value = JsonConvert.DeserializeObject<T>(source.GetString(key));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ private static JObject ConvertEntityToJObject(TableEntity tableEntity)
JObject jsonObject = new JObject();
foreach (var entityProperty in tableEntity)
{
JToken value = JToken.FromObject(entityProperty.Value);
// V4 compatibility
if (string.Compare(entityProperty.Key, "odata.etag", StringComparison.OrdinalIgnoreCase) == 0 ||
string.Compare(entityProperty.Key, "timestamp", StringComparison.OrdinalIgnoreCase) == 0)
{
continue;
}

jsonObject.Add(entityProperty.Key, value);
jsonObject.Add(entityProperty.Key, new JValue(entityProperty.Value));
}
return jsonObject;
}
Expand All @@ -145,8 +150,14 @@ private static TableEntity CreateTableEntityFromJObject(string partitionKey, str
TableEntity tableEntity = new TableEntity(partitionKey, rowKey);
foreach (JProperty property in entity.Properties())
{
// TODO: validation?
tableEntity[property.Name] = ((JValue)property.Value).Value;
if (property.Value is JValue value)
{
tableEntity[property.Name] = value.Value;
}
else
{
tableEntity[property.Name] = property.Value.ToString();
}
}

return tableEntity;
Expand Down
Loading

0 comments on commit 1ac7d4c

Please sign in to comment.