Skip to content
Merged
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
10 changes: 5 additions & 5 deletions eng/helix/content/InstallDotNet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ param(

& $PSScriptRoot\Download.ps1 "https://dot.net/v1/dotnet-install.ps1" $PSScriptRoot\dotnet-install.ps1
Write-Host "Download of dotnet-install.ps1 complete..."
Write-Host "Installing SDK...& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Version $sdkVersion -InstallDir $installDir"
Invoke-Expression "& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Version $sdkVersion -InstallDir $installDir"
Write-Host "Installing Runtime...& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Runtime dotnet -Version $runtimeVersion -InstallDir $installDir"
Invoke-Expression "& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Runtime dotnet -Version $runtimeVersion -InstallDir $installDir"
Write-Host "InstallDotNet.ps1 complete..."
Write-Host "Installing SDK...& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Version $sdkVersion -InstallDir $installDir -NoPath"
Invoke-Expression "& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Version $sdkVersion -InstallDir $installDir -NoPath"
Write-Host "Installing Runtime...& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Runtime dotnet -Version $runtimeVersion -InstallDir $installDir -NoPath"
Invoke-Expression "& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Runtime dotnet -Version $runtimeVersion -InstallDir $installDir -NoPath"
Write-Host "InstallDotNet.ps1 complete..."
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this change show up here❔

BTW @HaoK you'll need to port #24968 to release/5.0. It missed today's branching.

Copy link
Member

Choose a reason for hiding this comment

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

Okay I can file another PR unless we want it to go in with this one?

Copy link
Contributor

Choose a reason for hiding this comment

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

For tracking, better separate but it's up to @pranavkm if validation passes this time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry missed this. I changed the branch after I created it, let me rebase on 5.0 since this build is busted anyway

62 changes: 47 additions & 15 deletions src/Mvc/Mvc.Core/src/ControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1886,13 +1886,29 @@ public virtual ObjectResult Problem(
string title = null,
string type = null)
{
var problemDetails = ProblemDetailsFactory.CreateProblemDetails(
HttpContext,
statusCode: statusCode ?? 500,
title: title,
type: type,
detail: detail,
instance: instance);
ProblemDetails problemDetails;
if (ProblemDetailsFactory == null)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have some precedence for having test-only code paths in Controller \ ControllerBase (e.g.

if (_controllerContext == null)
{
_controllerContext = new ControllerContext();
}
). It felt excessive to author a default implementation of the factory when it's easy to instantiate ProblemDetails \ ValidationProblemDetails in the action.

{
// ProblemDetailsFactory may be null in unit testing scenarios. Improvise to make this more testable.
problemDetails = new ProblemDetails
{
Detail = detail,
Instance = instance,
Status = statusCode ?? 500,
Title = title,
Type = type,
};
}
else
{
problemDetails = ProblemDetailsFactory.CreateProblemDetails(
HttpContext,
statusCode: statusCode ?? 500,
title: title,
type: type,
detail: detail,
instance: instance);
}

return new ObjectResult(problemDetails)
{
Expand Down Expand Up @@ -1958,14 +1974,30 @@ public virtual ActionResult ValidationProblem(
{
modelStateDictionary ??= ModelState;

var validationProblem = ProblemDetailsFactory.CreateValidationProblemDetails(
HttpContext,
modelStateDictionary,
statusCode: statusCode,
title: title,
type: type,
detail: detail,
instance: instance);
ValidationProblemDetails validationProblem;
if (ProblemDetailsFactory == null)
{
// ProblemDetailsFactory may be null in unit testing scenarios. Improvise to make this more testable.
validationProblem = new ValidationProblemDetails(modelStateDictionary)
{
Detail = detail,
Instance = instance,
Status = statusCode,
Title = title,
Type = type,
};
}
else
{
validationProblem = ProblemDetailsFactory?.CreateValidationProblemDetails(
HttpContext,
modelStateDictionary,
statusCode: statusCode,
title: title,
type: type,
detail: detail,
instance: instance);
}

if (validationProblem.Status == 400)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public void ControllerAcceptedAtRoute_InvokedInUnitTests()
Assert.Equal(routeName, acceptedAtRouteResult.RouteName);
Assert.Single(acceptedAtRouteResult.RouteValues);
Assert.Equal("sample", acceptedAtRouteResult.RouteValues["route"]);
Assert.Same(value,acceptedAtRouteResult.Value);
Assert.Same(value, acceptedAtRouteResult.Value);

// Arrange
controller = new TestabilityController();
Expand Down Expand Up @@ -682,6 +682,42 @@ public void ViewComponent_WithArguments()
Assert.Equal(new { Arg1 = "Hi", Arg2 = "There" }, result.Arguments);
}

[Fact]
public void Problem_Works()
{
// Arrange
var detail = "Some random error";
var controller = new TestabilityController();

// Act
var result = controller.Problem(detail);

// Assert
var badRequest = Assert.IsType<ObjectResult>(result);
var problemDetails = Assert.IsType<ProblemDetails>(badRequest.Value);
Assert.Equal(detail, problemDetails.Detail);
}

[Fact]
public void ValidationProblem_Works()
{
// Arrange
var detail = "Some random error";
var controller = new TestabilityController();

// Act
controller.ModelState.AddModelError("some-key", "some-error");
var result = controller.ValidationProblem(detail);

// Assert
var badRequest = Assert.IsType<ObjectResult>(result);
var validationProblemDetails = Assert.IsType<ValidationProblemDetails>(badRequest.Value);
Assert.Equal(detail, validationProblemDetails.Detail);
var error = Assert.Single(validationProblemDetails.Errors);
Assert.Equal("some-key", error.Key);
Assert.Equal(new[] { "some-error" }, error.Value);
}

public static IEnumerable<object[]> TestabilityViewTestData
{
get
Expand Down