Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

BUG: DynamicData does not work properly for Interfaces
TKrueger
#1 Posted : Monday, February 4, 2019 11:52:32 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/4/2019(UTC)
Posts: 9
Location: Germany

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)
Code:

public interface ISomeImplementation
{
	bool DoSomething();
}

public class SomeImplementation : ISomeImplementation
{
	public bool DoSomething()
	{
		return true;
	}
}

[TestClass, TestCategory("NCrunch.DynamicData")]
public class ImplementationVsInterfaceDynamicDataTest
{
	/*
	 * This test failed no matter which analyser setting I set for MSTest. But with different error messages:
	 * 
	 * StaticAnalysis: Type mismatch on test parameter 1 (NCrunchTest.ISomeImplementation != NCrunchTest.SomeImplementation)
	 * DynamicAnalysis: System.Exception: Type 'NCrunchTest.SomeImplementation' is not marked as serializable.  Resolution path = NCrunchTest.SomeImplementation
	 *
	 */

	public static IEnumerable<object[]> DoSomethingTestData
	{
		get
		{
			yield return new object[] { new SomeImplementation(), true, "Doubled input" };
		}
	}

	[DataTestMethod]
	[DynamicData(nameof(DoSomethingTestData), DynamicDataSourceType.Property)]
	public void DoSomethingTest(ISomeImplementation implementation, bool expected, string description)
	{
		implementation.DoSomething().Should().BeTrue();
	}
}
Remco
#2 Posted : Monday, March 4, 2019 10:17:50 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,692

Thanks: 738 times
Was thanked: 944 time(s) in 899 post(s)
1 user thanked Remco for this useful post.
TKrueger on 3/6/2019(UTC)
TKrueger
#3 Posted : Wednesday, March 6, 2019 8:09:27 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/4/2019(UTC)
Posts: 9
Location: Germany

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)
Hello,

I tried the new version in my test project and main application. There the test has now been successfully completed.

Thanks
TKrueger
#4 Posted : Wednesday, March 6, 2019 12:14:20 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/4/2019(UTC)
Posts: 9
Location: Germany

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)
Hi,

I have tried to resolve my left issues in my main application and could not fix the following scenario as extension of the reported issue:

Code:

public static IEnumerable<object[]> DoSomethingTestData
{
	get
	{
		yield return new object[] { null, true, "Doubled input" };
	}
}

[DataTestMethod]
[DynamicData(nameof(DoSomethingTestData), DynamicDataSourceType.Property)]
public void DoSomethingTest(ISomeImplementation implementation, bool expected, string description)
{
	// No action required
}


Now I get the following result:
Quote:

--------- DoSomethingTest ((null), True, Doubled input)
Type mismatch on test parameter 1 (parameter should not be null)


It seems to happen if null should be passed to an interface method parameter.

Thanks for your support.
Remco
#5 Posted : Wednesday, March 6, 2019 9:41:52 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,692

Thanks: 738 times
Was thanked: 944 time(s) in 899 post(s)
1 user thanked Remco for this useful post.
TKrueger on 3/7/2019(UTC)
TKrueger
#6 Posted : Thursday, March 7, 2019 7:35:14 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/4/2019(UTC)
Posts: 9
Location: Germany

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)
Good morning,

I tried the new version in my test project and main application. The tests there have now been successfully completed.

Thank you for your fast support.
Remco
#7 Posted : Thursday, March 7, 2019 10:26:24 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,692

Thanks: 738 times
Was thanked: 944 time(s) in 899 post(s)
Great to hear! Thanks for confirming.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.047 seconds.