-
Notifications
You must be signed in to change notification settings - Fork 352
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
Fixing CopyFrom method in OdataMessageReader and OdataMessageWriter to include Arraypool #1595
Changes from all commits
1700fe9
84a1478
9a786ed
2f5ba1b
1345914
00685d0
6f277b7
0cddbf5
5fa540e
bbfbdaa
bd57e09
a2471c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,24 +187,9 @@ private void CompareMessageReaderSettings(ODataMessageReaderSettings expected, O | |
{ | ||
return; | ||
} | ||
|
||
Assert.True(expected != null, "expected settings cannot be null"); | ||
Assert.True(actual != null, "actual settings cannot be null"); | ||
Assert.True(expected.Validations == actual.Validations, "Validations does not match"); | ||
Assert.True(Uri.Compare(expected.BaseUri, actual.BaseUri, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.CurrentCulture) == 0, | ||
"BaseUri does not match"); | ||
Assert.True(expected.ClientCustomTypeResolver == actual.ClientCustomTypeResolver, "ClientCustomTypeResolver does not match"); | ||
Assert.True(expected.PrimitiveTypeResolver == actual.PrimitiveTypeResolver, "PrimitiveTypeResolver does not match"); | ||
Assert.True(expected.EnableMessageStreamDisposal == actual.EnableMessageStreamDisposal, "EnableMessageStreamDisposal does not match"); | ||
Assert.True(expected.EnablePrimitiveTypeConversion == actual.EnablePrimitiveTypeConversion, "EnablePrimitiveTypeConversion does not match"); | ||
Assert.True(expected.EnableCharactersCheck == actual.EnableCharactersCheck, "CheckCharacters does not match"); | ||
Assert.True(expected.ShouldIncludeAnnotation == actual.ShouldIncludeAnnotation, "UseKeyAsSegment does not match"); | ||
Assert.True(expected.Validations == actual.Validations, "Validations does not match"); | ||
Assert.True(expected.MaxProtocolVersion == actual.MaxProtocolVersion, "MaxProtocolVersion does not match."); | ||
Assert.True(expected.MessageQuotas.MaxPartsPerBatch == actual.MessageQuotas.MaxPartsPerBatch, "MaxPartsPerBatch does not match"); | ||
Assert.True(expected.MessageQuotas.MaxOperationsPerChangeset == actual.MessageQuotas.MaxOperationsPerChangeset, "MaxOperationsPerChangeset does not match"); | ||
Assert.True(expected.MessageQuotas.MaxNestingDepth == actual.MessageQuotas.MaxNestingDepth, "MaxNestingDepth does not match"); | ||
Assert.True(expected.MessageQuotas.MaxReceivedMessageSize == actual.MessageQuotas.MaxReceivedMessageSize, "MaxMessageSize does not match"); | ||
|
||
var differences = ValidationHelper.GetDifferences<ODataMessageReaderSettings>(expected, actual); | ||
Assert.True(differences.Count == 0, String.Join(",", differences)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
remove the unused whitespace |
||
} | ||
|
||
[Fact] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//--------------------------------------------------------------------- | ||
// <copyright file="TestCharArrayPool.cs" company="Microsoft"> | ||
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
// </copyright> | ||
//--------------------------------------------------------------------- | ||
|
||
using System; | ||
using Microsoft.OData.Buffers; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copyright There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved |
||
namespace Microsoft.OData.Tests | ||
{ | ||
public class TestCharArrayPool : ICharArrayPool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember I had a default implementation for ICharArrayPool. Don't I? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kept the Testchararraypool as such to be reused later as the the testarraypool implementation was inside another class file. |
||
{ | ||
public char[] Buffer { get { return Rent(MinSize); } } | ||
|
||
public int MinSize { set; get; } | ||
|
||
public TestCharArrayPool(int minSize) | ||
{ | ||
this.MinSize = minSize; | ||
} | ||
|
||
public char[] Rent(int minSize) | ||
{ | ||
return new char[minSize]; | ||
} | ||
|
||
public void Return(char[] array) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
//--------------------------------------------------------------------- | ||
// <copyright file="ValidationHelper.cs" company="Microsoft"> | ||
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
// </copyright> | ||
//--------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copyright There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. REsolved |
||
using System.Reflection; | ||
|
||
namespace Microsoft.OData.Tests | ||
{ | ||
public static class ValidationHelper | ||
{ | ||
/// <summary> | ||
/// This method takes 2 generic types and see if one is the deep copy of other | ||
/// </summary> | ||
/// <typeparam name="T">Method accepts Generic type</typeparam> | ||
/// <param name="obj">Object to be compared with</param> | ||
/// <param name="copy">Copy object to compare</param> | ||
/// <returns>Returns a list of differences</returns> | ||
public static List<string> GetDifferences<T>(T obj, T copy) | ||
{ | ||
var diff = new List<string>(); | ||
EvaluateDifferences(obj, copy, diff); | ||
|
||
return diff; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// To evaluate the differences of 2 generic types, called recursively | ||
/// </summary> | ||
/// <typeparam name="T">Method accepts Generic type</typeparam> | ||
/// <param name="obj">Object to be compared with</param> | ||
/// <param name="copy">Copy object to compare</param> | ||
/// <param name="diff">List Of Differences</param> | ||
/// <param name="objName">Optional parameter for objectname, to be used in differences string, default empty string</param> | ||
/// <param name="isCollection">Optional parameter to see if its a collection, default false</param> | ||
private static void EvaluateDifferences<T>(T obj, T copy, List<string> diff,string objName ="", bool isCollection =false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
add the whitespace correctly. for example: |
||
{ | ||
if (obj == null && copy == null) | ||
{ | ||
return; | ||
} | ||
|
||
string collectionStatement = isCollection?" collection":string.Empty; | ||
|
||
if (obj == null || copy == null) | ||
{ | ||
diff.Add(string.Format("Value of{0} {1} does not match", collectionStatement, objName)); | ||
return; | ||
} | ||
|
||
var objType = obj.GetType(); | ||
|
||
if (typeof(Uri) == objType) | ||
{ | ||
if (Uri.Compare(new Uri(obj.ToString()), new Uri(copy.ToString()), UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.CurrentCulture) != 0) | ||
{ | ||
diff.Add(string.Format("Value of Uri{0} {1} does not match.", collectionStatement,objName)); | ||
} | ||
} | ||
else if (typeof(IComparable).IsAssignableFrom(objType) || objType.IsPrimitive() || objType.IsValueType()) | ||
{ | ||
if ((!obj.Equals(copy))) | ||
{ | ||
diff.Add(string.Format("Value of{0} {1} does not match.",collectionStatement, objName)); | ||
} | ||
} | ||
else if (objType.IsArray || typeof(IEnumerable).IsAssignableFrom(objType)) | ||
{ | ||
var collection1 = ((IEnumerable)obj).Cast<object>(); | ||
var collection2 = ((IEnumerable)copy).Cast<object>(); | ||
|
||
if (collection1.Count() != collection2.Count()) | ||
{ | ||
diff.Add(string.Format("Collection count of {0} does not match.", objName)); | ||
} | ||
else | ||
{ | ||
for (int i = 0; i < collection1.Count(); i++) | ||
{ | ||
var element1 = collection1.ElementAt(i); | ||
var element2 = collection2.ElementAt(i); | ||
|
||
EvaluateDifferences(element1, element2, diff, collection1.GetType().Name, true); | ||
} | ||
} | ||
} | ||
else if ( objType.IsClass()) | ||
{ | ||
foreach (var prop in obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanRead && x.CanWrite)) | ||
{ | ||
var val1 = prop.GetValue(obj); | ||
var val2 = prop.GetValue(copy); | ||
|
||
EvaluateDifferences(val1, val2, diff,prop.Name); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add the "GetDifferences" function call, how about the codes from Line 191 to Line 207?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't want to change the existing code. Existing lines will function as such
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's my concern. It seems we verify the same twice.
In reply to: 348177998 [](ancestors = 348177998)