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

Can i test generics-on-generics static method between another dlls? #30

Open
balmychan opened this issue Mar 30, 2017 · 0 comments
Open

Comments

@balmychan
Copy link

balmychan commented Mar 30, 2017

I want to test like below static method. but Method2 test is failed.

In app.dll

namespace Sample.App
{
	public static class SampleUtil
	{
		public static string Method1(IEnumerable<int> ids)
		{
			return "Method1";
		}
		
		public static string Method2<T>(IEnumerable<T> ids)
		{
			return "Method2";
		}
	}
}

In test.dll

namespace Sample.Test
{
	[TestClass]
	public class SampleUtilTest
	{
		[TestMethod]
		public void SampleUtil_Method1_Method2_Test()
		{
			Smock.Run(context =>
			{
				context.Setup(() => SampleUtil.Method1(
					Smocks.Matching.It.IsAny<IEnumerable<int>>()
				)).Returns("Mock: Method1");
				context.Setup(() => SampleUtil.Method2<int>(
					Smocks.Matching.It.IsAny<IEnumerable<int>>()
				)).Returns("Mock: Method2");
				Assert.AreEqual("Mock: Method1", SampleUtil.Method1(new int[] { 1, 2, 3 })); // This test is passed.
				Assert.AreEqual("Mock: Method2", SampleUtil.Method2(new int[] { 1, 2, 3 })); // This test is failed.		
			});
		}
	}
}

next, I prepared SampleUtil into same dll (in test.dll), Method2 test is passed.

namespace Sample.Test
{
	public static class SampleUtil
	{
		public static string Method1(IEnumerable<int> ids)
		{
			return "Method1";
		}

		public static string Method2<T>(IEnumerable<T> ids)
		{
			return "Method2";
		}
	}

	[TestClass]
	public class SampleUtilTest
	{

		[TestMethod]
		public void SampleUtil_Method1_Method2_Test()
		{
			Smock.Run(context =>
			{
				context.Setup(() => SampleUtil.Method1(
					Smocks.Matching.It.IsAny<IEnumerable<int>>()
				)).Returns("Mock: Method1");
				context.Setup(() => SampleUtil.Method2<int>(
					Smocks.Matching.It.IsAny<IEnumerable<int>>()
				)).Returns("Mock: Method2");
				Assert.AreEqual("Mock: Method1", SampleUtil.Method1(new int[] { 1, 2, 3 })); // This test is passed.
				Assert.AreEqual("Mock: Method2", SampleUtil.Method2(new int[] { 1, 2, 3 })); // This test is passed.
			});
		}
	}
}

Can i test generics-on-generics static method between another dlls? If you know anything, please tell me. Thank you.

@balmychan balmychan changed the title Can i test generics-on-generics static method between another dlls. Can i test generics-on-generics static method between another dlls? Mar 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant