forked from fluentassertions/fluentassertions.aspnetcore.mvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAcceptedAtActionResultAssertions.cs
89 lines (79 loc) · 4.33 KB
/
AcceptedAtActionResultAssertions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using FluentAssertions.Execution;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Diagnostics;
namespace FluentAssertions.AspNetCore.Mvc
{
/// <summary>
/// Contains a number of methods to assert that a <see cref="AcceptedAtActionResult"/> is in the expected state.
/// </summary>
[DebuggerNonUserCode]
public class AcceptedAtActionResultAssertions : ObjectResultAssertionsBase<AcceptedAtActionResult, AcceptedAtActionResultAssertions>
{
/// <summary>
/// Initializes a new instance of the <see cref="AcceptedAtActionResultAssertions" /> class.
/// </summary>
public AcceptedAtActionResultAssertions(AcceptedAtActionResult subject) : base(subject) { }
/// <summary>
/// Asserts that the action name is the expected action.
/// </summary>
/// <param name="expectedActionName">The expected action.</param>
/// <param name="reason">
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
/// </param>
/// <param name="reasonArgs">
/// Zero or more objects to format using the placeholders in <paramref name="reason"/>.
/// </param>
public AcceptedAtActionResultAssertions WithActionName(string expectedActionName, string reason = "", params object[] reasonArgs)
{
string actualActionName = ObjectResultSubject.ActionName;
Execute.Assertion
.ForCondition(string.Equals(actualActionName, expectedActionName, StringComparison.OrdinalIgnoreCase))
.BecauseOf(reason, reasonArgs)
.WithDefaultIdentifier("AcceptedAtActionResult.ActionName")
.FailWith(FailureMessages.CommonFailMessage, expectedActionName, actualActionName);
return this;
}
/// <summary>
/// Asserts that the controller name is the expected controller.
/// </summary>
/// <param name="expectedControllerName">The expected controller.</param>
/// <param name="reason">
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
/// </param>
/// <param name="reasonArgs">
/// Zero or more objects to format using the placeholders in <paramref name="reason"/>.
/// </param>
public AcceptedAtActionResultAssertions WithControllerName(string expectedControllerName, string reason = "", params object[] reasonArgs)
{
string actualControllerName = ObjectResultSubject.ControllerName;
Execute.Assertion
.ForCondition(string.Equals(actualControllerName, expectedControllerName, StringComparison.OrdinalIgnoreCase))
.BecauseOf(reason, reasonArgs)
.WithDefaultIdentifier("AcceptedAtActionResult.ControllerName")
.FailWith(FailureMessages.CommonFailMessage, expectedControllerName, actualControllerName);
return this;
}
/// <summary>
/// Asserts that the redirect has the expected route value.
/// </summary>
/// <param name="key">The expected key.</param>
/// <param name="expectedValue">The expected value.</param>
/// <param name="reason">
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
/// </param>
/// <param name="reasonArgs">
/// Zero or more objects to format using the placeholders in <paramref name="reason"/>.
/// </param>
public AcceptedAtActionResultAssertions WithRouteValue(string key, object expectedValue, string reason = "", params object[] reasonArgs)
{
var actualRouteValues = ObjectResultSubject.RouteValues;
AssertionHelpers.AssertStringObjectDictionary(actualRouteValues,
"AcceptedAtActionResult.RouteValues", key, expectedValue, reason, reasonArgs);
return this;
}
}
}