Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --no-restore
run: dotnet test --no-restore --filter Category!=Samples
14 changes: 14 additions & 0 deletions NMatcher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NMatcher.FluentAssertions",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NMatcher.FluentAssertions.Tests", "tests\NMatcher.FluentAssertions.Tests\NMatcher.FluentAssertions.Tests.csproj", "{0DF37F7A-4722-4873-B00F-C8A280F8FADA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{3964488E-ED62-4F41-970C-763841630355}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NMatcher.Samples.Api", "samples\NMatcher.Samples.Api\NMatcher.Samples.Api.csproj", "{E6718A10-90BF-4A12-9F62-A41EA160029B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NMatcher.Samples.Api.Tests", "samples\NMatcher.Samples.Api.Tests\NMatcher.Samples.Api.Tests.csproj", "{B23EE86F-B5EB-43DA-BCDA-133579782271}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -43,6 +49,12 @@ Global
{0DF37F7A-4722-4873-B00F-C8A280F8FADA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DF37F7A-4722-4873-B00F-C8A280F8FADA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DF37F7A-4722-4873-B00F-C8A280F8FADA}.Release|Any CPU.Build.0 = Release|Any CPU
{E6718A10-90BF-4A12-9F62-A41EA160029B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6718A10-90BF-4A12-9F62-A41EA160029B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6718A10-90BF-4A12-9F62-A41EA160029B}.Release|Any CPU.Build.0 = Release|Any CPU
{B23EE86F-B5EB-43DA-BCDA-133579782271}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B23EE86F-B5EB-43DA-BCDA-133579782271}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B23EE86F-B5EB-43DA-BCDA-133579782271}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -53,6 +65,8 @@ Global
{4DE59B9C-826D-441C-878F-C7A4E65DC35B} = {7E005CFE-FF3B-4E55-B8C4-96E8F2AB4481}
{CB8E085C-5062-4AD3-A954-BF64C6B0766B} = {5EA69303-20C6-4906-8F93-298D65E73A92}
{0DF37F7A-4722-4873-B00F-C8A280F8FADA} = {7E005CFE-FF3B-4E55-B8C4-96E8F2AB4481}
{E6718A10-90BF-4A12-9F62-A41EA160029B} = {3964488E-ED62-4F41-970C-763841630355}
{B23EE86F-B5EB-43DA-BCDA-133579782271} = {3964488E-ED62-4F41-970C-763841630355}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DAE6A9BE-43BC-4653-BC7C-191832BB7F84}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using FluentAssertions;
using NMatcher.FluentAssertions;

namespace NMatcher.Samples.Api.Tests.Integration;


[Trait("Category", "Sample")]
public class WeatherForecastControllerTests
{
[Fact]
public async Task test_weather_forecast_endpoint()
{
var program = new TestApiProgram();
var client = program.CreateClient();

var rs = await client.GetAsync("/WeatherForecast");
var response = await rs.Content.ReadAsStringAsync();

response.Should().MatchJson(@"
[
{
""date"": ""@[email protected]()"",
""temperatureC"": ""@int@"",
""temperatureF"": ""@int@"",
""summary"": ""@[email protected]('Freezing', 'Cool', 'Mild', 'Warm', 'Balmy', 'Hot')""
},
""@skip@""
]
");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.16" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NMatcher.FluentAssertions" Version="2.2.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NMatcher.Samples.Api\NMatcher.Samples.Api.csproj" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions samples/NMatcher.Samples.Api.Tests/TestApiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc.Testing;

namespace NMatcher.Samples.Api.Tests;

sealed class TestApiProgram : WebApplicationFactory<Program>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.UseEnvironment("Test");
}
}
1 change: 1 addition & 0 deletions samples/NMatcher.Samples.Api.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;

namespace NMatcher.Samples.Api.Controllers;

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Cool", "Mild", "Warm", "Balmy", "Hot",
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
18 changes: 18 additions & 0 deletions samples/NMatcher.Samples.Api/NMatcher.Samples.Api.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0;</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>11</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="$(AssemblyName).Tests" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions samples/NMatcher.Samples.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
41 changes: 41 additions & 0 deletions samples/NMatcher.Samples.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:45067",
"sslPort": 44351
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5270",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7048;http://localhost:5270",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
12 changes: 12 additions & 0 deletions samples/NMatcher.Samples.Api/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace NMatcher.Samples.Api;

public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string? Summary { get; set; }
}
8 changes: 8 additions & 0 deletions samples/NMatcher.Samples.Api/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions samples/NMatcher.Samples.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}