Skip to content

Instantly share code, notes, and snippets.

@margusmartsepp
Created November 12, 2015 14:40
Show Gist options
  • Select an option

  • Save margusmartsepp/bf64cd645fe80e017765 to your computer and use it in GitHub Desktop.

Select an option

Save margusmartsepp/bf64cd645fe80e017765 to your computer and use it in GitHub Desktop.
fluent nunit tests
[TestFixture]
public class RepresentativeServiceTests
{
public class TestStory
{
public class Fail
{
public static IEnumerable Constructor
{
get
{
IUserContext userContext = null;
INavServiceClient navServiceClient = null;
yield return new TestCaseData(userContext, navServiceClient).Throws(typeof(ArgumentNullException)).SetName("Context is null");
userContext = Mock.Of<IUserContext>();
yield return new TestCaseData(userContext, navServiceClient).Throws(typeof(ArgumentNullException)).SetName("Service is null");
navServiceClient = Mock.Of<INavServiceClient>();
yield return new TestCaseData(userContext, navServiceClient).Throws(typeof(ArgumentNullException)).SetName("Context.CustomerNumber is null");
Mock.Get(userContext).Setup(o => o.CustomerNumber).Returns((string)null);
yield return new TestCaseData(userContext, navServiceClient).Throws(typeof(ArgumentNullException)).SetName("Context.CustomerNumber has value (string)null");
Mock.Get(userContext).Setup(o => o.CustomerNumber).Returns(string.Empty);
yield return new TestCaseData(userContext, navServiceClient).Throws(typeof(ArgumentNullException)).SetName("Context.CustomerNumber has value string.Empty");
Mock.Get(userContext).Setup(o => o.CustomerNumber).Returns("000007");
yield return new TestCaseData(userContext, navServiceClient).Throws(typeof(ArgumentNullException)).SetName("Context.PersonalCode is null");
Mock.Get(userContext).Setup(o => o.PersonalCode).Returns((string)null);
yield return new TestCaseData(userContext, navServiceClient).Throws(typeof(ArgumentNullException)).SetName("Context.PersonalCode has value (string)null");
Mock.Get(userContext).Setup(o => o.PersonalCode).Returns(string.Empty);
yield return new TestCaseData(userContext, navServiceClient).Throws(typeof(ArgumentNullException)).SetName("Context.PersonalCode has value string.Empty");
}
}
}
public class Pass
{
public static IEnumerable Constructor
{
get
{
var userContext = Mock.Of<IUserContext>();
var navServiceClient = Mock.Of<INavServiceClient>();
Mock.Get(userContext).Setup(o => o.CustomerNumber).Returns("000007");
Mock.Get(userContext).Setup(o => o.PersonalCode).Returns("38703070123");
yield return new TestCaseData(userContext, navServiceClient).SetName("Representative service created");
}
}
}
}
[Test, TestCaseSource(typeof(TestStory.Fail), nameof(TestStory.Fail.Constructor))]
public void RepresentativeServiceFailTests(IUserContext userContext, INavServiceClient navServiceClient)
{
new RepresentativeService(userContext, navServiceClient);
}
[Test, TestCaseSource(typeof(TestStory.Pass), nameof(TestStory.Pass.Constructor))]
public void RepresentativeServicePassTests(IUserContext userContext, INavServiceClient navServiceClient)
{
new RepresentativeService(userContext, navServiceClient);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment