Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed May 10, 2023
1 parent 6a1af9e commit 5b14086
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ public static void Ctor_String(string name)

[Theory]
[InlineData(null)]
public static void Ctor_String_NullName_ThrowsArgumentException(string name)
{
AssertExtensions.Throws<ArgumentNullException>("name", null, () => new ColumnAttribute(name));
}

[Theory]
[InlineData("")]
[InlineData(" \t\r\n")]
public static void Ctor_String_NullOrWhitespaceName_ThrowsArgumentException(string name)
public static void Ctor_String_WhitespaceName_ThrowsArgumentException(string name)
{
AssertExtensions.Throws<ArgumentException>("name", null, () => new ColumnAttribute(name));
}
Expand Down Expand Up @@ -61,9 +67,16 @@ public static void TypeName_Set_ReturnsExpected(string value)

[Theory]
[InlineData(null)]
public static void TypeName_Set_NullValue_ThrowsArgumentException(string value)
{
ColumnAttribute attribute = new ColumnAttribute();
AssertExtensions.Throws<ArgumentNullException>("value", null, () => attribute.TypeName = value);
}

[Theory]
[InlineData("")]
[InlineData(" \t\r\n")]
public static void TypeName_Set_NullOrWhitespaceValue_ThrowsArgumentException(string value)
public static void TypeName_Set_WhitespaceValue_ThrowsArgumentException(string value)
{
ColumnAttribute attribute = new ColumnAttribute();
AssertExtensions.Throws<ArgumentException>("value", null, () => attribute.TypeName = value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ public static void Ctor_String(string name)

[Theory]
[InlineData(null)]
public static void Ctor_String_NullName_ThrowsArgumentException(string name)
{
AssertExtensions.Throws<ArgumentNullException>("name", null, () => new ForeignKeyAttribute(name));
}

[Theory]
[InlineData("")]
[InlineData(" \t\r\n")]
public static void Ctor_String_NullOrWhitespaceName_ThrowsArgumentException(string name)
public static void Ctor_String_WhitespaceName_ThrowsArgumentException(string name)
{
AssertExtensions.Throws<ArgumentException>("name", null, () => new ForeignKeyAttribute(name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ public static void Ctor_String(string property)

[Theory]
[InlineData(null)]
public static void Ctor_String_NullProperty_ThrowsArgumentException(string property)
{
AssertExtensions.Throws<ArgumentNullException>("property", null, () => new InversePropertyAttribute(property));
}

[Theory]
[InlineData("")]
[InlineData(" \t\r\n")]
public static void Ctor_String_NullOrWhitespaceProperty_ThrowsArgumentException(string property)
public static void Ctor_String_WhitespaceProperty_ThrowsArgumentException(string property)
{
AssertExtensions.Throws<ArgumentException>("property", null, () => new InversePropertyAttribute(property));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ public static void Ctor_String(string name)

[Theory]
[InlineData(null)]
public static void Ctor_String_NullName_ThrowsArgumentException(string name)
{
AssertExtensions.Throws<ArgumentNullException>("name", null, () => new TableAttribute(name));
}

[Theory]
[InlineData("")]
[InlineData(" \t\r\n")]
public static void Ctor_String_NullOrWhitespaceName_ThrowsArgumentException(string name)
public static void Ctor_String_WhitespaceName_ThrowsArgumentException(string name)
{
AssertExtensions.Throws<ArgumentException>("name", null, () => new TableAttribute(name));
}
Expand All @@ -35,9 +41,16 @@ public static void Schema_Set_ReturnsExpected(string value)

[Theory]
[InlineData(null)]
public static void Schema_Set_NullValue_ThrowsArgumentException(string value)
{
TableAttribute attribute = new TableAttribute("Perspicacia Tick");
AssertExtensions.Throws<ArgumentNullException>("value", null, () => attribute.Schema = value);
}

[Theory]
[InlineData("")]
[InlineData(" \t\r\n")]
public static void Schema_Set_NullOrWhitespaceValue_ThrowsArgumentException(string value)
public static void Schema_Set_WhitespaceValue_ThrowsArgumentException(string value)
{
TableAttribute attribute = new TableAttribute("Perspicacia Tick");
AssertExtensions.Throws<ArgumentException>("value", null, () => attribute.Schema = value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Ctor_ValidMethodToken_Success()
[Fact]
public void Ctor_NullMethod_Exception()
{
AssertExtensions.Throws<ArgumentException>("method", () => { new HttpMethod(null); } );
AssertExtensions.Throws<ArgumentNullException>("method", () => { new HttpMethod(null); } );
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public class MultipartContentTest
[Fact]
public void Ctor_NullOrEmptySubType_ThrowsArgumentException()
{
AssertExtensions.Throws<ArgumentException>("subtype", () => new MultipartContent(null));
AssertExtensions.Throws<ArgumentNullException>("subtype", () => new MultipartContent(null));
AssertExtensions.Throws<ArgumentException>("subtype", () => new MultipartContent(""));
AssertExtensions.Throws<ArgumentException>("subtype", () => new MultipartContent(" "));
}

[Fact]
public void Ctor_NullOrEmptyBoundary_ThrowsArgumentException()
{
AssertExtensions.Throws<ArgumentException>("boundary", () => new MultipartContent("Some", null));
AssertExtensions.Throws<ArgumentNullException>("boundary", () => new MultipartContent("Some", null));
AssertExtensions.Throws<ArgumentException>("boundary", () => new MultipartContent("Some", ""));
AssertExtensions.Throws<ArgumentException>("boundary", () => new MultipartContent("Some", " "));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Ctor_NoParams_CorrectMediaType()
[Fact]
public void Ctor_NullBoundary_ThrowsArgumentException()
{
AssertExtensions.Throws<ArgumentException>("boundary", () => new MultipartFormDataContent(null));
AssertExtensions.Throws<ArgumentNullException>("boundary", () => new MultipartFormDataContent(null));
}

[Fact]
Expand All @@ -42,7 +42,7 @@ public void Add_NullContent_ThrowsArgumentNullException()
public void Add_NullName_ThrowsArgumentException()
{
var content = new MultipartFormDataContent();
AssertExtensions.Throws<ArgumentException>("name", () => content.Add(new StringContent("Hello world"), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => content.Add(new StringContent("Hello world"), null));
}

[Fact]
Expand All @@ -56,7 +56,7 @@ public void Add_EmptyName_ThrowsArgumentException()
public void Add_NullFileName_ThrowsArgumentException()
{
var content = new MultipartFormDataContent();
AssertExtensions.Throws<ArgumentException>("fileName", () => content.Add(new StringContent("Hello world"), "name", null));
AssertExtensions.Throws<ArgumentNullException>("fileName", () => content.Add(new StringContent("Hello world"), "name", null));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Ctor_SetBothSchemeAndParameters_MatchExpectation()
Assert.Equal("Basic", auth.Scheme);
Assert.Equal("realm=\"contoso.com\"", auth.Parameter);

AssertExtensions.Throws<ArgumentException>("scheme", () => { new AuthenticationHeaderValue(null, "x"); });
AssertExtensions.Throws<ArgumentNullException>("scheme", () => { new AuthenticationHeaderValue(null, "x"); });
AssertExtensions.Throws<ArgumentException>("scheme", () => { new AuthenticationHeaderValue("", "x"); });
Assert.Throws<FormatException>(() => { new AuthenticationHeaderValue(" x", "x"); });
Assert.Throws<FormatException>(() => { new AuthenticationHeaderValue("x ", "x"); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public void Properties_SetAndGetAllProperties_SetValueReturnedInGetter()

// String collection properties
Assert.NotNull(cacheControl.NoCacheHeaders);
AssertExtensions.Throws<ArgumentException>("item", () => { cacheControl.NoCacheHeaders.Add(null); });
AssertExtensions.Throws<ArgumentNullException>("item", () => { cacheControl.NoCacheHeaders.Add(null); });
Assert.Throws<FormatException>(() => { cacheControl.NoCacheHeaders.Add("invalid token"); });
cacheControl.NoCacheHeaders.Add("token");
Assert.Equal(1, cacheControl.NoCacheHeaders.Count);
Assert.Equal("token", cacheControl.NoCacheHeaders.First());

Assert.NotNull(cacheControl.PrivateHeaders);
AssertExtensions.Throws<ArgumentException>("item", () => { cacheControl.PrivateHeaders.Add(null); });
AssertExtensions.Throws<ArgumentNullException>("item", () => { cacheControl.PrivateHeaders.Add(null); });
Assert.Throws<FormatException>(() => { cacheControl.PrivateHeaders.Add("invalid token"); });
cacheControl.PrivateHeaders.Add("token");
Assert.Equal(1, cacheControl.PrivateHeaders.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ContentDispositionHeaderValueTest
[Fact]
public void Ctor_ContentDispositionNull_Throw()
{
AssertExtensions.Throws<ArgumentException>("dispositionType", () => { new ContentDispositionHeaderValue(null); });
AssertExtensions.Throws<ArgumentNullException>("dispositionType", () => { new ContentDispositionHeaderValue(null); });
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void Unit_GetAndSetValidAndInvalidValues_MatchExpectation()
range.Unit = "myunit";
Assert.Equal("myunit", range.Unit); // "Unit (custom value)"

AssertExtensions.Throws<ArgumentException>("value", () => { range.Unit = null; }); // "<null>"
AssertExtensions.Throws<ArgumentNullException>("value", () => { range.Unit = null; }); // "<null>"
AssertExtensions.Throws<ArgumentException>("value", () => { range.Unit = ""; }); // "empty string"
Assert.Throws<FormatException>(() => { range.Unit = " x"; }); // "leading space"
Assert.Throws<FormatException>(() => { range.Unit = "x "; }); // "trailing space"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class EntityTagHeaderValueTest
[Fact]
public void Ctor_ETagNull_Throw()
{
AssertExtensions.Throws<ArgumentException>("tag", () => { new EntityTagHeaderValue(null); });
AssertExtensions.Throws<ArgumentNullException>("tag", () => { new EntityTagHeaderValue(null); });
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void CheckValidQuotedString_ValidAndInvalidvalues_MatchExpectation()
HeaderUtilities.CheckValidQuotedString("\"x\"", "param");
HeaderUtilities.CheckValidQuotedString("\"x y\"", "param");

AssertExtensions.Throws<ArgumentException>("param", () => { HeaderUtilities.CheckValidQuotedString(null, "param"); });
AssertExtensions.Throws<ArgumentNullException>("param", () => { HeaderUtilities.CheckValidQuotedString(null, "param"); });
AssertExtensions.Throws<ArgumentException>("param", () => { HeaderUtilities.CheckValidQuotedString("", "param"); });
Assert.Throws<FormatException>(() => { HeaderUtilities.CheckValidQuotedString("\"x", "param"); });
Assert.Throws<FormatException>(() => { HeaderUtilities.CheckValidQuotedString("\"x\"y", "param"); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,17 @@ public void TryAddWithoutValidation_MultipleAddNullValueCollection_Throws()

[Theory]
[InlineData(null)]
public void Add_SingleUseNullHeaderName_Throw(string headerName)
{
MockHeaders headers = new MockHeaders();

AssertExtensions.Throws<ArgumentNullException>("name", () => { headers.Add(headerName, "value"); });
}

[Theory]
[InlineData("")]
public void Add_SingleUseEmptyHeaderName_Throw(string headerName)
[InlineData(" \t\r\n ")]
public void Add_SingleUseWhiteSpaceHeaderName_Throw(string headerName)
{
MockHeaders headers = new MockHeaders();

Expand Down Expand Up @@ -1064,8 +1073,17 @@ public void Clear_AddMultipleHeadersAndThenClear_NoHeadersInCollection()

[Theory]
[InlineData(null)]
public void Remove_UseNullHeaderName_Throw(string headerName)
{
MockHeaders headers = new MockHeaders();

AssertExtensions.Throws<ArgumentNullException>("name", () => { headers.Remove(headerName); });
}

[Theory]
[InlineData("")]
public void Remove_UseEmptyHeaderName_Throw(string headerName)
[InlineData(" \t\r\n ")]
public void Remove_UseWhiteSpaceHeaderName_Throw(string headerName)
{
MockHeaders headers = new MockHeaders();

Expand Down Expand Up @@ -1211,8 +1229,17 @@ public void TryGetValues_GetValuesForExistingHeader_ReturnsTrueAndListOfValues()

[Theory]
[InlineData(null)]
public void GetValues_UseNullHeaderName_Throw(string headerName)
{
MockHeaders headers = new MockHeaders();

AssertExtensions.Throws<ArgumentNullException>("name", () => { headers.GetValues(headerName); });
}

[Theory]
[InlineData("")]
public void GetValues_UseEmptyHeaderName_Throw(string headerName)
[InlineData(" \t\r\n ")]
public void GetValues_UseWhiteSpaceHeaderName_Throw(string headerName)
{
MockHeaders headers = new MockHeaders();

Expand Down Expand Up @@ -1576,7 +1603,16 @@ public void NonValidated_ValidInvalidAndRaw_AllReturned()

[Theory]
[InlineData(null)]
public void Contains_UseNullHeaderName_Throw(string headerName)
{
MockHeaders headers = new MockHeaders();

AssertExtensions.Throws<ArgumentNullException>("name", () => { headers.Contains(headerName); });
}

[Theory]
[InlineData("")]
[InlineData(" \t\r\n ")]
public void Contains_UseEmptyHeaderName_Throw(string headerName)
{
MockHeaders headers = new MockHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MediaTypeHeaderValueTest
[Fact]
public void Ctor_MediaTypeNull_Throw()
{
AssertExtensions.Throws<ArgumentException>("mediaType", () => { new MediaTypeHeaderValue(null); });
AssertExtensions.Throws<ArgumentNullException>("mediaType", () => { new MediaTypeHeaderValue(null); });
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NameValueHeaderValueTest
[Fact]
public void Ctor_NameNull_Throw()
{
AssertExtensions.Throws<ArgumentException>("name", () => { NameValueHeaderValue nameValue = new NameValueHeaderValue((string)null); });
AssertExtensions.Throws<ArgumentNullException>("name", () => { NameValueHeaderValue nameValue = new NameValueHeaderValue((string)null); });
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class NameValueWithParametersHeaderValueTest
[Fact]
public void Ctor_NameNull_Throw()
{
AssertExtensions.Throws<ArgumentException>("name", () => { NameValueWithParametersHeaderValue nameValue = new NameValueWithParametersHeaderValue(null); });
AssertExtensions.Throws<ArgumentNullException>("name", () => { NameValueWithParametersHeaderValue nameValue = new NameValueWithParametersHeaderValue(null); });
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Ctor_SetValidHeaderValues_InstanceCreatedCorrectly()
[Fact]
public void Ctor_UseInvalidValues_Throw()
{
AssertExtensions.Throws<ArgumentException>("name", () => { new ProductHeaderValue(null); });
AssertExtensions.Throws<ArgumentNullException>("name", () => { new ProductHeaderValue(null); });
AssertExtensions.Throws<ArgumentException>("name", () => { new ProductHeaderValue(string.Empty); });
Assert.Throws<FormatException>(() => { new ProductHeaderValue(" x"); });
Assert.Throws<FormatException>(() => { new ProductHeaderValue("x "); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Ctor_CommentOverload_MatchExpectation()
Assert.Null(productInfo.Product);
Assert.Equal("(this is a comment)", productInfo.Comment);

AssertExtensions.Throws<ArgumentException>("comment", () => { new ProductInfoHeaderValue((string)null); });
AssertExtensions.Throws<ArgumentNullException>("comment", () => { new ProductInfoHeaderValue((string)null); });
Assert.Throws<FormatException>(() => { new ProductInfoHeaderValue("invalid comment"); });
Assert.Throws<FormatException>(() => { new ProductInfoHeaderValue(" (leading space)"); });
Assert.Throws<FormatException>(() => { new ProductInfoHeaderValue("(trailing space) "); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Ctor_EntityTagStringOverload_MatchExpectation()
Assert.Equal(new EntityTagHeaderValue("\"y\""), rangeCondition.EntityTag);
Assert.Null(rangeCondition.Date);

AssertExtensions.Throws<ArgumentException>("tag", () => { new RangeConditionHeaderValue((string)null); });
AssertExtensions.Throws<ArgumentNullException>("tag", () => { new RangeConditionHeaderValue((string)null); });
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Unit_GetAndSetValidAndInvalidValues_MatchExpectation()
range.Unit = "myunit";
Assert.Equal("myunit", range.Unit);

AssertExtensions.Throws<ArgumentException>("value", () => { range.Unit = null; });
AssertExtensions.Throws<ArgumentNullException>("value", () => { range.Unit = null; });
AssertExtensions.Throws<ArgumentException>("value", () => { range.Unit = ""; });
Assert.Throws<FormatException>(() => { range.Unit = " x"; });
Assert.Throws<FormatException>(() => { range.Unit = "x "; });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Ctor_StringOnlyOverload_MatchExpectation()
Assert.Equal("token", value.Value);
Assert.Null(value.Quality);

AssertExtensions.Throws<ArgumentException>("value", () => { new StringWithQualityHeaderValue(null); });
AssertExtensions.Throws<ArgumentNullException>("value", () => { new StringWithQualityHeaderValue(null); });
AssertExtensions.Throws<ArgumentException>("value", () => { new StringWithQualityHeaderValue(""); });
Assert.Throws<FormatException>(() => { new StringWithQualityHeaderValue("in valid"); });
}
Expand All @@ -28,7 +28,7 @@ public void Ctor_StringWithQualityOverload_MatchExpectation()
Assert.Equal("token", value.Value);
Assert.Equal(0.5, value.Quality);

AssertExtensions.Throws<ArgumentException>("value", () => { new StringWithQualityHeaderValue(null, 0.1); });
AssertExtensions.Throws<ArgumentNullException>("value", () => { new StringWithQualityHeaderValue(null, 0.1); });
AssertExtensions.Throws<ArgumentException>("value", () => { new StringWithQualityHeaderValue("", 0.1); });
Assert.Throws<FormatException>(() => { new StringWithQualityHeaderValue("in valid", 0.1); });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TransferCodingHeaderValueTest
[Fact]
public void Ctor_ValueNull_Throw()
{
AssertExtensions.Throws<ArgumentException>("value", () => { new TransferCodingHeaderValue(null); });
AssertExtensions.Throws<ArgumentNullException>("value", () => { new TransferCodingHeaderValue(null); });
}

[Fact]
Expand Down
Loading

0 comments on commit 5b14086

Please sign in to comment.