Skip to content

Commit

Permalink
.Net 7 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
savpek authored Jan 9, 2023
1 parent b6b8506 commit 6252dc5
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 69 deletions.
14 changes: 0 additions & 14 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceRoot}/Protacon.NetCore.WebApi.TestUtil.Tests/bin/Debug/netcoreapp3.1/Protacon.NetCore.WebApi.TestUtil.Tests.dll",
"args": [],
"cwd": "${workspaceRoot}/Protacon.NetCore.WebApi.TestUtil.Tests",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
Expand Down
6 changes: 3 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
library "jenkins-ptcs-library@4.0.3"
library "jenkins-ptcs-library@5.0.0"

// pod provides common utilies and tools to jenkins-ptcs-library function correctly.
// certain ptcs-library command requires containers (like docker or gcloud.)
podTemplate(label: pod.label,
containers: pod.templates + [ // This adds all depencies for jenkins-ptcs-library methods to function correctly.
containerTemplate(name: 'dotnet', image: 'mcr.microsoft.com/dotnet/sdk:6.0', ttyEnabled: true, command: '/bin/sh -c', args: 'cat')
containerTemplate(name: 'dotnet', image: 'mcr.microsoft.com/dotnet/sdk:7.0', ttyEnabled: true, command: '/bin/sh -c', args: 'cat')
]
) {
node(pod.label) {
Expand All @@ -21,7 +21,7 @@ podTemplate(label: pod.label,
stage('Test') {
container('dotnet') {
sh """
dotnet test --framework=net6.0 Protacon.NetCore.WebApi.TestUtil.Tests
dotnet test --framework=net7.0 Protacon.NetCore.WebApi.TestUtil.Tests
"""
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NSubstitute" Version="4.4.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 12 additions & 12 deletions Protacon.NetCore.WebApi.TestUtil.Tests/Tests/BasicFlowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ await TestHost.Run<TestStartup>().Get("/returnthree/")
.Passing(
x => x.Should().Be(3));

TestHost.Run<TestStartup>().Get("/returnthree/")
await TestHost.Run<TestStartup>().Get("/returnthree/")
.Awaiting(x => x.ExpectStatusCode(HttpStatusCode.NoContent))
.Should()
.Throw<ExpectedStatusCodeException>();
.ThrowAsync<ExpectedStatusCodeException>();
}

[Fact]
Expand All @@ -33,9 +33,9 @@ public async Task WhenDeleteIsCalled_ThenAssertingItWorks()
await TestHost.Run<TestStartup>().Delete("/something/abc")
.ExpectStatusCode(HttpStatusCode.NoContent);

TestHost.Run<TestStartup>().Delete("/something/abc")
await TestHost.Run<TestStartup>().Delete("/something/abc")
.Awaiting(x => x.ExpectStatusCode(HttpStatusCode.NotFound))
.Should().Throw<ExpectedStatusCodeException>();
.Should().ThrowAsync<ExpectedStatusCodeException>();
}

[Fact]
Expand All @@ -46,9 +46,9 @@ public async Task WhenPutIsCalled_ThenAssertingItWorks()
.WithContentOf<DummyRequest>()
.Passing(x => x.Value.Should().Be("3"));

TestHost.Run<TestStartup>().Put("/returnsame/", new { value = 3 })
await TestHost.Run<TestStartup>().Put("/returnsame/", new { value = 3 })
.Awaiting(x => x.ExpectStatusCode(HttpStatusCode.NotFound))
.Should().Throw<ExpectedStatusCodeException>();
.Should().ThrowAsync<ExpectedStatusCodeException>();
}

[Fact]
Expand All @@ -59,9 +59,9 @@ public async Task WhenPostIsCalled_ThenAssertingItWorks()
.WithContentOf<DummyRequest>()
.Passing(x => x.Value.Should().Be("3"));

TestHost.Run<TestStartup>().Post("/returnsame/", new { value = 3 })
await TestHost.Run<TestStartup>().Post("/returnsame/", new { value = 3 })
.Awaiting(x => x.ExpectStatusCode(HttpStatusCode.NotFound))
.Should().Throw<ExpectedStatusCodeException>();
.Should().ThrowAsync<ExpectedStatusCodeException>();
}

[Fact]
Expand All @@ -74,7 +74,7 @@ public async Task WhenPatchIsCalled_ThenAssertingItWorks()
}

[Fact]
public async Task WhenNonAcceptedCodeIsExpected_ThenAcceptItAsResult()
public async Task WhenNonAcceptedCodeIsExpected_ThenAcceptItAsResult()
{
await TestHost.Run<TestStartup>().Get("/errorcontent/")
.ExpectStatusCode(HttpStatusCode.NotFound)
Expand All @@ -83,11 +83,11 @@ await TestHost.Run<TestStartup>().Get("/errorcontent/")
}

[Fact]
public void WhenExpectedCodeIsNotDefinedOnError_ThenFail()
public async Task WhenExpectedCodeIsNotDefinedOnError_ThenFail()
{
TestHost.Run<TestStartup>().Get("/errorcontent/")
await TestHost.Run<TestStartup>().Get("/errorcontent/")
.Awaiting(x => x.WithContentOf<DummyRequest>())
.Should().Throw<ExpectedStatusCodeException>();
.Should().ThrowAsync<ExpectedStatusCodeException>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ await TestHost.Run<TestStartup>().Get("/headertest/",
headers: new Dictionary<string, string> {{"example", "somevalue"}})
.ExpectStatusCode(HttpStatusCode.NoContent);

TestHost.Run<TestStartup>()
await TestHost.Run<TestStartup>()
.Awaiting(x => x.Get("/headertest/",
headers: new Dictionary<string, string> {{"somethingElse", "somevalue"}})
.ExpectStatusCode(HttpStatusCode.NoContent))
.Should().Throw<InvalidOperationException>();
.Should().ThrowAsync<InvalidOperationException>();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using FluentAssertions;
using Protacon.NetCore.WebApi.TestUtil.Extensions;
using Xunit;
Expand All @@ -8,19 +9,19 @@ namespace Protacon.NetCore.WebApi.TestUtil.Tests
public class WaitForContentTests
{
[Fact]
public void WhenNoValidResponseIsReceived_ThenThrowErrorAfterTimeout()
public async Task WhenNoValidResponseIsReceived_ThenThrowErrorAfterTimeout()
{
TestHost.Run<TestStartup>().Get("/returnthree/")
await TestHost.Run<TestStartup>().Get("/returnthree/")
.Awaiting(x => x.WaitFor<int>(r => r.Should().Be(1), TimeSpan.FromSeconds(2)))
.Should().Throw<Exception>();
.Should().ThrowAsync<Exception>();
}

[Fact]
public void WhenValidResponseIsReceived_ThenReturnWithoutError()
public async Task WhenValidResponseIsReceived_ThenReturnWithoutError()
{
TestHost.Run<TestStartup>().Get("/returnthree/")
await TestHost.Run<TestStartup>().Get("/returnthree/")
.Awaiting(x => x.WaitFor<int>(r => r.Should().Be(3), TimeSpan.FromSeconds(2)))
.Should().NotThrow<Exception>();
.Should().NotThrowAsync<Exception>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ namespace Protacon.NetCore.WebApi.TestUtil.Tests
public class WaitForStatusCodeTests
{
[Fact]
public void WhenErronousCodeIsReturned_ThenThrowErrorAfterTimeout()
public async Task WhenErronousCodeIsReturned_ThenThrowErrorAfterTimeout()
{
TestHost.Run<TestStartup>().Get("/returnthree/")
await TestHost.Run<TestStartup>().Get("/returnthree/")
.Awaiting(x => x.WaitForStatusCode(HttpStatusCode.BadRequest, TimeSpan.FromSeconds(2)))
.Should().Throw<ExpectedStatusCodeException>();
.Should().ThrowAsync<ExpectedStatusCodeException>();
}

[Fact]
public void WhenValidCodeIsReturned_ThenReturnWithoutError()
public async Task WhenValidCodeIsReturned_ThenReturnWithoutError()
{
TestHost.Run<TestStartup>().Get("/returnthree/")
await TestHost.Run<TestStartup>().Get("/returnthree/")
.Awaiting(x => x.WaitForStatusCode(HttpStatusCode.OK, TimeSpan.FromSeconds(2)))
.Should().NotThrow<Exception>();
.Should().NotThrowAsync<Exception>();
}
}
}
13 changes: 7 additions & 6 deletions Protacon.NetCore.WebApi.TestUtil.Tests/Tests/WaitForTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using FluentAssertions;
using Protacon.NetCore.WebApi.TestUtil.Extensions;
using Xunit;
Expand All @@ -8,19 +9,19 @@ namespace Protacon.NetCore.WebApi.TestUtil.Tests
public class WaitForTests
{
[Fact]
public void WhenNoValidResponseIsReceived_ThenThrowErrorAfterTimeout()
public async Task WhenNoValidResponseIsReceived_ThenThrowErrorAfterTimeout()
{
TestHost.Run<TestStartup>().Get("/returnthree/")
await TestHost.Run<TestStartup>().Get("/returnthree/")
.Awaiting(x => x.WaitFor<int>(r => r.Should().Be(1), TimeSpan.FromSeconds(2)))
.Should().Throw<Exception>();
.Should().ThrowAsync<Exception>();
}

[Fact]
public void WhenValidResponseIsReceived_ThenReturnWithoutError()
public async Task WhenValidResponseIsReceived_ThenReturnWithoutError()
{
TestHost.Run<TestStartup>().Get("/returnthree/")
await TestHost.Run<TestStartup>().Get("/returnthree/")
.Awaiting(x => x.WaitFor<int>(r => r.Should().Be(3), TimeSpan.FromSeconds(2)))
.Should().NotThrow<Exception>();
.Should().NotThrowAsync<Exception>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.3" />
<PackageReference Include="System.Text.Json" Version="4.6.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.0" />
</ItemGroup>
</Project>

0 comments on commit 6252dc5

Please sign in to comment.