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

Fix serialization issue with TestRunSettings #3317

Merged
merged 1 commit into from
Feb 2, 2022
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 @@ -12,7 +12,6 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel;
/// </summary>
public abstract class TestRunSettings
{

#region Constructor

/// <summary>
Expand All @@ -37,7 +36,7 @@ protected TestRunSettings(string name)
/// during RunSettings.LoadSection() call
/// TODO: Communicate to Chutzpah and fix it
/// </summary>
public string Name { get; private set; }
public string Name { get; }

#endregion

Expand All @@ -46,6 +45,7 @@ protected TestRunSettings(string name)
/// Converter the setting to be an XmlElement.
/// </summary>
/// <returns>The Xml element for the run settings provided.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1059:MembersShouldNotExposeCertainConcreteTypes", Justification = "XmlElement is required in the data collector.")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's unrelated but I noticed this was removed during the reformatting and should not have been.

public abstract XmlElement ToXml();
#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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.ObjectModel.UnitTests;

using System.IO;
using System.Xml;
using System.Xml.Serialization;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class RunSettingsTests
{
[TestMethod]
public void RunSettingsNameSerialization()
{
var chilRunSettings = new ChildRunSettings();
var xml = chilRunSettings.ToXml();
Assert.IsNotNull(xml);
}

public class ChildRunSettings : TestRunSettings
{
public ChildRunSettings() : base("SomeName")
{
}

public override XmlElement ToXml()
{
var document = new XmlDocument();
using (XmlWriter writer = document.CreateNavigator().AppendChild())
{
new XmlSerializer(typeof(ChildRunSettings)).Serialize(writer, this);
}
return document.DocumentElement;
}
}
}