Skip to content

Commit bb704e9

Browse files
committed
Refactor CreatedAtRouteResultAssertions to use ObjectResultAssertionsBase.
1 parent c91edc5 commit bb704e9

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

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

+4-28
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="CreatedAtRouteResult"/> is in the expected state.
1110
/// </summary>
1211
[DebuggerNonUserCode]
13-
public class CreatedAtRouteResultAssertions : ObjectAssertions
12+
public class CreatedAtRouteResultAssertions : ObjectResultAssertionsBase<CreatedAtRouteResult, CreatedAtRouteResultAssertions>
1413
{
1514
/// <summary>
1615
/// Initializes a new instance of the <see cref="CreatedAtRouteResultAssertions" /> class.
@@ -62,28 +61,5 @@ public CreatedAtRouteResultAssertions WithRouteValue(string key, object expected
6261

6362
return this;
6463
}
65-
66-
/// <summary>
67-
/// Asserts the value is of the expected type.
68-
/// </summary>
69-
/// <typeparam name="TValue">The expected type.</typeparam>
70-
/// <returns>The typed value.</returns>
71-
public TValue ValueAs<TValue>()
72-
{
73-
var subjectTyped = Subject as CreatedAtRouteResult;
74-
var value = subjectTyped.Value;
75-
76-
if (value == null)
77-
Execute.Assertion
78-
.WithDefaultIdentifier("CreatedAtRouteResult.Value")
79-
.FailWith(FailureMessages.CommonNullWasSuppliedFailMessage, typeof(TValue));
80-
81-
Execute.Assertion
82-
.ForCondition(value is TValue)
83-
.WithDefaultIdentifier("CreatedAtRouteResult.Value")
84-
.FailWith(FailureMessages.CommonTypeFailMessage, typeof(TValue), value.GetType());
85-
86-
return (TValue)value;
87-
}
8864
}
8965
}

‎tests/FluentAssertions.AspNetCore.Mvc.Tests/CreatedAtRouteResultAssertions_Tests.cs

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

0 commit comments

Comments
 (0)