Hi,
I have a problem with the following test code.
It is a single test class, which depends on some testcases.
It builds fine, and runs fine. Except for test case nr. 2, which should fail.
The problems in NCrunch are the following:
* if I remove the Serializable attribute(s), NCrunch complains and stops building. It should not, because VS2019 (and resharper test runner) runs fine without it. I named the class NonSerializableStuff just to indicate it should not really have the serializable attribute. (same for the testcase for that matter, but I seemd not to go through thr trouble naming that the same ;) )
* when NCrunch runs with the serializable attribute, it does not complain, but sees only one test case. It does not find or run the second test case.
Could you please look into this ?
Thanks,
Dirk
Code:
using System;
using Xunit;
using Xunit.Abstractions;
namespace Testing
{
public class NCrunchTestcaseTests
{
[Theory]
[ClassData(typeof(NcrunchTestCases))]
public void Test(NCrunchTestCase testCase)
{
Assert.Equal(3, testCase.Id);
}
}
internal class NcrunchTestCases : TheoryData<NCrunchTestCase>
{
/// <inheritdoc />
public NcrunchTestCases()
{
Add(new NCrunchTestCase(){Id = 3, Stuff = new NonSerializableStuff(){AnotherId = 5}});
Add(new NCrunchTestCase(){Id = 4});
}
}
[Serializable]
public class NCrunchTestCase : IXunitSerializable
{
public int Id { get; set; }
public NonSerializableStuff Stuff { get; set; }
#region Implementation of IXunitSerializable
/// <inheritdoc />
public void Deserialize(IXunitSerializationInfo info)
{
Id = info.GetValue<int>(nameof(Id));
Stuff = info.GetValue<NonSerializableStuff>(nameof(Stuff));
}
/// <inheritdoc />
public void Serialize(IXunitSerializationInfo info)
{
info.AddValue(nameof(Id), Id);
info.AddValue(nameof(Stuff), Stuff);
}
#endregion
}
[Serializable]
public class NonSerializableStuff : IXunitSerializable
{
public int AnotherId { get; set; }
#region Implementation of IXunitSerializable
/// <inheritdoc />
public void Deserialize(IXunitSerializationInfo info)
{
AnotherId = info.GetValue<int>(nameof(AnotherId));
}
/// <inheritdoc />
public void Serialize(IXunitSerializationInfo info)
{
info.AddValue(nameof(AnotherId), AnotherId);
}
#endregion
}
}