-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathConflictObjectResultAssertions_Tests.cs
73 lines (59 loc) · 2.62 KB
/
ConflictObjectResultAssertions_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
using FluentAssertions.Mvc.Tests.Helpers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using System;
using Xunit;
namespace FluentAssertions.AspNetCore.Mvc.Tests
{
public class ConflictObjectResultAssertions_Tests
{
private const string TestError = "testError";
[Fact]
public void Error_GivenConflictObjectResult_ShouldHaveTheSameError()
{
var result = new TestController().Conflict(TestError);
result.Should().BeConflictObjectResult().Error.Should().BeSameAs(TestError);
}
[Fact]
public void SerializableError_GivenExpectedModelState_ShouldPass()
{
const string testErrorKey = "TestErrorKey";
const string testErrorMessage = "TestErrorMessage";
var testModelState = new ModelStateDictionary();
testModelState.AddModelError(testErrorKey, testErrorMessage);
var result = new TestController().Conflict(testModelState);
result.Should().BeConflictObjectResult().SerializableError.Should().ContainKey(testErrorKey);
}
[Fact]
public void ErrorAs_GivenExpectedError_ShouldPass()
{
var result = new TestController().Conflict(TestError);
result.Should().BeConflictObjectResult().ErrorAs<string>().Should().Be(TestError);
}
[Fact]
public void ErrorAs_GivenUnexpectedError_ShouldFail()
{
var result = new TestController().Conflict(TestError);
Action a = () => result.Should().BeConflictObjectResult().ErrorAs<string>().Should().Be("xyx");
a.Should().Throw<Exception>();
}
[Fact]
public void ErrorAs_GivenWrongType_ShouldFail()
{
var result = new TestController().Conflict(TestError);
var failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundY(
"ConflictObjectResult.Error", typeof(int), typeof(string));
Action a = () => result.Should().BeConflictObjectResult().ErrorAs<int>().Should().Be(2);
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
[Fact]
public void ErrorAs_Null_ShouldFail()
{
ActionResult result = new ConflictObjectResult(null as object);
var failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundNull(
"ConflictObjectResult.Error", typeof(object));
Action a = () => result.Should().BeConflictObjectResult().ErrorAs<object>();
a.Should().Throw<Exception>().WithMessage(failureMessage);
}
}
}