diff options
Diffstat (limited to 'test')
35 files changed, 615 insertions, 214 deletions
diff --git a/test/dotnet/dotnet_env.sh b/test/dotnet/dotnet_env.sh new file mode 100644 index 0000000..37b14ea --- /dev/null +++ b/test/dotnet/dotnet_env.sh @@ -0,0 +1,4 @@ +#!/bin/bash +export DOTNET_NOLOGO=true +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true +export DOTNET_GENERATE_ASPNET_CERTIFICATE=false
\ No newline at end of file diff --git a/test/dotnet/dotnet_helpers.sh b/test/dotnet/dotnet_helpers.sh new file mode 100644 index 0000000..6c833b4 --- /dev/null +++ b/test/dotnet/dotnet_helpers.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# Prints the latest dotnet version in the specified channel +# Usage: fetch_latest_version_in_channel <channel> [<runtime>] +# Example: fetch_latest_version_in_channel "LTS" +# Example: fetch_latest_version_in_channel "6.0" "dotnet" +# Example: fetch_latest_version_in_channel "6.0" "aspnetcore" +fetch_latest_version_in_channel() { + local channel="$1" + local runtime="$2" + if [ "$runtime" = "dotnet" ]; then + wget -qO- "https://dotnetcli.azureedge.net/dotnet/Runtime/$channel/latest.version" + elif [ "$runtime" = "aspnetcore" ]; then + wget -qO- "https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$channel/latest.version" + else + wget -qO- "https://dotnetcli.azureedge.net/dotnet/Sdk/$channel/latest.version" + fi + +} + +# Prints the latest dotnet version +# Usage: fetch_latest_version [<runtime>] +# Example: fetch_latest_version +# Example: fetch_latest_version "dotnet" +# Example: fetch_latest_version "aspnetcore" +fetch_latest_version() { + local runtime="$1" + local sts_version + local lts_version + sts_version=$(fetch_latest_version_in_channel "STS" "$runtime") + lts_version=$(fetch_latest_version_in_channel "LTS" "$runtime") + if [[ "$sts_version" > "$lts_version" ]]; then + echo "$sts_version" + else + echo "$lts_version" + fi +} + +# Asserts that the specified .NET SDK version is installed +# Returns a non-zero exit code if the check fails +# Usage: is_dotnet_sdk_version_installed <version> +# Example: is_dotnet_sdk_version_installed "6.0" +# Example: is_dotnet_sdk_version_installed "6.0.412" +is_dotnet_sdk_version_installed() { + local expected="$1" + dotnet --list-sdks | grep --fixed-strings --silent "$expected" + return $? +} + + +# Asserts that the specified .NET Runtime version is installed +# Returns a non-zero exit code if the check fails +# Usage: is_dotnet_runtime_version_installed <version> +# Example: is_dotnet_runtime_version_installed "6.0" +# Example: is_dotnet_runtime_version_installed "6.0.412" +is_dotnet_runtime_version_installed() { + local expected="$1" + dotnet --list-runtimes | grep --fixed-strings --silent "Microsoft.NETCore.App $expected" + return $? +} + +# Asserts that the specified ASP.NET Core Runtime version is installed +# Returns a non-zero exit code if the check fails +# Usage: is_aspnetcore_runtime_version_installed <version> +# Example: is_aspnetcore_runtime_version_installed "6.0" +# Example: is_aspnetcore_runtime_version_installed "6.0.412" +is_aspnetcore_runtime_version_installed() { + local expected="$1" + dotnet --list-runtimes | grep --fixed-strings --silent "Microsoft.AspNetCore.App $expected" + return $? +}
\ No newline at end of file diff --git a/test/dotnet/install_additional_dotnet.sh b/test/dotnet/install_additional_dotnet.sh deleted file mode 100644 index e69c7dc..0000000 --- a/test/dotnet/install_additional_dotnet.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -check "dotnet version 6.0.301 installed as default" bash -c "dotnet --version | grep 6.0.301" -check "dotnet version 5.0 installed" bash -c "ls -l /usr/local/dotnet | grep 5.0" -check "dotnet version 3.1.420 installed" bash -c "ls -l /usr/local/dotnet | grep 3.1.420" - -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk - -# Report result -reportResults diff --git a/test/dotnet/install_aspnetcore_runtime_only.sh b/test/dotnet/install_aspnetcore_runtime_only.sh new file mode 100644 index 0000000..35bd540 --- /dev/null +++ b/test/dotnet/install_aspnetcore_runtime_only.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check <LABEL> <cmd> [args...] +source dotnet_env.sh +source dotnet_helpers.sh + +expected=$(fetch_latest_version "aspnetcore") + +check "Latest ASP.NET Core Runtime version installed" \ +is_aspnetcore_runtime_version_installed "$expected" + +# Expect this check to fail in November 2023 when .NET 8.0 becomes GA +check "It is a flavor of .NET 7.0" \ +is_aspnetcore_runtime_version_installed "7.0" + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults
\ No newline at end of file diff --git a/test/dotnet/install_dotnet_3.sh b/test/dotnet/install_dotnet_3.sh deleted file mode 100644 index 51d871b..0000000 --- a/test/dotnet/install_dotnet_3.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -check "dotnet sdks" dotnet --list-sdks -check "some major version of dotnet 3 is installed" bash -c "dotnet --list-sdks | grep '3\.[0-9]*\.[0-9]*'" -check "dotnet version 3 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep '3\.[0-9]*\.[0-9]*'" - -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk - -# Report result -reportResults diff --git a/test/dotnet/install_dotnet_6_bullseye.sh b/test/dotnet/install_dotnet_6_bullseye.sh deleted file mode 100644 index 758f040..0000000 --- a/test/dotnet/install_dotnet_6_bullseye.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -check "dotnet sdks" dotnet --list-sdks -check "some major version of dotnet 6 is installed" bash -c "dotnet --list-sdks | grep '6\.[0-9]*\.[0-9]*'" -check "dotnet version 6 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep '6\.[0-9]*\.[0-9]*'" - -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk - -# Report result -reportResults diff --git a/test/dotnet/install_dotnet_6_focal.sh b/test/dotnet/install_dotnet_6_focal.sh deleted file mode 100644 index 758f040..0000000 --- a/test/dotnet/install_dotnet_6_focal.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -check "dotnet sdks" dotnet --list-sdks -check "some major version of dotnet 6 is installed" bash -c "dotnet --list-sdks | grep '6\.[0-9]*\.[0-9]*'" -check "dotnet version 6 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep '6\.[0-9]*\.[0-9]*'" - -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk - -# Report result -reportResults diff --git a/test/dotnet/install_dotnet_6_jammy.sh b/test/dotnet/install_dotnet_6_jammy.sh deleted file mode 100644 index fd10634..0000000 --- a/test/dotnet/install_dotnet_6_jammy.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -check "dotnet sdks" dotnet --list-sdks -check "some major version of dotnet 6 is installed" bash -c "dotnet --list-sdks | grep '6\.[0-9]*\.[0-9]*'" -check "dotnet version 6 installed" bash -c "ls -l /usr/lib/dotnet/sdk | grep '6\.[0-9]*\.[0-9]*'" - -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk - -# Report result -reportResults diff --git a/test/dotnet/install_dotnet_7_bullseye.sh b/test/dotnet/install_dotnet_7_bullseye.sh deleted file mode 100644 index 2c015fc..0000000 --- a/test/dotnet/install_dotnet_7_bullseye.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -check "dotnet sdks" dotnet --list-sdks -check "some major version of dotnet 7 is installed" bash -c "dotnet --list-sdks | grep '7\.[0-9]*\.[0-9]*'" -check "dotnet version 7 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep '7\.[0-9]*\.[0-9]*'" - -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk - -# Report result -reportResults diff --git a/test/dotnet/install_dotnet_7_jammy.sh b/test/dotnet/install_dotnet_7_jammy.sh deleted file mode 100644 index 1392168..0000000 --- a/test/dotnet/install_dotnet_7_jammy.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -check "dotnet sdks" dotnet --list-sdks -check "some major version of dotnet 7 is installed" bash -c "dotnet --list-sdks | grep '7\.[0-9]*\.[0-9]*'" -check "dotnet version 7 installed" bash -c "ls -l /usr/lib/dotnet/sdk | grep '7\.[0-9]*\.[0-9]*'" - -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk - -# Report result -reportResults diff --git a/test/dotnet/install_dotnet_exact_version.sh b/test/dotnet/install_dotnet_exact_version.sh new file mode 100644 index 0000000..ec89f3b --- /dev/null +++ b/test/dotnet/install_dotnet_exact_version.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check <LABEL> <cmd> [args...] +source dotnet_env.sh +source dotnet_helpers.sh + +check ".NET SDK 8.0.100-preview.6.23330.14 installed" \ +is_dotnet_sdk_version_installed "8.0.100-preview.6.23330.14" + +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
\ No newline at end of file diff --git a/test/dotnet/install_dotnet_global_tool.sh b/test/dotnet/install_dotnet_global_tool.sh new file mode 100644 index 0000000..948b650 --- /dev/null +++ b/test/dotnet/install_dotnet_global_tool.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check <LABEL> <cmd> [args...] +source dotnet_env.sh +source dotnet_helpers.sh + +# From https://learn.microsoft.com/en-us/dotnet/core/tools/global-tools +check "Install a .NET global tool" \ +dotnet tool install --global dotnetsay + +check "Run the tool" \ +dotnetsay "$(dotnet --info)" + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults
\ No newline at end of file diff --git a/test/dotnet/install_dotnet_latest.sh b/test/dotnet/install_dotnet_latest.sh deleted file mode 100644 index 1392168..0000000 --- a/test/dotnet/install_dotnet_latest.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -check "dotnet sdks" dotnet --list-sdks -check "some major version of dotnet 7 is installed" bash -c "dotnet --list-sdks | grep '7\.[0-9]*\.[0-9]*'" -check "dotnet version 7 installed" bash -c "ls -l /usr/lib/dotnet/sdk | grep '7\.[0-9]*\.[0-9]*'" - -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk - -# Report result -reportResults diff --git a/test/dotnet/install_dotnet_latest_when_version_is_empty.sh b/test/dotnet/install_dotnet_latest_when_version_is_empty.sh new file mode 100644 index 0000000..7418892 --- /dev/null +++ b/test/dotnet/install_dotnet_latest_when_version_is_empty.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check <LABEL> <cmd> [args...] +source dotnet_env.sh +source dotnet_helpers.sh + +expected=$(fetch_latest_version) + +check "Latest .NET SDK version installed" \ +is_dotnet_sdk_version_installed "$expected" + +# Expect this check to fail in November 2023 when .NET 8.0 becomes GA +check "It is a flavor of .NET 7.0" \ +is_dotnet_sdk_version_installed "7.0" + +check "Build and run example project" \ +dotnet run --project projects/net7.0 + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults
\ No newline at end of file diff --git a/test/dotnet/install_dotnet_lts.sh b/test/dotnet/install_dotnet_lts.sh index 758f040..fe37b89 100644 --- a/test/dotnet/install_dotnet_lts.sh +++ b/test/dotnet/install_dotnet_lts.sh @@ -2,16 +2,25 @@ set -e -# Optional: Import test library +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. source dev-container-features-test-lib -check "dotnet sdks" dotnet --list-sdks -check "some major version of dotnet 6 is installed" bash -c "dotnet --list-sdks | grep '6\.[0-9]*\.[0-9]*'" -check "dotnet version 6 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep '6\.[0-9]*\.[0-9]*'" +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check <LABEL> <cmd> [args...] +source dotnet_env.sh +source dotnet_helpers.sh -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk +expected=$(fetch_latest_version_in_channel "LTS") -# Report result -reportResults +check "Latest LTS version installed" \ +is_dotnet_sdk_version_installed "$expected" + +check "Build and run example project" \ +dotnet run --project projects/net6.0 + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults
\ No newline at end of file diff --git a/test/dotnet/install_dotnet_multiple_versions.sh b/test/dotnet/install_dotnet_multiple_versions.sh new file mode 100644 index 0000000..5f0f125 --- /dev/null +++ b/test/dotnet/install_dotnet_multiple_versions.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check <LABEL> <cmd> [args...] +source dotnet_env.sh +source dotnet_helpers.sh + +check ".NET SDK 8.0 installed" \ +is_dotnet_sdk_version_installed "8.0" + +check ".NET SDK 7.0 installed" \ +is_dotnet_sdk_version_installed "7.0" + +check ".NET SDK 6.0 installed" \ +is_dotnet_sdk_version_installed "6.0" + +check "Build example class library" \ +dotnet build projects/multitargeting + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults
\ No newline at end of file diff --git a/test/dotnet/install_dotnet_runtime_only.sh b/test/dotnet/install_dotnet_runtime_only.sh new file mode 100644 index 0000000..65188c5 --- /dev/null +++ b/test/dotnet/install_dotnet_runtime_only.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check <LABEL> <cmd> [args...] +source dotnet_env.sh +source dotnet_helpers.sh + +expected=$(fetch_latest_version "dotnet") + +check "Latest .NET Runtime version installed" \ +is_dotnet_runtime_version_installed "$expected" + +# Expect this check to fail in November 2023 when .NET 8.0 becomes GA +check "It is a flavor of .NET 7.0" \ +is_dotnet_runtime_version_installed "7.0" + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults
\ No newline at end of file diff --git a/test/dotnet/install_dotnet_specific_release.sh b/test/dotnet/install_dotnet_specific_release.sh new file mode 100644 index 0000000..207e582 --- /dev/null +++ b/test/dotnet/install_dotnet_specific_release.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check <LABEL> <cmd> [args...] +source dotnet_env.sh +source dotnet_helpers.sh + +expected=$(fetch_latest_version_in_channel "3.1") + +check ".NET Core SDK 3.1 installed" \ +is_dotnet_sdk_version_installed "$expected" + +check "Build and run example 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
\ No newline at end of file diff --git a/test/dotnet/install_dotnet_specific_release_and_feature_band.sh b/test/dotnet/install_dotnet_specific_release_and_feature_band.sh new file mode 100644 index 0000000..51f5c58 --- /dev/null +++ b/test/dotnet/install_dotnet_specific_release_and_feature_band.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check <LABEL> <cmd> [args...] +source dotnet_env.sh +source dotnet_helpers.sh + +check ".NET SDK 5.0.3xx installed" \ +is_dotnet_sdk_version_installed "5.0.3" + +check "Build and run example project" \ +dotnet run --project projects/net5.0 + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults
\ No newline at end of file diff --git a/test/dotnet/install_wo_apt.sh b/test/dotnet/install_wo_apt.sh deleted file mode 100644 index a1745c5..0000000 --- a/test/dotnet/install_wo_apt.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -check "dotnet sdks" dotnet --list-sdks -check "some major version of dotnet 7 is installed" bash -c "dotnet --list-sdks | grep '7\.[0-9]*\.[0-9]*'" -check "dotnet version 7 installed" bash -c "ls -l /usr/local/dotnet | grep '7\.[0-9]*\.[0-9]*'" - -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk - -# Report result -reportResults diff --git a/test/dotnet/projects/.gitignore b/test/dotnet/projects/.gitignore new file mode 100644 index 0000000..8d4a6c0 --- /dev/null +++ b/test/dotnet/projects/.gitignore @@ -0,0 +1,2 @@ +bin +obj
\ No newline at end of file diff --git a/test/dotnet/projects/multitargeting/Class1.cs b/test/dotnet/projects/multitargeting/Class1.cs new file mode 100644 index 0000000..453b6a4 --- /dev/null +++ b/test/dotnet/projects/multitargeting/Class1.cs @@ -0,0 +1,4 @@ +public class Class1 +{ + +} diff --git a/test/dotnet/projects/multitargeting/example_classlib.csproj b/test/dotnet/projects/multitargeting/example_classlib.csproj new file mode 100644 index 0000000..ba47b0f --- /dev/null +++ b/test/dotnet/projects/multitargeting/example_classlib.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/test/dotnet/projects/net5.0/Program.cs b/test/dotnet/projects/net5.0/Program.cs new file mode 100644 index 0000000..3f3144f --- /dev/null +++ b/test/dotnet/projects/net5.0/Program.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +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 +{ + public string Name { get; set; } = "Default Name"; + public DateTime ReleaseDate { get; set; } + public List<string> Genres { get; set; } = new List<string>(); +} diff --git a/test/dotnet/projects/net5.0/example_project.csproj b/test/dotnet/projects/net5.0/example_project.csproj new file mode 100644 index 0000000..63450c3 --- /dev/null +++ b/test/dotnet/projects/net5.0/example_project.csproj @@ -0,0 +1,13 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net5.0</TargetFramework> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> + </ItemGroup> + +</Project>
\ No newline at end of file diff --git a/test/dotnet/projects/net6.0/Program.cs b/test/dotnet/projects/net6.0/Program.cs new file mode 100644 index 0000000..6d73112 --- /dev/null +++ b/test/dotnet/projects/net6.0/Program.cs @@ -0,0 +1,30 @@ +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 +{ + public string Name { get; set; } = "Default Name"; + public DateTime ReleaseDate { get; set; } + public List<string> Genres { get; set; } = new List<string>(); +} diff --git a/test/dotnet/projects/net6.0/example_project.csproj b/test/dotnet/projects/net6.0/example_project.csproj new file mode 100644 index 0000000..aa2434c --- /dev/null +++ b/test/dotnet/projects/net6.0/example_project.csproj @@ -0,0 +1,14 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> + </ItemGroup> + +</Project>
\ No newline at end of file diff --git a/test/dotnet/projects/net7.0/Program.cs b/test/dotnet/projects/net7.0/Program.cs new file mode 100644 index 0000000..6d73112 --- /dev/null +++ b/test/dotnet/projects/net7.0/Program.cs @@ -0,0 +1,30 @@ +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 +{ + public string Name { get; set; } = "Default Name"; + public DateTime ReleaseDate { get; set; } + public List<string> Genres { get; set; } = new List<string>(); +} diff --git a/test/dotnet/projects/net7.0/example_project.csproj b/test/dotnet/projects/net7.0/example_project.csproj new file mode 100644 index 0000000..424f54a --- /dev/null +++ b/test/dotnet/projects/net7.0/example_project.csproj @@ -0,0 +1,14 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net7.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> + </ItemGroup> + +</Project>
\ No newline at end of file diff --git a/test/dotnet/projects/net8.0/Program.cs b/test/dotnet/projects/net8.0/Program.cs new file mode 100644 index 0000000..690a54e --- /dev/null +++ b/test/dotnet/projects/net8.0/Program.cs @@ -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 +{ + public string Name { get; set; } = "Default Name"; + public DateTime ReleaseDate { get; set; } + public List<string> Genres { get; set; } = new List<string>(); +} diff --git a/test/dotnet/projects/net8.0/example_project.csproj b/test/dotnet/projects/net8.0/example_project.csproj new file mode 100644 index 0000000..2f1f608 --- /dev/null +++ b/test/dotnet/projects/net8.0/example_project.csproj @@ -0,0 +1,14 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> + </ItemGroup> + +</Project>
\ No newline at end of file diff --git a/test/dotnet/projects/netcoreapp3.1/Program.cs b/test/dotnet/projects/netcoreapp3.1/Program.cs new file mode 100644 index 0000000..3e088a9 --- /dev/null +++ b/test/dotnet/projects/netcoreapp3.1/Program.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +class Program +{ + public static void Main() + { + 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 +{ + public string Name { get; set; } = "Default Name"; + public DateTime ReleaseDate { get; set; } + public List<string> Genres { get; set; } = new List<string>(); +} diff --git a/test/dotnet/projects/netcoreapp3.1/example_project.csproj b/test/dotnet/projects/netcoreapp3.1/example_project.csproj new file mode 100644 index 0000000..e2e909c --- /dev/null +++ b/test/dotnet/projects/netcoreapp3.1/example_project.csproj @@ -0,0 +1,14 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> + </ItemGroup> + +</Project>
\ No newline at end of file diff --git a/test/dotnet/scenarios.json b/test/dotnet/scenarios.json index afee26f..f07aaa5 100644 --- a/test/dotnet/scenarios.json +++ b/test/dotnet/scenarios.json @@ -1,83 +1,84 @@ { - "install_additional_dotnet": { - "image": "ubuntu:focal", + "install_dotnet_lts": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "remoteUser": "vscode", "features": { "dotnet": { - "version": "6.0.301", - "additionalVersions": "5.0,3.1.420" + "version": "lts" } } }, - "install_dotnet_3": { - "image": "ubuntu:focal", + "install_dotnet_specific_release": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04", + "remoteUser": "vscode", "features": { "dotnet": { - "version": "3" + "version": "3.1" } } }, - "install_dotnet_6_bullseye": { - "image": "debian:bullseye", + "install_dotnet_specific_release_and_feature_band": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04", + "remoteUser": "vscode", "features": { "dotnet": { - "version": "6" + "version": "5.0.3xx" } } }, - "install_dotnet_6_focal": { - "image": "ubuntu:focal", + "install_dotnet_exact_version": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "remoteUser": "vscode", "features": { "dotnet": { - "version": "6" + "version": "8.0.100-preview.6.23330.14" } } }, - "install_dotnet_7_bullseye": { - "image": "debian:bullseye", + "install_dotnet_multiple_versions": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "remoteUser": "vscode", "features": { "dotnet": { - "version": "7" + "version": "8.0.100-preview.6.23330.14", + "additionalVersions": [ + "7.0", + "6.0" + ] } } }, - "install_dotnet_7_jammy": { - "image": "ubuntu:jammy", + "install_dotnet_global_tool": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "remoteUser": "vscode", "features": { - "dotnet": { - "version": "7" - } + "dotnet": {} } }, - "install_dotnet_6_jammy": { - "image": "mcr.microsoft.com/devcontainers/base:jammy", + "install_dotnet_latest_when_version_is_empty": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "remoteUser": "vscode", "features": { - "dotnet": { - "version": "6" - } + "dotnet": "" } }, - "install_dotnet_latest": { - "image": "ubuntu:jammy", + "install_dotnet_runtime_only": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "remoteUser": "vscode", "features": { "dotnet": { - "version": "latest" - } - } - }, - "install_dotnet_lts": { - "image": "ubuntu:focal", - "features": { - "dotnet": { - "version": "lts" + "version": "none", + "dotnetRuntimeVersions": "latest" } } }, - "install_wo_apt": { - "image": "ubuntu:jammy", + "install_aspnetcore_runtime_only": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "remoteUser": "vscode", "features": { "dotnet": { - "version": "7", - "installUsingApt": false + "version": "none", + "aspnetcoreRuntimeVersions": "latest" } } } diff --git a/test/dotnet/test.sh b/test/dotnet/test.sh index f433654..7418892 100755..100644 --- a/test/dotnet/test.sh +++ b/test/dotnet/test.sh @@ -2,20 +2,29 @@ set -e -# Optional: Import test library +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. source dev-container-features-test-lib -# Definition specific tests -check "dotnet" dotnet --info -check "sdks" dotnet --list-sdks -check "version" dotnet --version +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check <LABEL> <cmd> [args...] +source dotnet_env.sh +source dotnet_helpers.sh -echo "Validating expected version present..." -check "some major version of dotnet (7/8) is installed" bash -c "dotnet --version | grep '[7-8]\.[0-9]*\.[0-9]*'" +expected=$(fetch_latest_version) -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk +check "Latest .NET SDK version installed" \ +is_dotnet_sdk_version_installed "$expected" -# Report result +# Expect this check to fail in November 2023 when .NET 8.0 becomes GA +check "It is a flavor of .NET 7.0" \ +is_dotnet_sdk_version_installed "7.0" + +check "Build and run example project" \ +dotnet run --project projects/net7.0 + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. reportResults
\ No newline at end of file |