-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix setting of json serializer to ignore self referencing loop (#796)
* Dont pick package from fallbackPackageFolders as we want all the packages in vstest\package folder * Issue: 1) #706 2) #618 Fix: Don’t serialize the type if that have self-referencing loop * Address PR comment. * Log the exception in EqtTrace thrown from OnDiscoveryAbort and OnTestRunAbort
- Loading branch information
1 parent
a657e1e
commit 333752b
Showing
5 changed files
with
123 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/JsonDataSerializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.TestPlatform.CommunicationUtilities.UnitTests | ||
{ | ||
using System; | ||
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class JsonDataSerializerTests | ||
{ | ||
[TestMethod] | ||
public void SerializePayloadShouldSerializeAnObjectWithSelfReferencingLoop() | ||
{ | ||
var classWithSelfReferencingLoop = new ClassWithSelfReferencingLoop(null); | ||
classWithSelfReferencingLoop = new ClassWithSelfReferencingLoop(classWithSelfReferencingLoop); | ||
classWithSelfReferencingLoop.InfiniteRefernce.InfiniteRefernce = classWithSelfReferencingLoop; | ||
|
||
var sut = JsonDataSerializer.Instance; | ||
|
||
// This line should not throw exception | ||
sut.SerializePayload("dummy", classWithSelfReferencingLoop); | ||
} | ||
|
||
[TestMethod] | ||
public void DeserializeShouldDeserializeAnObjectWhichHadSelfReferencingLoopBeforeSerialization() | ||
{ | ||
var classWithSelfReferencingLoop = new ClassWithSelfReferencingLoop(null); | ||
classWithSelfReferencingLoop = new ClassWithSelfReferencingLoop(classWithSelfReferencingLoop); | ||
classWithSelfReferencingLoop.InfiniteRefernce.InfiniteRefernce = classWithSelfReferencingLoop; | ||
|
||
var sut = JsonDataSerializer.Instance; | ||
|
||
var json = sut.SerializePayload("dummy", classWithSelfReferencingLoop); | ||
|
||
// This line should deserialize properly | ||
var result = sut.Deserialize<ClassWithSelfReferencingLoop>(json, 1); | ||
|
||
Assert.AreEqual(typeof(ClassWithSelfReferencingLoop), result.GetType()); | ||
Assert.IsNull(result.InfiniteRefernce); | ||
} | ||
|
||
public class ClassWithSelfReferencingLoop | ||
{ | ||
public ClassWithSelfReferencingLoop(ClassWithSelfReferencingLoop ir) | ||
{ | ||
this.InfiniteRefernce = ir; | ||
} | ||
|
||
public ClassWithSelfReferencingLoop InfiniteRefernce | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
} | ||
} |