Skip to content

Commit 4c44e01

Browse files
committed
completed RedirectResultAssertions and tests
1 parent 475c3aa commit 4c44e01

File tree

2 files changed

+49
-23
lines changed

2 files changed

+49
-23
lines changed

src/FluentAssertions.Mvc3/RedirectResultAssertions.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,42 @@
77

88
namespace FluentAssertions.Mvc3
99
{
10-
public class RedirectResultAssertions : ReferenceTypeAssertions<RedirectResult, RedirectResultAssertions>
10+
public class RedirectResultAssertions : ObjectAssertions
1111
{
12-
public RedirectResultAssertions(RedirectResult subject)
13-
{
14-
Subject = subject;
15-
}
12+
public RedirectResultAssertions(RedirectResult subject) : base(subject) { }
1613

17-
public RedirectResultAssertions HaveUrl(string expectedUrl)
14+
public RedirectResultAssertions WithUrl(string expectedUrl)
1815
{
19-
HaveUrl(expectedUrl, string.Empty, null);
16+
WithUrl(expectedUrl, string.Empty, null);
2017
return this;
2118
}
2219

23-
public RedirectResultAssertions HaveUrl(string expectedUrl, string reason, string reasonArgs)
20+
public RedirectResultAssertions WithUrl(string expectedUrl, string reason, string reasonArgs)
2421
{
22+
string actualUrl = (Subject as RedirectResult).Url;
23+
2524
Execute.Verification
26-
.ForCondition(string.Equals(Subject.Url, expectedUrl, StringComparison.InvariantCultureIgnoreCase))
25+
.ForCondition(string.Equals(actualUrl, expectedUrl, StringComparison.InvariantCultureIgnoreCase))
2726
.BecauseOf(reason, reasonArgs)
28-
.FailWith("Expected RedirectResult.Url to be '{0}' but was '{1}'", expectedUrl, Subject.Url);
27+
.FailWith("Expected RedirectResult.Url to be {0}{reason} but was {1}", expectedUrl, actualUrl);
2928

3029
return this;
3130
}
3231

33-
public RedirectResultAssertions HavePermanent(bool expectedPermanent)
32+
public RedirectResultAssertions WithPermanent(bool expectedPermanent)
3433
{
35-
HavePermanent(expectedPermanent, string.Empty, null);
34+
WithPermanent(expectedPermanent, string.Empty, null);
3635
return this;
3736
}
3837

39-
public RedirectResultAssertions HavePermanent(bool expectedPermanent, string reason, string reasonArgs)
38+
public RedirectResultAssertions WithPermanent(bool expectedPermanent, string reason, string reasonArgs)
4039
{
40+
bool actualPermanent = (Subject as RedirectResult).Permanent;
41+
4142
Execute.Verification
42-
.ForCondition(expectedPermanent == Subject.Permanent)
43+
.ForCondition(expectedPermanent == actualPermanent)
4344
.BecauseOf(reason, reasonArgs)
44-
.FailWith("Expected RedirectResult.Permanent to be '{0}' but was '{1}'", expectedPermanent, Subject.Permanent);
45+
.FailWith("Expected RedirectResult.Permanent to be {0}{reason} but was {1}", expectedPermanent, actualPermanent);
4546

4647
return this;
4748
}
Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,50 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using NUnit.Framework;
62
using System.Web.Mvc;
7-
using FluentAssertions.Mvc3;
3+
using NUnit.Framework;
84

95
namespace FluentAssertions.Mvc3.Tests
106
{
117
[TestFixture]
128
public class RedirectResultAssertions_Tests
139
{
1410
[Test]
15-
public void HaveUrl_GivenValidUrl_ShouldPass()
11+
public void WithUrl_GivenExpectedUrl_ShouldPass()
12+
{
13+
ActionResult result = new RedirectResult("/abc");
14+
15+
result.Should().BeRedirect()
16+
.WithUrl("/abc");
17+
}
18+
19+
[Test]
20+
public void WithUrl_GivenUnexpectedUrl_ShouldFail()
1621
{
1722
ActionResult result = new RedirectResult("/abc");
1823

24+
Action a = () => result.Should().BeRedirect()
25+
.WithUrl("/xyz");
26+
a.ShouldThrow<Exception>()
27+
.WithMessage("Expected RedirectResult.Url to be \"/xyz\" but was \"/abc\"");
28+
}
29+
30+
[Test]
31+
public void WithPermanent_GivenExpectedUrl_ShouldPass()
32+
{
33+
ActionResult result = new RedirectResult("/abc", true);
34+
1935
result.Should().BeRedirect()
20-
.HaveUrl("/abc");
36+
.WithPermanent(true);
2137
}
2238

23-
#warning more tests!
39+
[Test]
40+
public void WithPermanent_GivenUnexpectedUrl_ShouldFail()
41+
{
42+
ActionResult result = new RedirectResult("/abc", true);
43+
44+
Action a = () => result.Should().BeRedirect()
45+
.WithPermanent(false);
46+
a.ShouldThrow<Exception>()
47+
.WithMessage("Expected RedirectResult.Permanent to be False but was True");
48+
}
2449
}
2550
}

0 commit comments

Comments
 (0)