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

Add Extensions to Translate Ardalis.Result to Microsoft.AspNetCore.Http.IResult #103

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add badrequest to weatherservice, change webmarker to interface
  • Loading branch information
KyleMcMaster committed Nov 22, 2022
commit 85c2e4bc64c5eec82d688fb62f2131733fa200d8
10 changes: 10 additions & 0 deletions sample/Ardalis.Result.Sample.Core/Services/WeatherService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public Result<IEnumerable<WeatherForecast>> GetForecast(ForecastRequestDto model
});
}

if (string.IsNullOrWhiteSpace(model.PostalCode))
{
return Result.Invalid(new List<ValidationError> {
new ValidationError
{
Identifier = nameof(model.PostalCode),
ErrorMessage = "PostalCode is required" }
});
}

// test value
if (model.PostalCode == "55555")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
using Xunit;

namespace Ardalis.Result.SampleMinimalApi.FunctionalTests;
public class NewWeatherForecast : IClassFixture<WebApplicationFactory<WebMarker>>
public class NewWeatherForecast : IClassFixture<WebApplicationFactory<IWebMarker>>
{
private const string ENDPOINT_POST_ROUTE = "/forecast/new";
private readonly HttpClient _client;

public NewWeatherForecast(WebApplicationFactory<WebMarker> factory)
public NewWeatherForecast(WebApplicationFactory<IWebMarker> factory)
{
_client = factory.CreateClient();
}
Expand All @@ -36,7 +36,7 @@ public async Task ReturnsOkWithValueGivenValidPostalCode()
Assert.Equal("Freezing", forecasts.First().Summary);
}

[Fact(Skip = "TODO: Minimal APIs not respecting System.ComponentModel.DataAnnotations")]
[Fact]
public async Task ReturnsBadRequestGivenNoPostalCode()
{
var requestDto = new ForecastRequestDto() { PostalCode = "" };
Expand Down
8 changes: 8 additions & 0 deletions sample/Ardalis.Result.SampleMinimalApi/IWebMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Ardalis.Result.SampleMinimalApi;

/// <summary>
/// This is a simple marker type that is used by the integration tests to reference the correct assembly for host building
/// </summary>
public interface IWebMarker
{
}
2 changes: 1 addition & 1 deletion sample/Ardalis.Result.SampleMinimalApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

app.UseHttpsRedirection();

app.MapPost("/Forecast/New", ([Required]ForecastRequestDto request, WeatherService weatherService) =>
app.MapPost("/Forecast/New", (ForecastRequestDto request, WeatherService weatherService) =>
{
return weatherService.GetForecast(request).ToHttpResult();
})
Expand Down
8 changes: 0 additions & 8 deletions sample/Ardalis.Result.SampleMinimalApi/WebMarker.cs

This file was deleted.