From 4b87963f49efbf53e49e1a03187c591e3f77e8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mille=20Bostr=C3=B6m?= Date: Sat, 15 Jan 2022 20:06:34 +0100 Subject: [PATCH] Temporary removed documentation link (as it's outdated) and added another example (#82) --- README.md | 48 ++++++++++++++++++- .../Integration/NunitTest.cs | 2 +- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0fadeca..34b3a64 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,6 @@ Testura.Code have three different types of helpers: ## Documentation - Wiki -[https://github.com/Testura/Testura.Code/wiki](https://github.com/Testura/Testura.Code/wiki) -- Api - [https://testura.github.io/Code/api/index.html](https://testura.github.io/Code/api/index.html) ## Examples @@ -323,6 +322,53 @@ namespace Models } ``` +### Test class with method references + +```c# + var @class = new ClassBuilder("NullTest", "MyTest") + .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)), + NunitAssertGenerator.Throws(new VariableReference("myList", new MethodReference("First")), typeof(ArgumentNullException)))) + .Build()) + .Build(); +``` + +This code will generate following code: + +```c# +using System; +using NUnit.Framework; + +namespace MyTest +{ + public class NullTest + { + [SetUp] + public void SetUp() + { + } + + [Test] + public void Test_WhenAddingNumber_ShouldBeCorrectSum() + { + List myList; + Assert.Throws(() => myList.First(), ""); + } + } +} +``` + ## Missing anything? If we miss a feature, syntax or statements - just create an issue or contact us and I'm sure we can add it. diff --git a/src/Testura.Code.Tests/Integration/NunitTest.cs b/src/Testura.Code.Tests/Integration/NunitTest.cs index 89d3285..f00a411 100644 --- a/src/Testura.Code.Tests/Integration/NunitTest.cs +++ b/src/Testura.Code.Tests/Integration/NunitTest.cs @@ -36,4 +36,4 @@ public void Test_ArgumentNull() .Build(); Assert.AreEqual(@"usingSystem;usingNUnit.Framework;namespaceMyTest{publicclassNullTest{[SetUp]publicvoidSetUp(){}[Test]publicvoidTest_WhenAddingNumber_ShouldBeCorrectSum(){ListmyList;Assert.Throws(()=>myList.First(),"""");}}}", @class.ToString()); } -} \ No newline at end of file +}