public void Test_ArgumentNull() { var classBuilder = new ClassBuilder("NullTest", "MyTest"); var @class = classBuilder .WithUsings("System", "NUnit.Framework") .WithModifiers(Modifiers.Public) .WithMethods( new MethodBuilder("SetUp") .WithAttributes(new Attribute("SetUp")) .WithModifiers(Modifiers.Public) .Build(), new MethodBuilder("Test_WhenAddingNumber_ShouldBeCorrectSum") .WithAttributes(new Attribute("Test")) .WithModifiers(Modifiers.Public) .WithBody( BodyGenerator.Create( Statement.Declaration.Declare("myList", typeof(List <int>)), NunitAssertGenerator.Throws(new VariableReference("myList", new MethodReference("First")), typeof(ArgumentNullException)))) .Build()) .Build(); Assert.AreEqual(@"usingSystem;usingNUnit.Framework;namespaceMyTest{publicclassNullTest{[SetUp]publicvoidSetUp(){}[Test]publicvoidTest_WhenAddingNumber_ShouldBeCorrectSum(){List<int>myList;Assert.Throws<ArgumentNullException>(()=>myList.First(),"""");}}}", @class.ToString()); }
public void Throws_WhenCallingWithAReferencethatIsNotMethod_ShouldShowError() { Assert.Throws <ArgumentException>(() => NunitAssertGenerator.Throws(new VariableReference("test"), typeof(ArgumentException), "test").ToString()); }
public void Throws_WhenCallingWithMessage_ShouldGenerateCode() { Assert.AreEqual("Assert.Throws<ArgumentNullException>(()=>MyMethod(),\"Message\");", NunitAssertGenerator.Throws(new MethodReference("MyMethod"), typeof(ArgumentNullException), "Message").ToString()); }
public void Contains_WhenCallingWithMessage_ShouldGenerateCode() { Assert.AreEqual("Assert.IsTrue(\"test\".Contains(\"t\"),\"Message\");", NunitAssertGenerator.Contains(new ValueArgument("t"), new ValueArgument("test"), "Message").ToString()); }
public void AreNotSame_WhenCallingWithMessage_ShouldGenerateCode() { Assert.AreEqual("Assert.AreNotSame(true,false,\"Message\");", NunitAssertGenerator.AreNotSame(new ValueArgument(true), new ValueArgument(false), "Message").ToString()); }