Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating an endpoint graph from an integration test #303

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BlazorHero.CleanArchitecture.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure.Shared", "sr
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{161B234C-6018-4CE5-86B2-0EA95A53982D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiRoutesTest", "src\Tests\ApiRoutesTest\ApiRoutesTest.csproj", "{3E1BDD60-0FA1-4085-8AEB-614715911373}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -88,6 +90,10 @@ Global
{161B234C-6018-4CE5-86B2-0EA95A53982D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{161B234C-6018-4CE5-86B2-0EA95A53982D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{161B234C-6018-4CE5-86B2-0EA95A53982D}.Release|Any CPU.Build.0 = Release|Any CPU
{3E1BDD60-0FA1-4085-8AEB-614715911373}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E1BDD60-0FA1-4085-8AEB-614715911373}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E1BDD60-0FA1-4085-8AEB-614715911373}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E1BDD60-0FA1-4085-8AEB-614715911373}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -107,6 +113,7 @@ Global
{34B1D3CA-BBB6-449E-82A7-DF2BDBC9838F} = {0317DF35-F5C5-4986-BA37-40C28554268F}
{6B3A1D03-E35E-4579-A24A-E3343D024B4B} = {885BB018-5B07-4038-B061-71B70188933B}
{BFAD2E2A-8C7C-4357-9C81-D2ECDEEFC0F1} = {39A93E2F-51DE-47C0-93AF-A24561630C18}
{3E1BDD60-0FA1-4085-8AEB-614715911373} = {1D491AAE-7A45-4B6B-9E3B-F8F3F0EFDED5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ED3E6669-AEC5-4A3B-9E57-2A81DE87BAAF}
Expand Down
27 changes: 27 additions & 0 deletions src/Tests/ApiRoutesTest/ApiRoutesTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<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>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Server\Server.csproj" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions src/Tests/ApiRoutesTest/GenerateGraphTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using BlazorHero.CleanArchitecture.Server;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Internal;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
using Xunit;
using Xunit.Abstractions;

namespace ApiRoutesTest
{
public class GenerateGraphTest
: IClassFixture<WebApplicationFactory<Startup>>
{
// Inject the factory and the output helper
private readonly WebApplicationFactory<Startup> _factory;
private readonly ITestOutputHelper _output;

public GenerateGraphTest(
WebApplicationFactory<Startup> factory, ITestOutputHelper output)
{
_factory = factory;
_output = output;
}

[Fact]
public void GenerateGraph()
{
// fetch the required services from the root container of the app
var graphWriter = _factory.Services.GetRequiredService<DfaGraphWriter>();
var endpointData = _factory.Services.GetRequiredService<EndpointDataSource>();

Directory.CreateDirectory("Files");

// build the graph
using (var sw = new StringWriter())
{
graphWriter.Write(endpointData, sw);
var graph = sw.ToString();

// write the graph to the test output
_output.WriteLine(graph);
}
}
}
}
27 changes: 27 additions & 0 deletions src/Tests/ApiRoutesTest/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:52434/",
"sslPort": 44356
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ApiRoutesTest": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this remove Kestrel?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this remove Kestrel?

This is just a xUnit Test Project, You can remove all of this config.
Also, it is possible to refactor the code, By deleting the ApiRouteTest project and implement it inside of the SERVER project as a new endpoint "/graph"
But this approach is better as the author said in the article :
https://andrewlock.net/adding-an-endpoint-graph-to-your-aspnetcore-application/

"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}