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

Make default testcase filter property name FullyQualifiedName #555

Merged
merged 5 commits into from
Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 27 additions & 3 deletions src/Microsoft.TestPlatform.Common/Filtering/Condition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ internal class Condition
/// </summary>
private static string propertyNameValueSeperatorString = @"(\!\=)|(\=)|(\~)|(\!)";

/// <summary>
/// Default property name which will be used when filter has only property value.
/// </summary>
public const string DefaultPropertyName = "FullyQualifiedName";

/// <summary>
/// Default operation which will be used when filter has only property value.
/// </summary>
public const Operation DefaultOperation = Operation.Contains;

/// <summary>
/// Name of the property used in condition.
Expand Down Expand Up @@ -156,17 +165,28 @@ internal bool Evaluate(Func<string, Object> propertyValueProvider)
/// </summary>
internal static Condition Parse(string conditionString)
{
if (string.IsNullOrWhiteSpace(conditionString))
{
ThrownFormatExceptionForInvalidCondition(conditionString);
}
string[] parts = Regex.Split(conditionString, propertyNameValueSeperatorString);
if (parts.Length == 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there an unit test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test is added in ConditionTests.cs.

{
// If only parameter values is passed, create condition with default property name,
// default operation and given condition string as parameter value.
return new Condition(Condition.DefaultPropertyName, Condition.DefaultOperation, conditionString.Trim());
}

if (parts.Length != 3)
{
throw new FormatException(string.Format(CultureInfo.CurrentCulture, CommonResources.TestCaseFilterFormatException, string.Format(CultureInfo.CurrentCulture, CommonResources.InvalidCondition, conditionString)));
ThrownFormatExceptionForInvalidCondition(conditionString);
}

for (int index = 0; index < 3; index++)
{
if (string.IsNullOrWhiteSpace(parts[index]))
{
throw new FormatException(string.Format(CultureInfo.CurrentCulture, CommonResources.TestCaseFilterFormatException, string.Format(CultureInfo.CurrentCulture, CommonResources.InvalidCondition, conditionString)));
ThrownFormatExceptionForInvalidCondition(conditionString);
}
parts[index] = parts[index].Trim();
}
Expand All @@ -176,7 +196,11 @@ internal static Condition Parse(string conditionString)
return condition;
}


private static void ThrownFormatExceptionForInvalidCondition(string conditionString)
{
throw new FormatException(string.Format(CultureInfo.CurrentCulture, CommonResources.TestCaseFilterFormatException,
string.Format(CultureInfo.CurrentCulture, CommonResources.InvalidCondition, conditionString)));
}


/// <summary>
Expand Down
21 changes: 21 additions & 0 deletions test/Microsoft.TestPlatform.AcceptanceTests/TestCaseFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,26 @@ public void RunSelectedTestsWithPriorityTrait(string runnerFramework, string tar
this.InvokeVsTest(arguments);
this.ValidateSummaryStatus(1, 0, 0);
}

/// <summary>
/// In case TestCaseFilter is provide without any property like Name or ClassName. ex. /TestCaseFilter:"UnitTest1"
/// this command should provide same results as /TestCaseFilter:"FullyQualifiedName~UnitTest1".
/// </summary>
[CustomDataTestMethod]
[NET46TargetFramework]
[NETCORETargetFramework]
public void TestCaseFilterShouldWork_IfOnlyPropertyValueGivenInExpression(string runnerFramework, string targetFramework, string targetRuntime)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: please remove underscore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Looks repetitive. Move to constructor/Test Init?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are using data row here, can't call from .ctor/Setup.


var arguments = PrepareArguments(
this.GetSampleTestAssembly(),
this.GetTestAdapterPath(),
string.Empty,
this.FrameworkArgValue);
arguments = string.Concat(arguments, " /TestCaseFilter:UnitTest1");
this.InvokeVsTest(arguments);
this.ValidateSummaryStatus(1, 1, 1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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.Common.UnitTests.Filtering
{
using System;
using Microsoft.VisualStudio.TestPlatform.Common.Filtering;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class ConditionTests
{
[TestMethod]
public void ParseShouldThrownFormatException_OnNullConditionString()
{
string conditionString = null;
Assert.ThrowsException<FormatException>(() => Condition.Parse(conditionString));
}

[TestMethod]
public void ParseShouldThrownFormatException_OnEmptyConditionString()
{
var conditionString = "";
Assert.ThrowsException<FormatException>(() => Condition.Parse(conditionString));
}

[TestMethod]
public void ParseShouldThrownFormatException_OnIncompleteConditionString()
{
var conditionString = "PropertyName=";
Assert.ThrowsException<FormatException>( ()=> Condition.Parse(conditionString));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍


[TestMethod]
public void ParseShouldCreateDefaultCondition_WhenOnlyPropertyValuePassed()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: no underscores.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

{
var conditionString = "ABC";
Condition condition = Condition.Parse(conditionString);
Assert.AreEqual(Condition.DefaultPropertyName, condition.Name);
Assert.AreEqual(Operation.Contains, condition.Operation);
Assert.AreEqual(conditionString, condition.Value);
}

[TestMethod]
public void ParseShouldCreateProperCondition_OnValidConditionString()
{
var conditionString = "PropertyName=PropertyValue";
Condition condition = Condition.Parse(conditionString);
Assert.AreEqual("PropertyName", condition.Name);
Assert.AreEqual(Operation.Equal, condition.Operation);
Assert.AreEqual("PropertyValue", condition.Value);
}
}
}