-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAcceptedResultAssertions_Tests.cs
98 lines (75 loc) · 3.63 KB
/
AcceptedResultAssertions_Tests.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
90
91
92
93
94
95
96
97
98
using FluentAssertions.Mvc.Tests.Helpers;
using Microsoft.AspNetCore.Mvc;
using System;
using Xunit;
namespace FluentAssertions.AspNetCore.Mvc.Tests
{
public class AcceptedResultAssertions_Tests
{
public const string Reason = FailureMessageHelper.Reason;
public readonly static object[] ReasonArgs = FailureMessageHelper.ReasonArgs;
private const string TestValue = "testValue";
private const string TestUriAsString = "http://localhost:5000";
private const string TestWrongUriAsString = "http://somedomain.com:5000";
private readonly Uri TestUri = new Uri(TestUriAsString);
private readonly Uri TestWrongUri = new Uri(TestWrongUriAsString);
[Fact]
public void Value_GivenAcceptedResult_ShouldHaveTheSameValue()
{
var result = new TestController().Accepted(TestUri, TestValue);
result.Should().BeAcceptedResult().Value.Should().BeSameAs(TestValue);
}
[Fact]
public void ValueAs_GivenAcceptedResult_ShouldHaveTheSameValue()
{
var result = new TestController().Accepted(TestUri, TestValue);
result.Should().BeAcceptedResult().ValueAs<string>().Should().BeSameAs(TestValue);
}
[Fact]
public void ValueAs_GivenWrongType_ShouldFail()
{
var result = new TestController().Accepted(TestUri, TestValue);
var failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundY(
"AcceptedResult.Value", typeof(int), typeof(string));
Action a = () => result.Should().BeAcceptedResult().ValueAs<int>().Should().Be(2);
a.Should().Throw<Exception>();
}
[Fact]
public void ValueAs_Null_ShouldFail()
{
ActionResult result = new AcceptedResult(TestUri, null);
var failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundNull(
"AcceptedResult.Value", typeof(object));
Action a = () => result.Should().BeAcceptedResult().ValueAs<object>();
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
[Fact]
public void WithUri_GivenExpectedUri_ShouldPass()
{
var result = new TestController().Accepted(TestUri, TestValue);
result.Should().BeAcceptedResult().WithUri(TestUri);
}
[Fact]
public void WithUri_GivenWrongUri_ShouldFail()
{
var result = new TestController().Accepted(TestWrongUri, TestValue);
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("AcceptedResult.Uri", TestUri.ToString(), TestWrongUri.ToString());
Action a = () => result.Should().BeAcceptedResult().WithUri(TestUri, Reason, ReasonArgs);
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
[Fact]
public void WithUri_GivenExpectedUriAsString_ShouldPass()
{
var result = new TestController().Accepted(TestUriAsString, TestValue);
result.Should().BeAcceptedResult().WithUri(TestUriAsString);
}
[Fact]
public void WithUri_GivenWrongUriAsString_ShouldFail()
{
var result = new TestController().Accepted(TestWrongUriAsString, TestValue);
var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("AcceptedResult.Uri", TestUriAsString, TestWrongUriAsString);
Action a = () => result.Should().BeAcceptedResult().WithUri(TestUriAsString, Reason, ReasonArgs);
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
}
}