Skip to content

Commit

Permalink
Temporary removed documentation link (as it's outdated) and added ano…
Browse files Browse the repository at this point in the history
…ther example (#82)
  • Loading branch information
MilleBo authored Jan 15, 2022
1 parent b44527f commit 4b87963
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<int>)),
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<int> myList;
Assert.Throws<ArgumentNullException>(() => 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.
Expand Down
2 changes: 1 addition & 1 deletion src/Testura.Code.Tests/Integration/NunitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public void Test_ArgumentNull()
.Build();
Assert.AreEqual(@"usingSystem;usingNUnit.Framework;namespaceMyTest{publicclassNullTest{[SetUp]publicvoidSetUp(){}[Test]publicvoidTest_WhenAddingNumber_ShouldBeCorrectSum(){List<int>myList;Assert.Throws<ArgumentNullException>(()=>myList.First(),"""");}}}", @class.ToString());
}
}
}

0 comments on commit 4b87963

Please sign in to comment.