From 98b02fc1a342f4ede509ec01ab480f2c22f0a7d1 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Fri, 24 Mar 2023 09:46:37 -0100 Subject: [PATCH] Admin: DotNet example project (#6110) --- .github/workflows/build.yml | 6 +++- .github/workflows/tests_sdk_dotnet.yml | 35 +++++++++++++++++++ .github/workflows/tests_sdk_java.yml | 2 +- .gitignore | 2 ++ .../ExampleTestProject.csproj | 26 ++++++++++++++ .../ExampleTestProject/UnitTest.cs | 35 +++++++++++++++++++ .../tests_dotnet/ExampleTestProject/Usings.cs | 1 + 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/tests_sdk_dotnet.yml create mode 100644 other_langs/tests_dotnet/ExampleTestProject/ExampleTestProject.csproj create mode 100644 other_langs/tests_dotnet/ExampleTestProject/UnitTest.cs create mode 100644 other_langs/tests_dotnet/ExampleTestProject/Usings.cs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f1423564..fc9a55f7e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -74,6 +74,10 @@ jobs: needs: lint uses: ./.github/workflows/tests_sdk_java.yml + dotnettest: + needs: lint + uses: ./.github/workflows/tests_sdk_dotnet.yml + test: needs: [lint] uses: ./.github/workflows/tests_decoratormode.yml @@ -85,7 +89,7 @@ jobs: release: name: Release runs-on: ubuntu-latest - needs: [javatest, test, testserver ] + needs: [dotnettest, javatest, test, testserver ] if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'getmoto/moto' }} steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/tests_sdk_dotnet.yml b/.github/workflows/tests_sdk_dotnet.yml new file mode 100644 index 000000000..457ffb9e8 --- /dev/null +++ b/.github/workflows/tests_sdk_dotnet.yml @@ -0,0 +1,35 @@ +name: .NET SDK test +on: [workflow_call] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Python 3.8 + uses: actions/setup-python@v4 + with: + python-version: "3.8" + - name: Start MotoServer + run: | + pip install build + python -m build + docker run --rm -t --name motoserver -e TEST_SERVER_MODE=true -e AWS_SECRET_ACCESS_KEY=server_secret -e AWS_ACCESS_KEY_ID=server_key -v `pwd`:/moto -p 5000:5000 -v /var/run/docker.sock:/var/run/docker.sock python:3.7-buster /moto/scripts/ci_moto_server.sh & + python scripts/ci_wait_for_server.py + - uses: actions/setup-dotnet@v3 + - uses: actions/cache@v3 + with: + path: ~/.nuget/packages + # Look to see if there is a cache hit for the corresponding requirements file + key: ${{ runner.os }}-nuget + restore-keys: | + ${{ runner.os }}-nuget + - name: Install dependencies + run: cd other_langs/tests_dotnet && dotnet restore ExampleTestProject/ + - name: Run tests + run: | + mkdir ~/.aws && touch ~/.aws/credentials && echo -e "[default]\naws_access_key_id = test\naws_secret_access_key = test" > ~/.aws/credentials + cd other_langs/tests_dotnet && dotnet test ExampleTestProject/ diff --git a/.github/workflows/tests_sdk_java.yml b/.github/workflows/tests_sdk_java.yml index da89c9d36..6844c47fe 100644 --- a/.github/workflows/tests_sdk_java.yml +++ b/.github/workflows/tests_sdk_java.yml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python 3.8 uses: actions/setup-python@v4 with: python-version: "3.8" diff --git a/.gitignore b/.gitignore index e6f8b7a22..a631ee86f 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ docs/_build moto_recording .hypothesis other_langs/tests_java/target +other_langs/tests_dotnet/ExampleTestProject/bin +other_langs/tests_dotnet/ExampleTestProject/obj diff --git a/other_langs/tests_dotnet/ExampleTestProject/ExampleTestProject.csproj b/other_langs/tests_dotnet/ExampleTestProject/ExampleTestProject.csproj new file mode 100644 index 000000000..ebda95cc3 --- /dev/null +++ b/other_langs/tests_dotnet/ExampleTestProject/ExampleTestProject.csproj @@ -0,0 +1,26 @@ + + + + net7.0 + enable + enable + + true + true + + 45a910a7-aba2-43ee-ad3c-ccad57f044d9 + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/other_langs/tests_dotnet/ExampleTestProject/UnitTest.cs b/other_langs/tests_dotnet/ExampleTestProject/UnitTest.cs new file mode 100644 index 000000000..84da37008 --- /dev/null +++ b/other_langs/tests_dotnet/ExampleTestProject/UnitTest.cs @@ -0,0 +1,35 @@ +using FluentAssertions; +using System.Net; + +// To interact with Amazon S3. +using Amazon.S3; +using Amazon.S3.Model; + +public class UnitTest1 +{ + + [Fact] + public async Task TestListBuckets() + { + + AmazonS3Config config = new AmazonS3Config() + { + ServiceURL = "http://localhost:5000", + }; + + AmazonS3Client s3Client = new AmazonS3Client(config); + + var initial_list = await s3Client.ListBucketsAsync(); + initial_list.Buckets.Count.Should().Be(0); + + var putBucketRequest = new PutBucketRequest + { + BucketName = "MyFirstBucket", + UseClientRegion = true + }; + await s3Client.PutBucketAsync(putBucketRequest); + + var listResponse = await s3Client.ListBucketsAsync(); + listResponse.Buckets.Count.Should().Be(1); + } +} \ No newline at end of file diff --git a/other_langs/tests_dotnet/ExampleTestProject/Usings.cs b/other_langs/tests_dotnet/ExampleTestProject/Usings.cs new file mode 100644 index 000000000..8c927eb74 --- /dev/null +++ b/other_langs/tests_dotnet/ExampleTestProject/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file