Skip to content

Commit

Permalink
Improve dotnet tests
Browse files Browse the repository at this point in the history
- add .net9.0 test case
- remove 'build and run' from scenarios with dynamic runtime versions because they fail when the version changes
  • Loading branch information
sliekens committed Jan 7, 2025
1 parent c225a51 commit 0950595
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 19 deletions.
3 changes: 0 additions & 3 deletions test/dotnet/install_dotnet_latest_when_version_is_empty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ expected=$(fetch_latest_version)
check "Latest .NET SDK version installed" \
is_dotnet_sdk_version_installed "$expected"

check "Build and run example project" \
dotnet run --project projects/net8.0

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
3 changes: 0 additions & 3 deletions test/dotnet/install_dotnet_lts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ expected=$(fetch_latest_version_in_channel "LTS")
check "Latest LTS version installed" \
is_dotnet_sdk_version_installed "$expected"

check "Build and run example project" \
dotnet run --project projects/net8.0

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
27 changes: 27 additions & 0 deletions test/dotnet/install_dotnet_multiple_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ source dev-container-features-test-lib
source dotnet_env.sh
source dotnet_helpers.sh

check ".NET SDK 9.0 installed" \
is_dotnet_sdk_version_installed "9.0"

check ".NET SDK 8.0 installed" \
is_dotnet_sdk_version_installed "8.0"

Expand All @@ -22,9 +25,33 @@ is_dotnet_sdk_version_installed "7.0"
check ".NET SDK 6.0 installed" \
is_dotnet_sdk_version_installed "6.0"

check ".NET SDK 5.0 installed" \
is_dotnet_sdk_version_installed "5.0"

check ".NET Core SDK 3.1 installed" \
is_dotnet_sdk_version_installed "3.1"

check "Build example class library" \
dotnet build projects/multitargeting

check "Build and run .NET 9.0 project" \
dotnet run --project projects/net9.0

check "Build and run .NET 8.0 project" \
dotnet run --project projects/net8.0

check "Build and run .NET 7.0 project" \
dotnet run --project projects/net7.0

check "Build and run .NET 6.0 project" \
dotnet run --project projects/net6.0

check "Build and run .NET 5.0 project" \
dotnet run --project projects/net5.0

check "Build and run .NET Core 3.1 project" \
dotnet run --project projects/netcoreapp3.1

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/dotnet/projects/net5.0/example_project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion test/dotnet/projects/net6.0/example_project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion test/dotnet/projects/net7.0/example_project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion test/dotnet/projects/net8.0/example_project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
32 changes: 32 additions & 0 deletions test/dotnet/projects/net9.0/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Newtonsoft.Json;

string json = """
{
"Name": "Inception",
"ReleaseDate": "2010-07-08T00:00:00",
"Genres": [
"Action",
"Thriller"
]
}
""";

Movie? m = JsonConvert.DeserializeObject<Movie>(json);

if (m == default)
{
Console.WriteLine("Decoding failed!");
}
else
{
Console.WriteLine($"Movie name: {m.Name}");
Console.WriteLine($"Release Date: {m.ReleaseDate}");
Console.WriteLine($"Genres: {string.Join(", ", m.Genres)}");
}

class Movie(string? name, DateTime releaseDate, List<string>? genres)
{
public string Name { get; set; } = name ?? "Default Name";
public DateTime ReleaseDate { get; set; } = releaseDate;
public List<string> Genres { get; set; } = genres ?? [];
}
14 changes: 14 additions & 0 deletions test/dotnet/projects/net9.0/example_project.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions test/dotnet/projects/netcoreapp3.1/example_project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
9 changes: 6 additions & 3 deletions test/dotnet/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@
"remoteUser": "vscode",
"features": {
"dotnet": {
"version": "8.0.100-preview.6.23330.14",
"version": "9.0",
"additionalVersions": [
"8.0",
"7.0",
"6.0"
"6.0",
"5.0",
"3.1"
]
}
}
Expand Down Expand Up @@ -92,4 +95,4 @@
}
}
}
}
}
3 changes: 0 additions & 3 deletions test/dotnet/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ expected=$(fetch_latest_version)
check "Latest .NET SDK version installed" \
is_dotnet_sdk_version_installed "$expected"

check "Build and run example project" \
dotnet run --project projects/net8.0

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults

0 comments on commit 0950595

Please sign in to comment.