Skip to content

Commit

Permalink
PR comments - rename and fix assert
Browse files Browse the repository at this point in the history
  • Loading branch information
Maya-Painter committed Nov 8, 2023
1 parent ad0881a commit 5dac219
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public string Serialize(object value, MemberExpression memberExpression, Type me
CustomAttributeData typeAttribute = memberType.GetsCustomAttributes().FirstOrDefault(ca => ca.AttributeType == typeof(Newtonsoft.Json.JsonConverterAttribute));
CustomAttributeData converterAttribute = memberAttribute ?? typeAttribute;

Debug.Assert(converterAttribute.ConstructorArguments.Count > 0);
Debug.Assert(converterAttribute.ConstructorArguments.Count > 0, $"{nameof(DefaultCosmosLinqSerializer)} Assert!", "At least one constructor argument exists.");
Type converterType = (Type)converterAttribute.ConstructorArguments[0].Value;

string serializedValue = converterType.GetConstructor(Type.EmptyTypes) != null
Expand All @@ -63,7 +63,7 @@ public string SerializeScalarExpression(ConstantExpression inputExpression)
return JsonConvert.SerializeObject(inputExpression.Value);
}

public string GetMemberName(MemberInfo memberInfo, CosmosLinqSerializerOptions linqSerializerOptions = null)
public string SerializeMemberName(MemberInfo memberInfo, CosmosLinqSerializerOptions linqSerializerOptions = null)
{
string memberName = null;

Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/Linq/ICosmosLinqSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ internal interface ICosmosLinqSerializer
string SerializeScalarExpression(ConstantExpression inputExpression);

/// <summary>
/// Gets a member name with LINQ serializer options applied.
/// Serializes a member name with LINQ serializer options applied.
/// </summary>
string GetMemberName(MemberInfo memberInfo, CosmosLinqSerializerOptions linqSerializerOptions = null);
string SerializeMemberName(MemberInfo memberInfo, CosmosLinqSerializerOptions linqSerializerOptions = null);
}
}
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Linq/TypeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static Type GetElementType(Type type)

public static string GetMemberName(this MemberInfo memberInfo, TranslationContext context)
{
return context.CosmosLinqSerializer.GetMemberName(memberInfo, context.LinqSerializerOptions);
return context.CosmosLinqSerializer.SerializeMemberName(memberInfo, context.LinqSerializerOptions);
}

private static Type GetElementType(Type type, HashSet<Type> visitedSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ public Datum2(string jsonProperty, string dataMember, string defaultMember, stri
public void TestAttributePriority()
{
ICosmosLinqSerializer cosmosLinqSerializer = new DefaultCosmosLinqSerializer();
Assert.AreEqual("jsonProperty", cosmosLinqSerializer.GetMemberName(typeof(Datum).GetMember("JsonProperty").First()));
Assert.AreEqual("dataMember", cosmosLinqSerializer.GetMemberName(typeof(Datum).GetMember("DataMember").First()));
Assert.AreEqual("Default", cosmosLinqSerializer.GetMemberName(typeof(Datum).GetMember("Default").First()));
Assert.AreEqual("jsonPropertyHasHigherPriority", cosmosLinqSerializer.GetMemberName(typeof(Datum).GetMember("JsonPropertyAndDataMember").First()));
Assert.AreEqual("jsonProperty", cosmosLinqSerializer.SerializeMemberName(typeof(Datum).GetMember("JsonProperty").First()));
Assert.AreEqual("dataMember", cosmosLinqSerializer.SerializeMemberName(typeof(Datum).GetMember("DataMember").First()));
Assert.AreEqual("Default", cosmosLinqSerializer.SerializeMemberName(typeof(Datum).GetMember("Default").First()));
Assert.AreEqual("jsonPropertyHasHigherPriority", cosmosLinqSerializer.SerializeMemberName(typeof(Datum).GetMember("JsonPropertyAndDataMember").First()));
}

/// <summary>
Expand Down

0 comments on commit 5dac219

Please sign in to comment.