Skip to content

Commit

Permalink
♻️ migrate to TUnit (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Odonno authored Jan 29, 2025
1 parent fb79ab1 commit e46a677
Show file tree
Hide file tree
Showing 152 changed files with 1,330 additions and 2,672 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.27.3",
"version": "0.30.6",
"commands": [
"dotnet-csharpier"
]
Expand Down
43 changes: 35 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ on:
paths-ignore:
- '**.md'
jobs:
build-remote:
runs-on: ubuntu-4cores
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup dotnet 9.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.0.x"

- name: Install .NET tools
run: dotnet tool restore

- name: Check Formatting
run: dotnet csharpier --check .

- name: Install dependencies
run: dotnet restore

- name: Disable embedded mode
run: sudo bash disable_embedded_mode.sh

- name: Build
run: dotnet build --no-restore

build:
needs: [embedded-build]
runs-on: ubuntu-4cores
Expand All @@ -34,7 +60,9 @@ jobs:
run: dotnet tool restore

- name: Check Formatting
run: dotnet csharpier --check .
run: |
export PATH
dotnet csharpier --check .
- name: Install dependencies
run: dotnet restore
Expand Down Expand Up @@ -86,27 +114,26 @@ jobs:
./SurrealDb.Net.Tests/SurrealDb.Net.Tests.csproj
--no-restore
--no-build
--collect "XPlat Code Coverage"
--results-directory .coverage
--
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
--coverage
--coverage-output-format cobertura
- name: Test Live Query feature
run: >
dotnet test
./SurrealDb.Net.LiveQuery.Tests/SurrealDb.Net.LiveQuery.Tests.csproj
--no-restore
--no-build
--collect "XPlat Code Coverage"
--results-directory .coverage
--
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
--coverage
--coverage-output-format cobertura
- name: Upload Coverage
if: matrix.surrealdb_version == 'v2.1.2'
uses: codecov/codecov-action@v5
with:
directory: .coverage
fail_ci_if_error: true
files: "**/*.cobertura.xml"

embedded-build:
runs-on: ubuntu-4cores
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@
<None Include="..\LICENSE" Pack="true" PackagePath="\" Visible="false" />
<None Include="..\img\icon.png" Pack="true" PackagePath="\" Visible="false" />
</ItemGroup>

<!-- Used to enable build & tests for embedded modes (memory, rocksdb, surrealkv) -->
<PropertyGroup Label="Constants" Condition="true">
<DefineConstants>EMBEDDED_MODE</DefineConstants>
</PropertyGroup>

</Project>
9 changes: 4 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
<PackageVersion Include="ConcurrentHashSet" Version="1.3.0" />
<PackageVersion Include="coverlet.collector" Version="3.1.2" />
<PackageVersion Include="csbindgen" Version="1.9.1" />
<PackageVersion Include="CSharpier.MsBuild" Version="0.27.3" />
<PackageVersion Include="CSharpier.MsBuild" Version="0.30.6" />
<PackageVersion Include="Dahomey.Cbor" Version="1.24.3" />
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.1.1" />
<PackageVersion Include="FlakyTest.XUnit" Version="2.4.10" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
Expand All @@ -22,6 +21,7 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Microsoft.Reactive.Testing" Version="6.0.1" />
<PackageVersion Include="Microsoft.Spatial" Version="7.18.0" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.13.1" />
<PackageVersion Include="MudBlazor" Version="6.11.2" />
<PackageVersion Include="Pidgin" Version="3.2.3" />
<PackageVersion Include="Scalar.AspNetCore" Version="1.2.36" />
Expand All @@ -32,10 +32,9 @@
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Interactive.Async" Version="6.0.1" />
<PackageVersion Include="SystemTextJsonPatch" Version="4.0.0" />
<PackageVersion Include="TUnit" Version="0.6.154" />
<PackageVersion Include="Ulid" Version="1.3.3" />
<PackageVersion Include="Verify.Xunit" Version="28.2.1" />
<PackageVersion Include="Verify.TUnit" Version="28.9.0" />
<PackageVersion Include="Websocket.Client" Version="5.1.1" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
</Project>
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,26 @@ public class WeatherForecastController : ControllerBase
Before contributing to this repository, please take note of the [Contributing](./CONTRIBUTING.md) guidelines. To contribute to this project, you will also need to install the following tools:

* The .NET SDK, preferably the latest stable version which is available for [download here](https://dotnet.microsoft.com/download)
* The [Rust programming language](https://www.rust-lang.org/learn/get-started)
* The [Rust programming language](https://www.rust-lang.org/learn/get-started), in order to build the embedded providers

The test and benchmark projects are highly dependent on the local Rust crate used by embedded providers. This crate is located in the [./rust-embedded](./rust-embedded) folder of this repository. To build the crate, make sure you installed the Rust toolchain on your machine and then follow these steps:
#### Embedded mode

The test and benchmark projects are dependent on the local Rust crate used by embedded providers. This crate is located in the [./rust-embedded](./rust-embedded) folder of this repository. To build the crate, make sure you installed the Rust toolchain on your machine and then follow these steps:

```sh
cd ./rust-embedded
cargo build
```

If the command line was successful, the compiled libraries are generated in the target folder and automatically copied when the .NET projects are built.
If the command line was successful, the compiled libraries are generated in the target folder and automatically copied when the .NET projects are built.

Note: you can manually disable the embedded mode by changing the value of the constant `EMBEDDED_MODE` located in the `Directory.Build.props` file like this:

```xml
<PropertyGroup Label="Constants" Condition="false">
<DefineConstants>EMBEDDED_MODE</DefineConstants>
</PropertyGroup>
```

### .NET release versions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</PropertyGroup>

<!-- https://stackoverflow.com/a/48714896/7847252 -->
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ItemGroup Condition="$(DefineConstants.Contains('EMBEDDED_MODE')) And '$(Configuration)' == 'Debug'">
<Content Include="../rust-embedded/target/debug/surreal_memory.dll" TargetPath="surreal_memory.dll" CopyToOutputDirectory="Always" Condition="'$(OS)' == 'Windows_NT'" />
<Content Include="../rust-embedded/target/debug/surreal_memory.pdb" TargetPath="surreal_memory.pdb" CopyToOutputDirectory="Always" Condition="'$(OS)' == 'Windows_NT'" />

Expand All @@ -66,7 +66,7 @@
<Content Include="../rust-embedded/target/release/libsurreal_memory.dylib" TargetPath="libsurreal_memory.dylib" CopyToOutputDirectory="Always" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))'" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Release' And !$(DefineConstants.Contains('BENCHMARK_MODE'))">
<ItemGroup Condition="$(DefineConstants.Contains('EMBEDDED_MODE')) And '$(Configuration)' == 'Release' And !$(DefineConstants.Contains('BENCHMARK_MODE'))">
<Content Include="../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_memory.dll" Condition="Exists('../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_memory.dll')" Pack="true" PackagePath="runtimes/win-x64/native/" />
<Content Include="../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_memory.pdb" Condition="Exists('../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_memory.pdb')" Pack="true" PackagePath="runtimes/win-x64/native/" />

Expand Down
12 changes: 6 additions & 6 deletions SurrealDb.Embedded.Internals/SurrealDbEmbeddedEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task Connect(CancellationToken cancellationToken)
handle = new RustGCHandle()
{
ptr = GCHandle.ToIntPtr(successHandle),
drop_callback = &NativeBindings.DropGcHandle
drop_callback = &NativeBindings.DropGcHandle,
},
callback = &NativeBindings.SuccessCallback,
};
Expand All @@ -104,7 +104,7 @@ public async Task Connect(CancellationToken cancellationToken)
handle = new RustGCHandle()
{
ptr = GCHandle.ToIntPtr(failureHandle),
drop_callback = &NativeBindings.DropGcHandle
drop_callback = &NativeBindings.DropGcHandle,
},
callback = &NativeBindings.FailureCallback,
};
Expand Down Expand Up @@ -287,7 +287,7 @@ await CborSerializer
handle = new RustGCHandle()
{
ptr = GCHandle.ToIntPtr(successHandle),
drop_callback = &NativeBindings.DropGcHandle
drop_callback = &NativeBindings.DropGcHandle,
},
callback = &NativeBindings.SuccessCallback,
};
Expand All @@ -297,7 +297,7 @@ await CborSerializer
handle = new RustGCHandle()
{
ptr = GCHandle.ToIntPtr(failureHandle),
drop_callback = &NativeBindings.DropGcHandle
drop_callback = &NativeBindings.DropGcHandle,
},
callback = &NativeBindings.FailureCallback,
};
Expand Down Expand Up @@ -968,7 +968,7 @@ await CborSerializer
handle = new RustGCHandle()
{
ptr = GCHandle.ToIntPtr(successHandle),
drop_callback = &NativeBindings.DropGcHandle
drop_callback = &NativeBindings.DropGcHandle,
},
callback = &NativeBindings.SuccessCallback,
};
Expand All @@ -978,7 +978,7 @@ await CborSerializer
handle = new RustGCHandle()
{
ptr = GCHandle.ToIntPtr(failureHandle),
drop_callback = &NativeBindings.DropGcHandle
drop_callback = &NativeBindings.DropGcHandle,
},
callback = &NativeBindings.FailureCallback,
};
Expand Down
4 changes: 2 additions & 2 deletions SurrealDb.Embedded.RocksDb/SurrealDb.Embedded.RocksDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</PropertyGroup>

<!-- https://stackoverflow.com/a/48714896/7847252 -->
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ItemGroup Condition="$(DefineConstants.Contains('EMBEDDED_MODE')) And '$(Configuration)' == 'Debug'">
<Content Include="../rust-embedded/target/debug/surreal_rocksdb.dll" TargetPath="surreal_rocksdb.dll" CopyToOutputDirectory="Always" Condition="'$(OS)' == 'Windows_NT'" />
<Content Include="../rust-embedded/target/debug/surreal_rocksdb.pdb" TargetPath="surreal_rocksdb.pdb" CopyToOutputDirectory="Always" Condition="'$(OS)' == 'Windows_NT'" />

Expand All @@ -66,7 +66,7 @@
<Content Include="../rust-embedded/target/release/libsurreal_rocksdb.dylib" TargetPath="libsurreal_rocksdb.dylib" CopyToOutputDirectory="Always" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))'" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Release' And !$(DefineConstants.Contains('BENCHMARK_MODE'))">
<ItemGroup Condition="$(DefineConstants.Contains('EMBEDDED_MODE')) And '$(Configuration)' == 'Release' And !$(DefineConstants.Contains('BENCHMARK_MODE'))">
<Content Include="../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_rocksdb.dll" Condition="Exists('../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_rocksdb.dll')" Pack="true" PackagePath="runtimes/win-x64/native/" />
<Content Include="../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_rocksdb.pdb" Condition="Exists('../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_rocksdb.pdb')" Pack="true" PackagePath="runtimes/win-x64/native/" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</PropertyGroup>

<!-- https://stackoverflow.com/a/48714896/7847252 -->
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ItemGroup Condition="$(DefineConstants.Contains('EMBEDDED_MODE')) And '$(Configuration)' == 'Debug'">
<Content Include="../rust-embedded/target/debug/surreal_surrealkv.dll" TargetPath="surreal_surrealkv.dll" CopyToOutputDirectory="Always" Condition="'$(OS)' == 'Windows_NT'" />
<Content Include="../rust-embedded/target/debug/surreal_surrealkv.pdb" TargetPath="surreal_surrealkv.pdb" CopyToOutputDirectory="Always" Condition="'$(OS)' == 'Windows_NT'" />

Expand All @@ -66,7 +66,7 @@
<Content Include="../rust-embedded/target/release/libsurreal_surrealkv.dylib" TargetPath="libsurreal_surrealkv.dylib" CopyToOutputDirectory="Always" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))'" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Release' And !$(DefineConstants.Contains('BENCHMARK_MODE'))">
<ItemGroup Condition="$(DefineConstants.Contains('EMBEDDED_MODE')) And '$(Configuration)' == 'Release' And !$(DefineConstants.Contains('BENCHMARK_MODE'))">
<Content Include="../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_surrealkv.dll" Condition="Exists('../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_surrealkv.dll')" Pack="true" PackagePath="runtimes/win-x64/native/" />
<Content Include="../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_surrealkv.pdb" Condition="Exists('../rust-embedded/target/x86_64-pc-windows-msvc/release/surreal_surrealkv.pdb')" Pack="true" PackagePath="runtimes/win-x64/native/" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class WeatherForecastFaker : Faker<WeatherForecast>
"Balmy",
"Hot",
"Sweltering",
"Scorching"
"Scorching",
};

public WeatherForecastFaker()
Expand Down
12 changes: 6 additions & 6 deletions SurrealDb.Examples.Blazor.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async Task InitializeDbAsync()
var tasks = new[]
{
GenerateWeatherForecastsAsync(surrealDbClient),
GenerateKanbanAsync(surrealDbClient)
GenerateKanbanAsync(surrealDbClient),
};

await Task.WhenAll(tasks);
Expand Down Expand Up @@ -92,13 +92,13 @@ async Task GenerateKanbanAsync(ISurrealDbClient surrealDbClient)
var task3 = new TaskRecord
{
Title = "Update the project plan",
DueDate = DateTime.Now.AddDays(3)
DueDate = DateTime.Now.AddDays(3),
};
var task4 = new TaskRecord { Title = "Finish the proposal", DueDate = DateTime.Now.AddDays(2) };
var task5 = new TaskRecord
{
Title = "Complete the presentation",
DueDate = DateTime.Now.AddDays(5)
DueDate = DateTime.Now.AddDays(5),
};

var taskTasks = new[] { task1, task2, task3, task4, task5 }.Select(t =>
Expand All @@ -111,19 +111,19 @@ async Task GenerateKanbanAsync(ISurrealDbClient surrealDbClient)
{
Name = "To Do",
Order = 1,
Tasks = new[] { taskRecords[0].Id!, taskRecords[1].Id! }
Tasks = new[] { taskRecords[0].Id!, taskRecords[1].Id! },
};
var inProgressColumn = new ColumnRecord
{
Name = "In Progress",
Order = 2,
Tasks = new[] { taskRecords[2].Id!, taskRecords[3].Id! }
Tasks = new[] { taskRecords[2].Id!, taskRecords[3].Id! },
};
var doneColumn = new ColumnRecord
{
Name = "Done",
Order = 3,
Tasks = new[] { taskRecords[4].Id! }
Tasks = new[] { taskRecords[4].Id! },
};

var columnTasks = new[] { todoColumn, inProgressColumn, doneColumn }.Select(column =>
Expand Down
4 changes: 2 additions & 2 deletions SurrealDb.Examples.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
Title = "Founder & CEO",
Name = new() { FirstName = "Tobie", LastName = "Morgan Hitchcock" },
Marketing = true
Marketing = true,
};
var created = await db.Create(TABLE, person);
Console.WriteLine(ToJsonString(created));
Expand All @@ -35,7 +35,7 @@

static string ToJsonString(object? o)
{
return JsonSerializer.Serialize(o, new JsonSerializerOptions { WriteIndented = true, });
return JsonSerializer.Serialize(o, new JsonSerializerOptions { WriteIndented = true });
}

public class Person : Record
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WeatherForecastFaker : Faker<WeatherForecast>
"Balmy",
"Hot",
"Sweltering",
"Scorching"
"Scorching",
};

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion SurrealDb.Examples.MinimalApis/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{
options.ConfigObject.Urls =
[
new UrlDescriptor { Name = "MinimalApis Examples API v1", Url = "/openapi/v1.json" }
new UrlDescriptor { Name = "MinimalApis Examples API v1", Url = "/openapi/v1.json" },
];
});
app.MapScalarApiReference();
Expand Down
2 changes: 1 addition & 1 deletion SurrealDb.Examples.TodoApi.Aot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async Task InitializeDbAsync()
new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)),
new(3, "Do the laundry", DateOnly.FromDateTime(DateTime.Now.AddDays(1))),
new(4, "Clean the bathroom"),
new(5, "Clean the car", DateOnly.FromDateTime(DateTime.Now.AddDays(2)))
new(5, "Clean the car", DateOnly.FromDateTime(DateTime.Now.AddDays(2))),
};

var surrealDbClient = new SurrealDbClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CancellationToken cancellationToken
Date = data.Date,
Country = data.Country,
TemperatureC = data.TemperatureC,
Summary = data.Summary
Summary = data.Summary,
};

return _surrealDbClient.Create(Table, weatherForecast, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WeatherForecastFaker : Faker<WeatherForecast>
"Balmy",
"Hot",
"Sweltering",
"Scorching"
"Scorching",
};

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Execute(GeneratorExecutionContext context)
{
"SurrealDb.MinimalApis.Extensions.SurrealDbMinimalApisOptions.cs",
"SurrealDbMinimalApisOptions.g.cs"
}
},
};

var assembly = Assembly.GetExecutingAssembly();
Expand Down
Loading

0 comments on commit e46a677

Please sign in to comment.