-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathNotFoundObjectResultAssertions_Tests.cs
61 lines (50 loc) · 2.09 KB
/
NotFoundObjectResultAssertions_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
using FluentAssertions.Mvc.Tests.Helpers;
using Microsoft.AspNetCore.Mvc;
using System;
using Xunit;
namespace FluentAssertions.AspNetCore.Mvc.Tests
{
public class NotFoundObjectResultAssertions_Tests
{
private const string TestValue = "testValue";
[Fact]
public void Value_GivenNotFoundObjectResult_ShouldHaveTheSameValue()
{
var result = new TestController().NotFound(TestValue);
result.Should().BeNotFoundObjectResult().Value.Should().BeSameAs(TestValue);
}
[Fact]
public void ValueAs_GivenNotFoundObjectResult_ShouldHaveTheSameValue()
{
var result = new TestController().NotFound(TestValue);
result.Should().BeNotFoundObjectResult().ValueAs<string>().Should().BeSameAs(TestValue);
}
[Fact]
public void ValueAs_GivenUnexpectedValue_ShouldFail()
{
var result = new TestController().NotFound(TestValue);
Action a = () => result.Should().BeNotFoundObjectResult().ValueAs<string>().Should().Be("xyx");
a.Should().Throw<Exception>();
}
[Fact]
public void ValueAs_GivenWrongType_ShouldFail()
{
var result = new TestController().NotFound(TestValue);
string failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundY(
"NotFoundObjectResult.Value", typeof(int), typeof(string));
Action a = () => result.Should().BeNotFoundObjectResult().ValueAs<int>().Should().Be(2);
a.Should().Throw<Exception>()
.WithMessage(failureMessage);
}
[Fact]
public void ValueAs_Null_ShouldFail()
{
ActionResult result = new NotFoundObjectResult(null);
string failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundNull(
"NotFoundObjectResult.Value", typeof(object));
Action a = () => result.Should().BeNotFoundObjectResult().ValueAs<object>();
a.Should().Throw<Exception>()
.WithMessage(failureMessage);
}
}
}