Skip to content

Commit 1eaf112

Browse files
committedOct 24, 2020
Refactor NotFoundObjectResultAssertions to use ObjectResultAssertionsBase.
1 parent 8837b44 commit 1eaf112

File tree

2 files changed

+4
-43
lines changed

2 files changed

+4
-43
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
using System.Diagnostics;
2-
using FluentAssertions.Execution;
3-
using FluentAssertions.Primitives;
4-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Mvc;
2+
using System.Diagnostics;
53

64
namespace FluentAssertions.AspNetCore.Mvc
75
{
86
/// <summary>
97
/// Contains a number of methods to assert that a <see cref="NotFoundObjectResult"/> is in the expected state.
108
/// </summary>
119
[DebuggerNonUserCode]
12-
public class NotFoundObjectResultAssertions : ObjectAssertions
10+
public class NotFoundObjectResultAssertions : ObjectResultAssertionsBase<NotFoundObjectResult, NotFoundObjectResultAssertions>
1311
{
1412
#region Public Constructors
1513

@@ -22,42 +20,5 @@ public NotFoundObjectResultAssertions(NotFoundObjectResult subject) : base(subje
2220
}
2321

2422
#endregion
25-
26-
#region Public Properties
27-
/// <summary>
28-
/// The value on the NotFoundObjectResult
29-
/// </summary>
30-
public object Value => NotFoundObjectResultSubject.Value;
31-
32-
#endregion
33-
34-
#region Private Properties
35-
private NotFoundObjectResult NotFoundObjectResultSubject => (NotFoundObjectResult)Subject;
36-
37-
#endregion
38-
39-
#region Public Methods
40-
/// <summary>
41-
/// Asserts the value is of the expected type.
42-
/// </summary>
43-
/// <typeparam name="TValue">The expected type.</typeparam>
44-
/// <returns>The typed value.</returns>
45-
public TValue ValueAs<TValue>()
46-
{
47-
var value = NotFoundObjectResultSubject.Value;
48-
49-
if (value == null)
50-
Execute.Assertion
51-
.WithDefaultIdentifier("NotFoundObjectResult.Value")
52-
.FailWith(FailureMessages.CommonNullWasSuppliedFailMessage, typeof(TValue));
53-
54-
Execute.Assertion
55-
.ForCondition(value is TValue)
56-
.WithDefaultIdentifier("NotFoundObjectResult.Value")
57-
.FailWith(FailureMessages.CommonTypeFailMessage, typeof(TValue), value.GetType());
58-
59-
return (TValue)value;
60-
}
61-
#endregion
6223
}
6324
}

‎src/FluentAssertions.AspNetCore.Mvc/ObjectResultAssertionsBase.cs

+1-1
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>

0 commit comments

Comments
 (0)
Failed to load comments.