Skip to content

Commit

Permalink
FastFilter Fix (microsoft#1247)
Browse files Browse the repository at this point in the history
* Adding the conditions for the negative scenario in the AddOperator for FastFilter
  • Loading branch information
singhsarab authored Nov 7, 2017
1 parent 8f83427 commit b85b410
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Microsoft.TestPlatform.Common/Filtering/FastFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Filtering
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
Expand Down Expand Up @@ -41,7 +42,7 @@ internal FastFilter(string filterPropertyName, ImmutableHashSet<string> filterPr
}
else
{
throw new ArgumentException();
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.FastFilterException));
}
}

Expand Down Expand Up @@ -150,6 +151,11 @@ internal void AddOperator(Operator @operator)
{
operatorEncountered = true;
fastFilterOperator = @operator;
if ((fastFilterOperation == Operation.NotEqual && fastFilterOperator == Operator.Or)
|| (fastFilterOperation == Operation.Equal && fastFilterOperator == Operator.And))
{
containsValidFilter = false;
}
}
}
else
Expand Down
11 changes: 11 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
<data name="FailedToFindInstalledUnitTestExtensions" xml:space="preserve">
<value>Failed to find the list of installed unit test extensions. Reason: {0}</value>
</data>
<data name="FastFilterException" xml:space="preserve">
<value>An error occured while creating Fast filter.</value>
</data>
<data name="IgnoredDuplicateConfiguration" xml:space="preserve">
<value>There are multiple configurations that have data collector FriendlyName as '{0}'. Duplicate configurations will be ignored in the test run.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

namespace Microsoft.TestPlatform.Common.UnitTests.Filtering
{
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestPlatform.Common.Filtering;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using System.Collections.Immutable;

[TestClass]
public class FastFilterTests
Expand Down Expand Up @@ -54,6 +56,7 @@ public void AndOperatorAndEqualsOperationShouldNotCreateFastFilter()
var fastFilter = filterExpressionWrapper.fastFilter;

Assert.IsTrue(fastFilter == null);
Assert.IsTrue(string.IsNullOrEmpty(filterExpressionWrapper.ParseError));
}

[TestMethod]
Expand All @@ -63,6 +66,7 @@ public void OrOperatorAndNotEqualsOperationShouldNotCreateFastFilter()
var fastFilter = filterExpressionWrapper.fastFilter;

Assert.IsTrue(fastFilter == null);
Assert.IsTrue(string.IsNullOrEmpty(filterExpressionWrapper.ParseError));
}

[TestMethod]
Expand Down Expand Up @@ -310,5 +314,20 @@ public void FastFilterWithWithRegexParseErrorShouldNotCreateFastFilter()
Assert.AreEqual(null, filterExpressionWrapper.fastFilter);
Assert.IsFalse(string.IsNullOrEmpty(filterExpressionWrapper.ParseError));
}

[TestMethod]
public void FastFilterShouldThrowExceptionForUnsupportedOperatorOperationCombination()
{
ImmutableHashSet<string>.Builder filterHashSetBuilder = ImmutableHashSet.CreateBuilder<string>();
try
{
var filter = new FastFilter("dummyName", filterHashSetBuilder.ToImmutableHashSet(), Operation.Equal, Operator.And);
}
catch (Exception ex)
{
Assert.IsTrue(ex is ArgumentException);
Assert.AreEqual("An error occured while creating Fast filter.", ex.Message);
}
}
}
}

0 comments on commit b85b410

Please sign in to comment.