Skip to content

Commit

Permalink
Merge pull request #146 from ServiceComposer/composition-over-existin…
Browse files Browse the repository at this point in the history
…g-endpoints

Add support for composition over existing Endpoints
  • Loading branch information
mauroservienti committed Jun 25, 2020
2 parents ade00fa + 4785593 commit 1d50a1c
Show file tree
Hide file tree
Showing 27 changed files with 459 additions and 217 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#if NETCOREAPP3_1
using System;
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;

namespace ServiceComposer.AspNetCore.Tests
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
class DelegateAuthenticationSchemeOptions : AuthenticationSchemeOptions
{
public Func<HttpRequest, Task<AuthenticateResult>> OnAuthenticate { get; set; }
}
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
#if NETCOREAPP3_1

using System.Dynamic;
using System.IO;
using System.Net.Http;
using System.Net.Mime;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Delete_with_2_handlers
{
Expand Down Expand Up @@ -83,6 +75,4 @@ public async Task Returns_expected_response()
Assert.Equal(expectedNumber, responseObj?.SelectToken("ANumber")?.Value<int>());
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if NETCOREAPP3_1

using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -9,7 +7,7 @@
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Get_request_and_subscribers_with_different_templates
{
Expand Down Expand Up @@ -94,6 +92,4 @@ public async Task Invokes_only_subscribers_with_the_expected_template()
Assert.False(responseObj.ContainsKey("ThisShouldNeverBeAppended"));
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if NETCOREAPP3_1

using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -9,7 +7,7 @@
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Get_with_1_handler_and_1_subscriber
{
Expand Down Expand Up @@ -78,6 +76,4 @@ public async Task Returns_expected_response()
Assert.Equal("sample", responseObj?.SelectToken("AnotherString")?.Value<string>());
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if NETCOREAPP3_1

using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -10,7 +8,7 @@
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Get_with_2_handlers
{
Expand Down Expand Up @@ -74,6 +72,4 @@ public async Task Returns_expected_response()
Assert.Equal(1, responseObj?.SelectToken("ANumber")?.Value<int>());
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#if NETCOREAPP3_1

using System.Net;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Xunit;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Get_with_configured_authentication
{
Expand Down Expand Up @@ -111,6 +109,4 @@ public async Task When_not_all_handlers_are_restricted_is_Unauthorized()
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#if NETCOREAPP3_1

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Xunit;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Get_with_matching_handler
{
Expand Down Expand Up @@ -50,6 +48,4 @@ public async Task Is_found()
Assert.True(response.IsSuccessStatusCode);
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if NETCOREAPP3_1

using System.Net;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
Expand All @@ -9,7 +7,7 @@
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Get_with_no_matching_handlers
{
Expand Down Expand Up @@ -51,6 +49,4 @@ public async Task Return_404()
Assert.Equal( HttpStatusCode.NotFound, response.StatusCode);
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if NETCOREAPP3_1

using System.Dynamic;
using System.Dynamic;
using System.IO;
using System.Net.Http;
using System.Net.Mime;
Expand All @@ -15,7 +13,7 @@
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Patch_with_2_handlers
{
Expand Down Expand Up @@ -98,6 +96,4 @@ public async Task Returns_expected_response()
Assert.Equal(expectedNumber, responseObj?.SelectToken("ANumber")?.Value<int>());
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if NETCOREAPP3_1

using System.Dynamic;
using System.Dynamic;
using System.IO;
using System.Net.Http;
using System.Net.Mime;
Expand All @@ -15,7 +13,7 @@
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Post_with_2_handlers
{
Expand Down Expand Up @@ -98,6 +96,4 @@ public async Task Returns_expected_response()
Assert.Equal(expectedNumber, responseObj?.SelectToken("ANumber")?.Value<int>());
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if NETCOREAPP3_1

using System.Dynamic;
using System.Dynamic;
using System.IO;
using System.Net.Http;
using System.Net.Mime;
Expand All @@ -15,7 +13,7 @@
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Post_with_2_handlers_1_subscriber
{
Expand Down Expand Up @@ -122,6 +120,4 @@ public async Task Returns_expected_response()
Assert.Equal($"ANumber: {expectedNumber}.", responseObj?.SelectToken("AValue")?.Value<string>());
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if NETCOREAPP3_1

using System.Dynamic;
using System.Dynamic;
using System.IO;
using System.Net.Http;
using System.Net.Mime;
Expand All @@ -15,7 +13,7 @@
using ServiceComposer.AspNetCore.Testing;
using Xunit;

namespace ServiceComposer.AspNetCore.Tests.When_using_endpoints
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
public class Put_with_2_handlers
{
Expand Down Expand Up @@ -98,6 +96,4 @@ public async Task Returns_expected_response()
Assert.Equal(expectedNumber, responseObj?.SelectToken("ANumber")?.Value<int>());
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ServiceComposer.AspNetCore\ServiceComposer.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ApprovalTests" Version="5.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.5" />
<PackageReference Include="FakeItEasy" Version="6.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="PublicApiGenerator" Version="10.1.2" />
<PackageReference Include="ServiceComposer.AspNetCore.Testing" Version="1.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#if NETCOREAPP3_1
using System.Text.Encodings.Web;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace ServiceComposer.AspNetCore.Tests
namespace ServiceComposer.AspNetCore.Endpoints.Tests
{
class TestAuthenticationHandler : AuthenticationHandler<DelegateAuthenticationSchemeOptions>
{
Expand All @@ -24,5 +23,4 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
return Options.OnAuthenticate(Request);
}
}
}
#endif
}

0 comments on commit 1d50a1c

Please sign in to comment.