diff --git a/src/Fizzler.Tests/ElementSelector.cs b/src/Fizzler.Tests/ElementSelector.cs index 5680247..9e161b3 100644 --- a/src/Fizzler.Tests/ElementSelector.cs +++ b/src/Fizzler.Tests/ElementSelector.cs @@ -89,10 +89,10 @@ public void Basic_Positive_Precedence_Within_Form() Assert.AreEqual(1, SelectList("form input").Count); } - [Test,ExpectedException(typeof(FormatException))] + [Test] public void Type_Star() { - SelectList("a*"); + Assert.Throws(() => SelectList("a*")); } } } \ No newline at end of file diff --git a/src/Fizzler.Tests/Fizzler.Tests.csproj b/src/Fizzler.Tests/Fizzler.Tests.csproj index 4319244..76fa46e 100644 --- a/src/Fizzler.Tests/Fizzler.Tests.csproj +++ b/src/Fizzler.Tests/Fizzler.Tests.csproj @@ -39,7 +39,7 @@ - + 3.5 diff --git a/src/Fizzler.Tests/HumanReadableSelectorGeneratorTests.cs b/src/Fizzler.Tests/HumanReadableSelectorGeneratorTests.cs index d737fd6..a8e9560 100644 --- a/src/Fizzler.Tests/HumanReadableSelectorGeneratorTests.cs +++ b/src/Fizzler.Tests/HumanReadableSelectorGeneratorTests.cs @@ -35,11 +35,12 @@ public class TestHumanReadableSelectorGenerator : HumanReadableSelectorGenerator } } - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void Null_Selector() { var generator = new TestHumanReadableSelectorGenerator(); - generator.Add(null); + var e = Assert.Throws(() => generator.Add(null)); + Assert.That(e.ParamName, Is.EqualTo("selector")); } [Test] diff --git a/src/Fizzler.Tests/ReaderTests.cs b/src/Fizzler.Tests/ReaderTests.cs index 27793d1..746d68c 100644 --- a/src/Fizzler.Tests/ReaderTests.cs +++ b/src/Fizzler.Tests/ReaderTests.cs @@ -33,16 +33,20 @@ namespace Fizzler.Tests [TestFixture] public class ReaderTests { - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void NullEnumeratorInitialization() { - new Reader((IEnumerator)null); + var e = Assert.Throws(() => + new Reader((IEnumerator)null)); + Assert.That(e.ParamName, Is.EqualTo("e")); } - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void NullEnumerableInitialization() { - new Reader((IEnumerable)null); + var e = Assert.Throws(() => + new Reader((IEnumerable)null)); + Assert.That(e.ParamName, Is.EqualTo("e")); } [Test] @@ -57,10 +61,11 @@ public void HasMoreWhenNotEmpty() Assert.IsTrue(new Reader(new int[1]).HasMore); } - [Test, ExpectedException(typeof(InvalidOperationException))] + [Test] public void ReadEmpty() { - new Reader(new int[0]).Read(); + Assert.Throws(() => + new Reader(new int[0]).Read()); } [Test] @@ -77,10 +82,11 @@ public void Unreading() Assert.AreEqual(910, reader.Read()); } - [Test, ExpectedException(typeof(InvalidOperationException))] + [Test] public void PeekEmpty() { - new Reader(new int[0]).Peek(); + Assert.Throws(() => + new Reader(new int[0]).Peek()); } [Test] @@ -151,34 +157,46 @@ public void DisposeDisposesOnce() Assert.AreEqual(1, e.DisposeCallCount); } - [Test, ExpectedException(typeof(ObjectDisposedException))] + [Test] public void HasMoreDisposed() { - var unused = CreateDisposedReader().HasMore; + var e = Assert.Throws(() => + { + var unused = CreateDisposedReader().HasMore; + }); + Assert.That(e.ObjectName, Is.EqualTo(typeof(Reader<>).Name)); } - [Test, ExpectedException(typeof(ObjectDisposedException))] + [Test] public void ReadDisposed() { - CreateDisposedReader().Read(); + var e = Assert.Throws(() => + CreateDisposedReader().Read()); + Assert.That(e.ObjectName, Is.EqualTo(typeof(Reader<>).Name)); } - [Test, ExpectedException(typeof(ObjectDisposedException))] + [Test] public void UnreadDisposed() { - CreateDisposedReader().Unread(42); + var e = Assert.Throws(() => + CreateDisposedReader().Unread(42)); + Assert.That(e.ObjectName, Is.EqualTo(typeof(Reader<>).Name)); } - [Test, ExpectedException(typeof(ObjectDisposedException))] + [Test] public void PeekDisposed() { - CreateDisposedReader().Peek(); + var e = Assert.Throws(() => + CreateDisposedReader().Peek()); + Assert.That(e.ObjectName, Is.EqualTo(typeof(Reader<>).Name)); } - [Test, ExpectedException(typeof(ObjectDisposedException))] + [Test] public void EnumerateDisposed() { - CreateDisposedReader().GetEnumerator(); + var e = Assert.Throws(() => + CreateDisposedReader().GetEnumerator()); + Assert.That(e.ObjectName, Is.EqualTo(typeof(Reader<>).Name)); } private static Reader CreateDisposedReader() diff --git a/src/Fizzler.Tests/SelectorGeneratorTeeTests.cs b/src/Fizzler.Tests/SelectorGeneratorTeeTests.cs index 997725d..349ca22 100644 --- a/src/Fizzler.Tests/SelectorGeneratorTeeTests.cs +++ b/src/Fizzler.Tests/SelectorGeneratorTeeTests.cs @@ -50,20 +50,20 @@ public void Setup() tee = new SelectorGeneratorTee(primary, secondary); } - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void NullPrimary() { - new SelectorGeneratorTee( - null, new FakeSelectorGenerator() - ); + var e = Assert.Throws(() => + new SelectorGeneratorTee(null, new FakeSelectorGenerator())); + Assert.That(e.ParamName, Is.EqualTo("primary")); } - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void NullSecondary() { - new SelectorGeneratorTee( - new FakeSelectorGenerator(), null - ); + var e = Assert.Throws(() => + new SelectorGeneratorTee(new FakeSelectorGenerator(), null)); + Assert.That(e.ParamName, Is.EqualTo("secondary")); } [Test] diff --git a/src/Fizzler.Tests/TokenTests.cs b/src/Fizzler.Tests/TokenTests.cs index c433786..cb39d8e 100644 --- a/src/Fizzler.Tests/TokenTests.cs +++ b/src/Fizzler.Tests/TokenTests.cs @@ -124,16 +124,18 @@ public void Ident() AssertToken(TokenKind.Ident, "foo", Token.Ident("foo")); } - [Test,ExpectedException(typeof(ArgumentNullException))] + [Test] public void IdentNullText() { - Token.Ident(null); + var e = Assert.Throws(() => Token.Ident(null)); + Assert.That(e.ParamName, Is.EqualTo("text")); } - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void IdentEmptyText() { - Token.Ident(string.Empty); + var e = Assert.Throws(() => Token.Ident(string.Empty)); + Assert.That(e.ParamName, Is.EqualTo("text")); } [Test] @@ -142,16 +144,18 @@ public void Hash() AssertToken(TokenKind.Hash, "foo", Token.Hash("foo")); } - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void HashNullText() { - Token.Hash(null); + var e = Assert.Throws(() => Token.Hash(null)); + Assert.That(e.ParamName, Is.EqualTo("text")); } - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void HashEmptyText() { - Token.Hash(string.Empty); + var e = Assert.Throws(() => Token.Hash(string.Empty)); + Assert.That(e.ParamName, Is.EqualTo("text")); } [Test] @@ -177,16 +181,18 @@ public void Function() AssertToken(TokenKind.Function, "foo", Token.Function("foo")); } - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void FunctionNullText() { - Token.Function(null); + var e = Assert.Throws(() => Token.Function(null)); + Assert.That(e.ParamName, Is.EqualTo("text")); } - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void FunctionEmptyText() { - Token.Function(string.Empty); + var e = Assert.Throws(() => Token.Function(string.Empty)); + Assert.That(e.ParamName, Is.EqualTo("text")); } public void WhiteSpace() @@ -194,16 +200,16 @@ public void WhiteSpace() AssertToken(TokenKind.WhiteSpace, " \n ", Token.WhiteSpace("foo")); } - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void WhiteSpaceNullText() { - Token.WhiteSpace(null); + Assert.Throws(() => Token.WhiteSpace(null)); } - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void WhiteSpaceEmptyText() { - Token.WhiteSpace(string.Empty); + Assert.Throws(() => Token.WhiteSpace(string.Empty)); } public void Integer() @@ -211,16 +217,18 @@ public void Integer() AssertToken(TokenKind.Integer, "123", Token.Integer("123")); } - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void IntegerNullText() { - Token.Integer(null); + var e = Assert.Throws(() => Token.Integer(null)); + Assert.That(e.ParamName, Is.EqualTo("text")); } - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void IntegerEmptyText() { - Token.Integer(string.Empty); + var e = Assert.Throws(() => Token.Integer(string.Empty)); + Assert.That(e.ParamName, Is.EqualTo("text")); } private static void AssertToken(TokenKind kindExpected, Token token) diff --git a/src/Fizzler.Tests/TokenerTests.cs b/src/Fizzler.Tests/TokenerTests.cs index 668cc8e..9b6066f 100644 --- a/src/Fizzler.Tests/TokenerTests.cs +++ b/src/Fizzler.Tests/TokenerTests.cs @@ -153,10 +153,11 @@ public void IdentifierUsingVendorExtensionSyntax() Assert.AreEqual(Token.Ident("-foo-BAR-42"), Tokener.Tokenize("-foo-BAR-42").First()); } - [Test, ExpectedException(typeof(FormatException))] + [Test] public void IdentifierUsingVendorExtensionSyntaxCannotBeginWithDigit() { - Tokener.Tokenize("-42").ToArray(); + Assert.Throws(() => + Tokener.Tokenize("-42").ToArray()); } [Test] @@ -236,10 +237,11 @@ public void BracketedIdent() Assert.IsFalse(token.MoveNext()); } - [Test, ExpectedException(typeof(FormatException))] + [Test] public void BadHash() { - Tokener.Tokenize("#").ToArray(); + Assert.Throws(() => + Tokener.Tokenize("#").ToArray()); } [Test] @@ -316,28 +318,33 @@ public void TildeWhitespacePrepended() Assert.AreEqual(TokenKind.Tilde, Tokener.Tokenize(" ~").First().Kind); } - [Test,ExpectedException(typeof(FormatException))] + [Test] public void StringSingleQuoteUnterminated() { - Tokener.Tokenize("'foo").ToArray(); + Assert.Throws(() => + Tokener.Tokenize("'foo").ToArray()); } - [Test, ExpectedException(typeof(FormatException))] + [Test] public void StringDoubleQuoteUnterminated() { - Tokener.Tokenize("\"foo").ToArray(); + Assert.Throws(() => + Tokener.Tokenize("\"foo").ToArray()); } - [Test, ExpectedException(typeof(FormatException))] + [Test] public void StringInvalidEscaping() { - Tokener.Tokenize(@"'f\oo").ToArray(); + Assert.Throws(() => + Tokener.Tokenize(@"'f\oo").ToArray()); } - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void NullReader() { - Tokener.Tokenize((TextReader) null); + var e = Assert.Throws(() => + Tokener.Tokenize((TextReader) null)); + Assert.That(e.ParamName, Is.EqualTo("reader")); } [Test] @@ -347,10 +354,11 @@ public void StringReader() Tokener.Tokenize(new StringReader("123,*")).ToArray()); } - [Test, ExpectedException(typeof(FormatException))] + [Test] public void InvalidChar() { - Tokener.Tokenize("what?").ToArray(); + Assert.Throws(() => + Tokener.Tokenize("what?").ToArray()); } } } \ No newline at end of file