-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SrkToolkit.Domain.AspNetCore2: migrate controller.ValidateResult (WIP)
- Loading branch information
Showing
4 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Sources/SrkToolkit.AspNetCore2.UnitTests/SrkDomainControllerExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
| ||
namespace SrkToolkit.Web.Tests; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
using SrkToolkit.Domain; | ||
using System; | ||
using Xunit; | ||
|
||
public class SrkDomainControllerExtensionsTests | ||
{ | ||
[Fact] | ||
public void ValidResult_TempData_Works() | ||
{ | ||
var context = new AspNetCoreTestContext(); | ||
var controller = new MyController(); | ||
controller.ControllerContext = context.CreateControllerContext(); | ||
var result = new BasicResult<ErrorCode>(); | ||
result.Succeed = true; | ||
var isValid = controller.ValidateResult(result, MessageDisplayMode.TempData); | ||
Assert.True(isValid); | ||
Assert.Empty(context.TempData); | ||
} | ||
|
||
[Fact] | ||
public void InvalidResult_TempData_Works() | ||
{ | ||
var context = new AspNetCoreTestContext(); | ||
var controller = new MyController(); | ||
controller.ControllerContext = context.CreateControllerContext(); | ||
var result = new BasicResult<ErrorCode>(); | ||
result.Errors.Add(ErrorCode.Unauthorized); | ||
result.Succeed = result.Errors.Count == 0; | ||
var isValid = controller.ValidateResult(result, MessageDisplayMode.TempData); | ||
Assert.False(isValid); | ||
Assert.Single(context.TempData); | ||
} | ||
|
||
class MyController : Controller | ||
{ | ||
public ActionResult MyAction() | ||
{ | ||
return this.NoContent(); | ||
} | ||
} | ||
|
||
enum ErrorCode | ||
{ | ||
Invalid, | ||
Unauthorized, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters