Skip to content

Commit df3b2b2

Browse files
committed
Refactor AcceptedResultAssertions to use ObjectResultAssertionsBase. (And fix the error messages.)
1 parent 9d01093 commit df3b2b2

File tree

5 files changed

+19
-52
lines changed

5 files changed

+19
-52
lines changed

src/FluentAssertions.AspNetCore.Mvc/AcceptedResultAssertions.cs

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
using System;
2-
using System.Diagnostics;
3-
using FluentAssertions.Execution;
4-
using FluentAssertions.Primitives;
1+
using FluentAssertions.Execution;
52
using Microsoft.AspNetCore.Mvc;
3+
using System;
4+
using System.Diagnostics;
65

76
namespace FluentAssertions.AspNetCore.Mvc
87
{
98
/// <summary>
109
/// Contains a number of methods to assert that a <see cref="AcceptedResult"/> is in the expected state.
1110
/// </summary>
1211
[DebuggerNonUserCode]
13-
public class AcceptedResultAssertions : ObjectAssertions
12+
public class AcceptedResultAssertions : ObjectResultAssertionsBase<AcceptedResult, AcceptedResultAssertions>
1413
{
1514
#region Public Constructors
1615

@@ -25,46 +24,14 @@ public AcceptedResultAssertions(AcceptedResult subject) : base(subject)
2524
#endregion
2625

2726
#region Public Properties
28-
/// <summary>
29-
/// The value on the AcceptedResult
30-
/// </summary>
31-
public object Value => AcceptedResultSubject.Value;
32-
3327
/// <summary>
3428
/// The location on the AcceptedResult
3529
/// </summary>
36-
public string Location => AcceptedResultSubject.Location;
37-
38-
#endregion
39-
40-
#region Private Properties
41-
private AcceptedResult AcceptedResultSubject => (AcceptedResult)Subject;
30+
public string Location => ObjectResultSubject.Location;
4231

4332
#endregion
4433

4534
#region Public Methods
46-
/// <summary>
47-
/// Asserts the value is of the expected type.
48-
/// </summary>
49-
/// <typeparam name="TValue">The expected type.</typeparam>
50-
/// <returns>The typed value.</returns>
51-
public TValue ValueAs<TValue>()
52-
{
53-
var value = AcceptedResultSubject.Value;
54-
55-
if (value == null)
56-
Execute.Assertion
57-
.WithDefaultIdentifier("AcceptedResultAssertions.Value")
58-
.FailWith(FailureMessages.CommonNullWasSuppliedFailMessage, typeof(TValue));
59-
60-
Execute.Assertion
61-
.ForCondition(value is TValue)
62-
.WithDefaultIdentifier("AcceptedResultAssertions.Value")
63-
.FailWith(FailureMessages.CommonTypeFailMessage, typeof(TValue), value.GetType());
64-
65-
return (TValue)value;
66-
}
67-
6835
/// <summary>
6936
/// Asserts the uri has the expected value.
7037
/// </summary>
@@ -86,7 +53,7 @@ public AcceptedResultAssertions WithUri(Uri uri, string reason = "", params obje
8653
Execute.Assertion
8754
.BecauseOf(reason, reasonArgs)
8855
.ForCondition(expectedUri == Location)
89-
.WithDefaultIdentifier("AcceptedResultAssertions.Uri")
56+
.WithDefaultIdentifier("AcceptedResult.Uri")
9057
.FailWith(FailureMessages.CommonFailMessage, expectedUri, Location);
9158

9259
return this;
@@ -111,7 +78,7 @@ public AcceptedResultAssertions WithUri(string uri, string reason = "", params o
11178
Execute.Assertion
11279
.BecauseOf(reason, reasonArgs)
11380
.ForCondition(uri == Location)
114-
.WithDefaultIdentifier("AcceptedResultAssertions.Uri")
81+
.WithDefaultIdentifier("AcceptedResult.Uri")
11582
.FailWith(FailureMessages.CommonFailMessage, uri, Location);
11683

11784
return this;

src/FluentAssertions.AspNetCore.Mvc/ObjectResultAssertionsBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace FluentAssertions.AspNetCore.Mvc
1212
/// <summary>
1313
/// Base class for <see cref="ObjectResultAssertions"/>.
1414
/// </summary>
15-
[DebuggerNonUserCode]
15+
//[DebuggerNonUserCode]
1616
public class ObjectResultAssertionsBase<TObjectResult, TObjectResultAssertion> : ObjectAssertions
1717
where TObjectResult : ObjectResult
1818
where TObjectResultAssertion : ObjectResultAssertionsBase<TObjectResult, TObjectResultAssertion>

tests/FluentAssertions.AspNetCore.Mvc.Tests/AcceptedAtActionResultAssertions_Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System;
2-
using FluentAssertions.Mvc.Tests.Helpers;
1+
using FluentAssertions.Mvc.Tests.Helpers;
32
using Microsoft.AspNetCore.Mvc;
3+
using System;
44
using Xunit;
55

66
namespace FluentAssertions.AspNetCore.Mvc.Tests

tests/FluentAssertions.AspNetCore.Mvc.Tests/AcceptedAtRouteResultAssertions_Tests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System;
2-
using FluentAssertions.Mvc.Tests.Helpers;
1+
using FluentAssertions.Mvc.Tests.Helpers;
32
using Microsoft.AspNetCore.Mvc;
3+
using System;
44
using Xunit;
55

66
namespace FluentAssertions.AspNetCore.Mvc.Tests
77
{
8-
8+
99
public class AcceptedAtRouteResultAssertions_Tests
1010
{
1111
public const string Reason = FailureMessageHelper.Reason;

tests/FluentAssertions.AspNetCore.Mvc.Tests/AcceptedResultAssertions_Tests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System;
2-
using FluentAssertions.Mvc.Tests.Helpers;
1+
using FluentAssertions.Mvc.Tests.Helpers;
32
using Microsoft.AspNetCore.Mvc;
3+
using System;
44
using Xunit;
55

66
namespace FluentAssertions.AspNetCore.Mvc.Tests
@@ -38,7 +38,7 @@ public void ValueAs_GivenWrongType_ShouldFail()
3838
{
3939
var result = new TestController().Accepted(TestUri, TestValue);
4040
var failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundY(
41-
"AcceptedResultAssertions.Value", typeof(int), typeof(string));
41+
"AcceptedResult.Value", typeof(int), typeof(string));
4242

4343
Action a = () => result.Should().BeAcceptedResult().ValueAs<int>().Should().Be(2);
4444

@@ -50,7 +50,7 @@ public void ValueAs_Null_ShouldFail()
5050
{
5151
ActionResult result = new AcceptedResult(TestUri, null);
5252
var failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundNull(
53-
"AcceptedResultAssertions.Value", typeof(object));
53+
"AcceptedResult.Value", typeof(object));
5454

5555
Action a = () => result.Should().BeAcceptedResult().ValueAs<object>();
5656

@@ -69,7 +69,7 @@ public void WithUri_GivenExpectedUri_ShouldPass()
6969
public void WithUri_GivenWrongUri_ShouldFail()
7070
{
7171
var result = new TestController().Accepted(TestWrongUri, TestValue);
72-
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("AcceptedResultAssertions.Uri", TestUri.ToString(), TestWrongUri.ToString());
72+
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("AcceptedResult.Uri", TestUri.ToString(), TestWrongUri.ToString());
7373

7474
Action a = () => result.Should().BeAcceptedResult().WithUri(TestUri, Reason, ReasonArgs);
7575

@@ -88,7 +88,7 @@ public void WithUri_GivenExpectedUriAsString_ShouldPass()
8888
public void WithUri_GivenWrongUriAsString_ShouldFail()
8989
{
9090
var result = new TestController().Accepted(TestWrongUriAsString, TestValue);
91-
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("AcceptedResultAssertions.Uri", TestUriAsString, TestWrongUriAsString);
91+
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("AcceptedResult.Uri", TestUriAsString, TestWrongUriAsString);
9292

9393
Action a = () => result.Should().BeAcceptedResult().WithUri(TestUriAsString, Reason, ReasonArgs);
9494

0 commit comments

Comments
 (0)