Admin: DotNet example project (#6110)

This commit is contained in:
Bert Blommers 2023-03-24 09:46:37 -01:00 committed by GitHub
parent 588dd58b37
commit 98b02fc1a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 105 additions and 2 deletions

View File

@ -74,6 +74,10 @@ jobs:
needs: lint needs: lint
uses: ./.github/workflows/tests_sdk_java.yml uses: ./.github/workflows/tests_sdk_java.yml
dotnettest:
needs: lint
uses: ./.github/workflows/tests_sdk_dotnet.yml
test: test:
needs: [lint] needs: [lint]
uses: ./.github/workflows/tests_decoratormode.yml uses: ./.github/workflows/tests_decoratormode.yml
@ -85,7 +89,7 @@ jobs:
release: release:
name: Release name: Release
runs-on: ubuntu-latest 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' }} if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'getmoto/moto' }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

35
.github/workflows/tests_sdk_dotnet.yml vendored Normal file
View File

@ -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/

View File

@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python 3.8
uses: actions/setup-python@v4 uses: actions/setup-python@v4
with: with:
python-version: "3.8" python-version: "3.8"

2
.gitignore vendored
View File

@ -31,3 +31,5 @@ docs/_build
moto_recording moto_recording
.hypothesis .hypothesis
other_langs/tests_java/target other_langs/tests_java/target
other_langs/tests_dotnet/ExampleTestProject/bin
other_langs/tests_dotnet/ExampleTestProject/obj

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
<UserSecretsId>45a910a7-aba2-43ee-ad3c-ccad57f044d9</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="3.7.103.34" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@ -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);
}
}

View File

@ -0,0 +1 @@
global using Xunit;