Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 61 additions & 5 deletions docs/docs/examples/filebased-csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ To use TUnit with a file-based C# application, you can follow these steps:
#:package TUnit@0.*
```

Alternatively, you can specify a specific version:
- Alternatively, you can specify a specific version:

```csharp
#:package [email protected]
```
```csharp
#:package [email protected]
```

- You can also use msbuild props files to include TUnit. By creating a `Directory.build.props` file in the same directory as the csharp file.

```xml
<Project>
<ItemGroup>
<PackageReference Include="TUnit" Version="*" />
</ItemGroup>
</Project>
```

3. **Write your tests**: You can write your tests in the same way you would in a regular C# project. For example:

Expand Down Expand Up @@ -47,7 +57,7 @@ To use TUnit with a file-based C# application, you can follow these steps:

```

4. **Run your tests**: You can run your tests by executing the script using `dotnet run`. The results will be printed to the console.
4. **Run your tests**: You can run your tests by executing the script using `dotnet run`. The results will be printed to the console.
To run the script, you can use the following command

```powershell
Expand All @@ -59,3 +69,49 @@ If you need to convert the file based application to a regular C# project, you c
```powershell
dotnet project convert Program.cs
```

## Using msbuild props with File-Based C# Application

Single file csharp applications can also be used with msbuild props files. You can create a `*.props` file and the dotnet sdk will automatically include it when running the file-based application.

1. Create a file named `Directory.build.props` with the following content:

```xml
<Project>
<ItemGroup>
<PackageReference Include="TUnit" Version="*" />
</ItemGroup>
</Project>
```

2. Create a csharp file with the following content:

```csharp
using TUnit;
public class Tests
{
[Test]
public void Basic()
{
Console.WriteLine("This is a basic test");
}

[Test]
[Arguments(1, 2, 3)]
[Arguments(2, 3, 5)]
public async Task DataDrivenArguments(int a, int b, int c)
{
Console.WriteLine("This one can accept arguments from an attribute");
var result = a + b;
await Assert.That(result).IsEqualTo(c);
}
}
```

3. Run the script using the following command:

```powershell
dotnet run file.cs
```

This will automatically include the `Directory.build.props` file as long as it is in the same directory as the csharp file, and you will be able to run your tests with TUnit.