Skip to content
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 @@ -25,8 +25,22 @@ protected override IEnumerable<IXunitTestCase> CreateTestCasesForTheory(ITestFra
protected override IEnumerable<IXunitTestCase> CreateTestCasesForDataRow(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, object[] dataRow)
{
var skipReason = testMethod.EvaluateSkipConditions();
return skipReason != null
? base.CreateTestCasesForSkippedDataRow(discoveryOptions, testMethod, theoryAttribute, dataRow, skipReason)
if (skipReason == null && dataRow?.Length > 0)
{
var obj = dataRow[0];
if (obj != null)
{
var type = obj.GetType();
var property = type.GetProperty("Skip");
if (property != null && property.PropertyType.Equals(typeof(string)))
{
skipReason = property.GetValue(obj) as string;
}
}
}

return skipReason != null ?
base.CreateTestCasesForSkippedDataRow(discoveryOptions, testMethod, theoryAttribute, dataRow, skipReason)
: base.CreateTestCasesForDataRow(discoveryOptions, testMethod, theoryAttribute, dataRow);
}
}
Expand Down
37 changes: 37 additions & 0 deletions test/Microsoft.AspNetCore.Testing.Tests/ConditionalTheoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.AspNetCore.Testing
{
Expand Down Expand Up @@ -115,5 +116,41 @@ public void Dispose()
Assert.True(TestRan, "If this assertion fails, a conditional theory wasn't discovered.");
}
}

[ConditionalTheory]
[MemberData(nameof(SkippableData))]
public void WithSkipableData(Skippable skippable)
{
Assert.Null(skippable.Skip);
Assert.Equal(1, skippable.Data);
}

public static TheoryData<Skippable> SkippableData => new TheoryData<Skippable>
{
new Skippable() { Data = 1 },
new Skippable() { Data = 2, Skip = "This row should be skipped." }
};

public class Skippable : IXunitSerializable
{
public Skippable() { }
public int Data { get; set; }
public string Skip { get; set; }

public void Serialize(IXunitSerializationInfo info)
{
info.AddValue(nameof(Data), Data, typeof(int));
}

public void Deserialize(IXunitSerializationInfo info)
{
Data = info.GetValue<int>(nameof(Data));
}

public override string ToString()
{
return Data.ToString();
}
}
}
}