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

Writes the test properties, CSSProjectStructure, CSSIteration, WorkItemIds and Description to the TRX log #1801

Closed
wants to merge 12 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ internal abstract class TestElement : ITestElement, IXmlTestStore
protected TestId id;
protected string name;
protected string owner;
protected string description;
protected string cssProjectStructure;
protected string cssIteration;
protected string storage;
protected string adapter;
protected int priority;
protected bool isRunnable;
protected TestExecId executionId;
protected TestExecId parentExecutionId;
protected TestCategoryItemCollection testCategories;
protected TestPropertyItemCollection testProperties;
protected TestListCategoryId catId;
protected System.Collections.Generic.IList<string> workItemIds;

public TestElement(Guid id, string name, string adapter)
{
Expand Down Expand Up @@ -81,6 +86,46 @@ public string Owner
}
}

/// <summary>
/// Gets or sets the description.
/// </summary>
public string Description
{
get { return this.description; }

set
{
EqtAssert.ParameterNotNull(value, "Description");
this.description = value;
}
}

/// <summary>
/// Gets or sets the CSS Project Structure.
/// </summary>
public string CssProjectStructure
{
get { return this.cssProjectStructure; }

set
{
this.cssProjectStructure = value;
}
}

/// <summary>
/// Gets or sets the CSS Iteration.
/// </summary>
public string CssIteration
{
get { return this.cssIteration; }

set
{
this.cssIteration = value;
}
}

/// <summary>
/// Gets or sets the priority.
/// </summary>
Expand Down Expand Up @@ -161,6 +206,26 @@ public TestCategoryItemCollection TestCategories
}
}

public TestPropertyItemCollection TestProperties
{
get { return this.testProperties; }
set
{
EqtAssert.ParameterNotNull(value, "TestProperties");
this.testProperties = value;
}
}

public System.Collections.Generic.IList<string> WorkItemIds
{
get { return this.workItemIds; }
set
{
EqtAssert.ParameterNotNull(value, "WorkItemIds");
this.workItemIds = value;
}
}

/// <summary>
/// Gets the adapter name.
/// </summary>
Expand Down Expand Up @@ -222,14 +287,21 @@ public virtual void Save(System.Xml.XmlElement element, XmlTestStoreParameters p
h.SaveSimpleField(element, "@name", this.name, null);
h.SaveSimpleField(element, "@storage", this.storage, string.Empty);
h.SaveSimpleField(element, "@priority", this.priority, DefaultPriority);
if (this.cssProjectStructure != null || this.cssIteration != null)
{
h.SaveSimpleField(element, "Css/@projectStructure", this.cssProjectStructure, string.Empty);
h.SaveSimpleField(element, "Css/@iteration", this.cssIteration, string.Empty);
}
h.SaveSimpleField(element, "Description", this.description, string.Empty);
h.SaveSimpleField(element, "Owners/Owner/@name", this.owner, string.Empty);
h.SaveObject(this.testCategories, element, "TestCategory", parameters);

if (this.executionId != null)
h.SaveGuid(element, "Execution/@id", this.executionId.Id);
if (this.parentExecutionId != null)
h.SaveGuid(element, "Execution/@parentId", this.parentExecutionId.Id);

h.SaveObject(this.testProperties, element, "Properties", parameters);
h.SaveIEnumerable(this.workItemIds, element, "WorkItemIDs", "@id", "WorkItem", parameters);
XmlTestStoreParameters testIdParameters = XmlTestStoreParameters.GetParameters();
testIdParameters[TestId.IdLocationKey] = "@id";
h.SaveObject(this.id, element, testIdParameters);
Expand All @@ -245,6 +317,8 @@ private void Initialize()
this.executionId = TestExecId.Empty;
this.parentExecutionId = TestExecId.Empty;
this.testCategories = new TestCategoryItemCollection();
this.testProperties = new TestPropertyItemCollection();
this.workItemIds = new System.Collections.Generic.List<string>();
this.isRunnable = true;
this.catId = TestListCategoryId.Uncategorized;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
// 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.Extensions.TrxLogger.ObjectModel
{
using System;
using System.Diagnostics;
using System.Text;

using Microsoft.TestPlatform.Extensions.TrxLogger.Utility;
using Microsoft.TestPlatform.Extensions.TrxLogger.XML;

#region TestPropertyItem
/// <summary>
/// Stores a string which categorizes the Test
/// </summary>
internal sealed class TestPropertyItem : IXmlTestStore
{
#region Fields
[StoreXmlSimpleField(Location = "Key", DefaultValue = "")]
private string key = string.Empty;

[StoreXmlSimpleField(Location = "Value", DefaultValue = "")]
private string value = string.Empty;

#endregion

#region Constructors
/// <summary>
/// Create a new item with the key/value set
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public TestPropertyItem(string key, string value)
{
// Treat null as empty.
if (string.IsNullOrEmpty(key))
throw new ArgumentNullException();

if (value == null)
{
value = String.Empty;
}

dotMorten marked this conversation as resolved.
Show resolved Hide resolved
this.key = key;
this.value = value;
}

#endregion

#region Properties/Methods
/// <summary>
/// Gets the Key for this TestProperty
/// </summary>
public string Key
{
get
{
return this.key;
}
}

/// <summary>
/// Gets the Value for this TestProperty
/// </summary>
public string Value
{
get
{
return this.value;
}
}

#endregion

#region Methods - overrides
/// <summary>
/// Compare the values of the items
/// </summary>
/// <param name="other">Value being compared to.</param>
/// <returns>True if the values are the same and false otherwise.</returns>
public override bool Equals(object other)
{
TestPropertyItem otherItem = other as TestPropertyItem;
if (otherItem == null)
{
return false;
}
return String.Equals(this.key, otherItem.key, StringComparison.OrdinalIgnoreCase) && String.Equals(this.value, otherItem.value, StringComparison.Ordinal);
}

/// <summary>
/// Convert the property name to a hashcode
/// </summary>
/// <returns>Hashcode of the category.</returns>
public override int GetHashCode()
{
return this.key.ToUpperInvariant().GetHashCode() ^ this.value.GetHashCode();
}

/// <summary>
/// Convert the property name to a string
/// </summary>
/// <returns>The property.</returns>
public override string ToString()
{
return this.key + " = " + this.value;
}
#endregion

#region IXmlTestStore Members

/// <summary>
/// Saves the class under the XmlElement.
/// </summary>
/// <param name="element"> XmlElement element </param>
/// <param name="parameters"> XmlTestStoreParameters parameters</param>
public void Save(System.Xml.XmlElement element, XmlTestStoreParameters parameters)
{
new XmlPersistence().SaveSingleFields(element, this, parameters);
}

#endregion
}
#endregion

#region TestPropertyItemCollection
/// <summary>
/// A collection of strings which categorize the test.
/// </summary>
internal sealed class TestPropertyItemCollection : EqtBaseCollection<TestPropertyItem>
{
#region Constructors
/// <summary>
/// Creates an empty TestPropertyItemCollection.
/// </summary>
public TestPropertyItemCollection()
{
childElementName = "Property";
}

#endregion

#region Methods

/// <summary>
/// Adds the property.
/// </summary>
/// <param name="key">Key to be added.</param>
/// <param name="value">Value to be added.</param>
public void Add(string key, string value)
{
this.Add(new TestPropertyItem(key, value));
}

/// <summary>
/// Adds the property.
/// </summary>
/// <param name="item">Property to be added.</param>
public override void Add(TestPropertyItem item)
{
EqtAssert.ParameterNotNull(item, "item");

// Don't add empty items.
if (!String.IsNullOrEmpty(item.Key))
{
base.Add(item);
}
}

/// <summary>
/// Convert the TestPropertyItemCollection to a string.
/// each item is surrounded by a comma (,)
/// </summary>
/// <returns></returns>
public override string ToString()
{
StringBuilder returnString = new StringBuilder();
if (this.Count > 0)
{
returnString.Append(",");
foreach (TestPropertyItem item in this)
{
returnString.Append(item.ToString());
returnString.Append(",");
}
}

return returnString.ToString();
}

/// <summary>
/// Compare the collection items
/// </summary>
/// <param name="obj">other collection</param>
/// <returns>true if the collections contain the same items</returns>
public override bool Equals(object obj)
{
TestPropertyItemCollection other = obj as TestPropertyItemCollection;
bool result = false;

if (other == null)
{
// Other object is not a TestPropertyItemCollection.
result = false;
}
else if (Object.ReferenceEquals(this, other))
{
// The other object is the same object as this one.
result = true;
}
else if (this.Count != other.Count)
{
// The count of categories in the other object does not
// match this one, so they are not equal.
result = false;
}
else
{
// Check each item and return on the first mismatch.
foreach (TestPropertyItem item in this)
{
if (!other.Contains(item))
{
result = false;
break;
}
}
}

return result;
}

/// <summary>
/// Return the hash code of this collection
/// </summary>
/// <returns>The hashcode.</returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
#endregion
}
#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void Dispose()
#region Fields
protected Hashtable container;

private string childElementName;
protected string childElementName;
#endregion

#region Constructors
Expand Down
Loading