Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility tests for Table extension #26038

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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