Navigation Menu

Skip to content

Commit

Permalink
Removed common setup from unit test constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
izevaka authored and davidfowl committed May 19, 2012
1 parent fd617dc commit 59175e6
Showing 1 changed file with 45 additions and 22 deletions.
67 changes: 45 additions & 22 deletions JabbR.Tests/QueryStringCollectionTests.cs
Expand Up @@ -14,33 +14,31 @@ public class QueryStringCollectionTests
{
public class Constructor
{
private Uri MakeUri(string parameters)
{
return new Uri("http://example.com?" + parameters);
}

[Fact]
public void ShouldReturnFirstAndSecondParameter()
{
var uri = MakeUri("first=value1&second=value2");
var collection = new QueryStringCollection(uri);
var collection = new QueryStringCollection(
new Uri("http://example.com?first=value1&second=value2")
);

Assert.Equal("value1", collection["first"]);
Assert.Equal("value2", collection["second"]);
}
[Fact]
public void ShouldHandleNameOnlyParameters()
{
var uri = MakeUri("first=value1&second");
var collection = new QueryStringCollection(uri);
var collection = new QueryStringCollection(
new Uri("http://example.com?first=value1&second")
);

Assert.Equal(null, collection["second"]);
}
[Fact]
public void ShouldHandleMultipleAmpersands()
{
var uri = MakeUri("first=value1&second&&");
var collection = new QueryStringCollection(uri);
var collection = new QueryStringCollection(
new Uri("http://example.com?first=value1&second=value2&&")
);

Assert.Equal(2, collection.Count);
}
Expand All @@ -56,14 +54,13 @@ public void ShouldThrowInvalidArgumentExceptionWhenUriIsNull()
}
public class TryGetAndConvert
{
QueryStringCollection _QueryStringCollection;
public TryGetAndConvert()
{
_QueryStringCollection = new QueryStringCollection(new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty"));
}
[Fact]
public void ShouldOutputValueForString()
{
var _QueryStringCollection = new QueryStringCollection(
new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty")
);

string output;
var result = _QueryStringCollection.TryGetAndConvert<string>("stringvalue", out output);

Expand All @@ -75,6 +72,10 @@ public void ShouldOutputValueForString()
[Fact]
public void ShouldOutputValueForInt()
{
var _QueryStringCollection = new QueryStringCollection(
new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty")
);

int output;
var result = _QueryStringCollection.TryGetAndConvert<int>("intvalue", out output);

Expand All @@ -85,6 +86,10 @@ public void ShouldOutputValueForInt()
[Fact]
public void ShouldOutputValueForBool()
{
var _QueryStringCollection = new QueryStringCollection(
new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty")
);

bool output;
var result = _QueryStringCollection.TryGetAndConvert<bool>("boolvalue", out output);

Expand All @@ -95,6 +100,10 @@ public void ShouldOutputValueForBool()
[Fact]
public void ShouldOutputNullForNonexistantString()
{
var _QueryStringCollection = new QueryStringCollection(
new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty")
);

string output;
var result = _QueryStringCollection.TryGetAndConvert<string>("stringvalue1", out output);

Expand All @@ -105,6 +114,10 @@ public void ShouldOutputNullForNonexistantString()
[Fact]
public void ShouldOutputZeroForNonexistantInt()
{
var _QueryStringCollection = new QueryStringCollection(
new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty")
);

int output;
var result = _QueryStringCollection.TryGetAndConvert<int>("nonexistant", out output);

Expand All @@ -114,6 +127,10 @@ public void ShouldOutputZeroForNonexistantInt()
[Fact]
public void ShouldReturnFalseForEmptyValueType()
{
var _QueryStringCollection = new QueryStringCollection(
new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty")
);

int output;
var result = _QueryStringCollection.TryGetAndConvert<int>("empty", out output);

Expand All @@ -122,6 +139,10 @@ public void ShouldReturnFalseForEmptyValueType()
[Fact]
public void ShouldReturnTrueForEmptyReferenceType()
{
var _QueryStringCollection = new QueryStringCollection(
new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty")
);

string output;
var result = _QueryStringCollection.TryGetAndConvert<string>("empty", out output);

Expand All @@ -130,6 +151,10 @@ public void ShouldReturnTrueForEmptyReferenceType()
[Fact]
public void ShouldReturnTrueForEmptyNullableType()
{
var _QueryStringCollection = new QueryStringCollection(
new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty")
);

bool? output;
var result = _QueryStringCollection.TryGetAndConvert<bool?>("empty", out output);

Expand All @@ -138,15 +163,13 @@ public void ShouldReturnTrueForEmptyNullableType()
}
public class Indexer
{
QueryStringCollection _QueryStringCollection;
public Indexer()
{
_QueryStringCollection = new QueryStringCollection(new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty"));
}

[Fact]
public void ShouldReturnNullForNonExistantEntry()
{
var _QueryStringCollection = new QueryStringCollection(
new Uri("http://example.com?intvalue=1&stringvalue=str&boolvalue=true&empty")
);

Assert.Null(_QueryStringCollection["nonexistant"]);
}
}
Expand Down

0 comments on commit 59175e6

Please sign in to comment.