|
8 | 8 | using System.Text; |
9 | 9 | using System.Text.Json; |
10 | 10 | using Microsoft.AspNetCore.Authentication; |
| 11 | +using Microsoft.AspNetCore.Mvc; |
11 | 12 | using Microsoft.AspNetCore.Routing; |
12 | 13 | using Microsoft.Net.Http.Headers; |
13 | 14 |
|
@@ -525,6 +526,136 @@ public void LocalRedirect_WithNonLocalUrlAndPermanentTrueAndPreserveTrue_ResultH |
525 | 526 | Assert.True(result.PreserveMethod); |
526 | 527 | } |
527 | 528 |
|
| 529 | + [Fact] |
| 530 | + public void NoContent_ResultHasCorrectValues() |
| 531 | + { |
| 532 | + // Act |
| 533 | + var result = Results.NoContent() as NoContent; |
| 534 | + |
| 535 | + // Assert |
| 536 | + Assert.Equal(StatusCodes.Status204NoContent, result.StatusCode); |
| 537 | + } |
| 538 | + |
| 539 | + [Fact] |
| 540 | + public void NotFound_WithValue_ResultHasCorrectValues() |
| 541 | + { |
| 542 | + // Arrange |
| 543 | + var value = new { }; |
| 544 | + |
| 545 | + // Act |
| 546 | + var result = Results.NotFound(value) as NotFound<object>; |
| 547 | + |
| 548 | + // Assert |
| 549 | + Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode); |
| 550 | + Assert.Equal(value, result.Value); |
| 551 | + } |
| 552 | + |
| 553 | + [Fact] |
| 554 | + public void NotFound_WithNoArgs_ResultHasCorrectValues() |
| 555 | + { |
| 556 | + // Act |
| 557 | + var result = Results.NotFound() as NotFound; |
| 558 | + |
| 559 | + // Assert |
| 560 | + Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode); |
| 561 | + } |
| 562 | + |
| 563 | + [Fact] |
| 564 | + public void Ok_WithValue_ResultHasCorrectValues() |
| 565 | + { |
| 566 | + // Arrange |
| 567 | + var value = new { }; |
| 568 | + |
| 569 | + // Act |
| 570 | + var result = Results.Ok(value) as Ok<object>; |
| 571 | + |
| 572 | + // Assert |
| 573 | + Assert.Equal(StatusCodes.Status200OK, result.StatusCode); |
| 574 | + Assert.Equal(value, result.Value); |
| 575 | + } |
| 576 | + |
| 577 | + [Fact] |
| 578 | + public void Ok_WithNoArgs_ResultHasCorrectValues() |
| 579 | + { |
| 580 | + // Act |
| 581 | + var result = Results.Ok() as Ok; |
| 582 | + |
| 583 | + // Assert |
| 584 | + Assert.Equal(StatusCodes.Status200OK, result.StatusCode); |
| 585 | + } |
| 586 | + |
| 587 | + [Fact] |
| 588 | + public void Problem_WithArgs_ResultHasCorrectValues() |
| 589 | + { |
| 590 | + // Arrange |
| 591 | + var detail = "test detail"; |
| 592 | + var instance = "test instance"; |
| 593 | + var statusCode = StatusCodes.Status409Conflict; |
| 594 | + var title = "test title"; |
| 595 | + var type = "test type"; |
| 596 | + var extensions = new Dictionary<string, object> { { "test", "value" } }; |
| 597 | + |
| 598 | + // Act |
| 599 | + var result = Results.Problem(detail, instance, statusCode, title, type, extensions) as ProblemHttpResult; |
| 600 | + |
| 601 | + // Assert |
| 602 | + Assert.Equal(detail, result.ProblemDetails.Detail); |
| 603 | + Assert.Equal(instance, result.ProblemDetails.Instance); |
| 604 | + Assert.Equal("application/problem+json", result.ContentType); |
| 605 | + Assert.Equal(statusCode, result.StatusCode); |
| 606 | + Assert.Equal(title, result.ProblemDetails.Title); |
| 607 | + Assert.Equal(type, result.ProblemDetails.Type); |
| 608 | + Assert.Equal(extensions, result.ProblemDetails.Extensions); |
| 609 | + } |
| 610 | + |
| 611 | + [Fact] |
| 612 | + public void Problem_WithNoArgs_ResultHasCorrectValues() |
| 613 | + { |
| 614 | + /// Act |
| 615 | + var result = Results.Problem() as ProblemHttpResult; |
| 616 | + |
| 617 | + // Assert |
| 618 | + Assert.Null(result.ProblemDetails.Detail); |
| 619 | + Assert.Null(result.ProblemDetails.Instance); |
| 620 | + Assert.Equal("application/problem+json", result.ContentType); |
| 621 | + Assert.Equal(StatusCodes.Status500InternalServerError, result.StatusCode); |
| 622 | + Assert.Equal("An error occurred while processing your request.", result.ProblemDetails.Title); |
| 623 | + Assert.Equal("https://tools.ietf.org/html/rfc7231#section-6.6.1", result.ProblemDetails.Type); |
| 624 | + Assert.Empty(result.ProblemDetails.Extensions); |
| 625 | + } |
| 626 | + |
| 627 | + [Fact] |
| 628 | + public void Problem_WithProblemArg_ResultHasCorrectValues() |
| 629 | + { |
| 630 | + // Arrange |
| 631 | + var problem = new ProblemDetails { Title = "Test title" }; |
| 632 | + |
| 633 | + // Act |
| 634 | + var result = Results.Problem(problem) as ProblemHttpResult; |
| 635 | + |
| 636 | + // Assert |
| 637 | + Assert.Equal(problem, result.ProblemDetails); |
| 638 | + Assert.Equal("Test title", result.ProblemDetails.Title); |
| 639 | + Assert.Equal("application/problem+json", result.ContentType); |
| 640 | + Assert.Equal(StatusCodes.Status500InternalServerError, result.StatusCode); |
| 641 | + } |
| 642 | + |
| 643 | + [Fact] |
| 644 | + public void Problem_WithValidationProblemArg_ResultHasCorrectValues() |
| 645 | + { |
| 646 | + // Arrange |
| 647 | + var problem = new HttpValidationProblemDetails { Title = "Test title" }; |
| 648 | + |
| 649 | + // Act |
| 650 | + var result = Results.Problem(problem) as ProblemHttpResult; |
| 651 | + |
| 652 | + // Assert |
| 653 | + Assert.Equal(problem, result.ProblemDetails); |
| 654 | + Assert.Equal("Test title", result.ProblemDetails.Title); |
| 655 | + Assert.Equal("application/problem+json", result.ContentType); |
| 656 | + Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode); |
| 657 | + } |
| 658 | + |
528 | 659 | [Theory] |
529 | 660 | [MemberData(nameof(FactoryMethodsFromTuples))] |
530 | 661 | public void FactoryMethod_ReturnsCorrectResultType(Expression<Func<IResult>> expression, Type expectedReturnType) |
|
0 commit comments