Skip to content

Commit

Permalink
Merge pull request #31 from gettyimages/update-sdk
Browse files Browse the repository at this point in the history
Update unit tests to .NET 6
  • Loading branch information
mapitman authored Mar 11, 2022
2 parents a1cf186 + ab79448 commit b47c20a
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 28 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core 2.1
- name: Setup .NET Core 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.x
- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: |
dotnet test --configuration Release --no-build --no-restore --verbosity normal -f netcoreapp2.1
dotnet test --configuration Release --no-build --no-restore --verbosity normal -f netcoreapp3.1
run: dotnet test --configuration Release --no-build --no-restore --verbosity normal -f net6
- uses: actions/upload-artifact@v1
with:
name: artifacts
Expand Down
14 changes: 4 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core 2.1
- name: Setup .NET Core 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.x
- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: 'Get Previous tag'
Expand All @@ -29,9 +25,7 @@ jobs:
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: |
dotnet test --configuration Release --no-build --no-restore --verbosity normal -f netcoreapp2.1
dotnet test --configuration Release --no-build --no-restore --verbosity normal -f netcoreapp3.1
run: dotnet test --configuration Release --no-build --no-restore --verbosity normal -f net6
- uses: actions/upload-artifact@v1
with:
name: artifacts
Expand All @@ -44,7 +38,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x' # SDK Version to use.
dotnet-version: '6.0.x' # SDK Version to use.
- uses: actions/download-artifact@v1
with:
name: artifacts
Expand Down
13 changes: 13 additions & 0 deletions .idea/.idea.GettyImages.Api/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.idea.GettyImages.Api/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.GettyImages.Api/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.GettyImages.Api/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.GettyImages.Api/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion GettyImages.Api/SdkException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal SdkException(string message, Exception innerException, HttpStatusCode?

internal static async Task GenerateSdkExceptionAsync(HttpResponseMessage httpResponse, string message = null)
{
if (string.IsNullOrEmpty(message))
if (httpResponse.Content != null && string.IsNullOrEmpty(message))
{
var resultContentAsString = await httpResponse.Content.ReadAsStringAsync();

Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
default: build

build:
dotnet restore --force
dotnet build

test:
dotnet test UnitTests
2 changes: 1 addition & 1 deletion UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net6</TargetFrameworks>

<IsPackable>false</IsPackable>

Expand Down
8 changes: 1 addition & 7 deletions UnitTests/WebHelper/WebHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ public async Task Check500CodeTest()
{
var httpResponse = new HttpResponseMessage();
httpResponse.StatusCode = (HttpStatusCode) 500;

var testHandler = new TestHandler(httpResponse);

var response = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret", testHandler)
.SearchImages().WithPhrase("cat");

var ex = await Assert.ThrowsAsync<NullReferenceException>(async () => await response.ExecuteAsync());

Assert.Equal("Object reference not set to an instance of an object.", ex.Message);

var ex = await Assert.ThrowsAsync<SdkException>(async () => await response.ExecuteAsync());
Assert.True(testHandler.NumberOfCallsSendAsync >= 2);
}
}
Expand Down

0 comments on commit b47c20a

Please sign in to comment.