From abed94e86dea4d9cf62b4059968ad6d27b9f7b14 Mon Sep 17 00:00:00 2001 From: "Frackiewicz, Fillip" Date: Wed, 20 May 2020 04:35:44 +0200 Subject: [PATCH 01/11] RMLNQ-129 Rider wants semicolon removed --- Development/UnitTesting/Sandboxing/TestResult.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Development/UnitTesting/Sandboxing/TestResult.cs b/Development/UnitTesting/Sandboxing/TestResult.cs index d0e7d9d1a..45a5d9cd1 100644 --- a/Development/UnitTesting/Sandboxing/TestResult.cs +++ b/Development/UnitTesting/Sandboxing/TestResult.cs @@ -23,7 +23,7 @@ namespace Remotion.Linq.Development.UnitTesting.Sandboxing { - public enum SandboxTestStatus { Succeeded, Ignored, Failed, FailedInSetUp, FailedInTearDown }; + public enum SandboxTestStatus { Succeeded, Ignored, Failed, FailedInSetUp, FailedInTearDown } /// /// represents a single result for a test method. From d39f00a22339df6b70c6046e243546336490b952 Mon Sep 17 00:00:00 2001 From: "Frackiewicz, Fillip" Date: Wed, 20 May 2020 04:56:39 +0200 Subject: [PATCH 02/11] RMLNQ-129 Features=ExpectedException --- .../Development.Net_3_5.UnitTests.csproj | 5 +- Development.Net_3_5.UnitTests/packages.config | 2 +- .../Development.Net_4_0.UnitTests.csproj | 5 +- Development.Net_4_0.UnitTests/packages.config | 2 +- .../Development.UnitTests.csproj | 5 +- Development.UnitTests/packages.config | 2 +- .../ExpressionVisitorTest.cs | 32 +-- UnitTests.Net_3_5/UnitTests.Net_3_5.csproj | 5 +- UnitTests.Net_3_5/packages.config | 2 +- UnitTests.Net_4_0/UnitTests.Net_4_0.csproj | 5 +- UnitTests.Net_4_0/packages.config | 2 +- UnitTests.Net_4_5/UnitTests.Net_4_5.csproj | 5 +- UnitTests.Net_4_5/packages.config | 2 +- .../AccessorFindingExpressionVisitorTest.cs | 49 +++-- ...ReferenceReplacingExpressionVisitorTest.cs | 15 +- .../ReverseResolvingExpressionVisitorTest.cs | 24 +- UnitTests/Clauses/GroupJoinClauseTest.cs | 8 +- UnitTests/Clauses/OrderByClauseTest.cs | 10 +- UnitTests/Clauses/QuerySourceMappingTest.cs | 30 ++- .../AggregateFromSeedResultOperatorTest.cs | 103 +++++---- .../AggregateResultOperatorTest.cs | 47 ++-- .../ResultOperators/AllResultOperatorTest.cs | 12 +- .../ResultOperators/AnyResultOperatorTest.cs | 12 +- .../AverageResultOperatorTest.cs | 19 +- .../ResultOperators/CastResultOperatorTest.cs | 12 +- .../ChoiceResultOperatorBaseTest.cs | 12 +- .../ConcatResultOperatorTest.cs | 20 +- .../ContainsResultOperatorTest.cs | 38 ++-- .../CountResultOperatorTest.cs | 12 +- .../DefaultIfEmptyResultOperatorTest.cs | 8 +- .../FirstResultOperatorTest.cs | 6 +- .../GroupResultOperatorTest.cs | 12 +- .../ResultOperators/LastResultOperatorTest.cs | 6 +- .../LongCountResultOperatorTest.cs | 12 +- .../OfTypeResultOperatorTest.cs | 12 +- ...nceTypePreservingResultOperatorBaseTest.cs | 12 +- .../SingleResultOperatorTest.cs | 13 +- .../ResultOperators/SkipResultOperatorTest.cs | 13 +- .../ResultOperators/SumResultOperatorTest.cs | 19 +- .../ResultOperators/TakeResultOperatorTest.cs | 13 +- .../UnionResultOperatorTest.cs | 20 +- .../StreamedScalarValueInfoTest.cs | 7 +- .../StreamedData/StreamedSequenceInfoTest.cs | 7 +- .../StreamedData/StreamedSequenceTest.cs | 21 +- .../StreamedSingleValueInfoTest.cs | 7 +- .../Clauses/StreamedData/StreamedValueTest.cs | 14 +- ...stantObservableCollectionEnumeratorTest.cs | 10 +- UnitTests/DefaultQueryProviderTest.cs | 42 ++-- .../ExpressionTransformerRegistryTest.cs | 22 +- ...BCompareStringExpressionTransformerTest.cs | 8 +- .../Structure/ExpressionTreeParserTest.cs | 24 +- .../AggregateExpressionNodeTest.cs | 15 +- .../AggregateFromSeedExpressionNodeTest.cs | 22 +- .../AllExpressionNodeTest.cs | 8 +- .../AnyExpressionNodeTest.cs | 8 +- .../AverageExpressionNodeTest.cs | 8 +- .../ClauseGenerationContextTest.cs | 13 +- .../ContainsExpressionNodeTest.cs | 8 +- .../CountExpressionNodeTest.cs | 8 +- .../FirstExpressionNodeTest.cs | 8 +- .../GroupByExpressionNodeTest.cs | 10 +- ...pByWithResultSelectorExpressionNodeTest.cs | 9 +- .../GroupJoinExpressionNodeTest.cs | 9 +- .../JoinExpressionNodeTest.cs | 18 +- .../LastExpressionNodeTest.cs | 8 +- .../LongCountExpressionNodeTest.cs | 8 +- .../MainSourceExpressionNodeTest.cs | 24 +- .../MaxExpressionNodeTest.cs | 8 +- .../MethodCallExpressionNodeFactoryTest.cs | 56 +++-- .../MinExpressionNodeTest.cs | 8 +- .../QuerySourceExpressionNodeUtilityTest.cs | 18 +- .../SelectManyExpressionNodeTest.cs | 9 +- .../SingleExpressionNodeTest.cs | 8 +- .../SumExpressionNodeTest.cs | 8 +- .../ThenByDescendingExpressionNodeTest.cs | 14 +- .../ThenByExpressionNodeTest.cs | 14 +- .../MethodCallExpressionParserTest.cs | 31 +-- ...ateInvocationQueryParserIntegrationTest.cs | 12 +- .../Parsing/ThrowingExpressionVisitorTest.cs | 206 ++++++++++++------ UnitTests/QueryModelBuilderTest.cs | 22 +- UnitTests/QueryModelTest.cs | 33 +-- UnitTests/QueryProviderBaseTest.cs | 8 +- UnitTests/QueryableBaseTest.cs | 10 +- .../SubQueryFromClauseFlattenerTest.cs | 22 +- UnitTests/UnitTests.csproj | 5 +- UnitTests/Utilities/ReflectionUtilityTest.cs | 5 +- UnitTests/packages.config | 2 +- 87 files changed, 897 insertions(+), 591 deletions(-) diff --git a/Development.Net_3_5.UnitTests/Development.Net_3_5.UnitTests.csproj b/Development.Net_3_5.UnitTests/Development.Net_3_5.UnitTests.csproj index f3ffe4da5..190808a04 100644 --- a/Development.Net_3_5.UnitTests/Development.Net_3_5.UnitTests.csproj +++ b/Development.Net_3_5.UnitTests/Development.Net_3_5.UnitTests.csproj @@ -41,8 +41,9 @@ ..\remotion.snk - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + ..\packages\NUnit.2.7.1\lib\nunit.framework.dll + True diff --git a/Development.Net_3_5.UnitTests/packages.config b/Development.Net_3_5.UnitTests/packages.config index 92fc80170..d670be11a 100644 --- a/Development.Net_3_5.UnitTests/packages.config +++ b/Development.Net_3_5.UnitTests/packages.config @@ -1,6 +1,6 @@  - + diff --git a/Development.Net_4_0.UnitTests/Development.Net_4_0.UnitTests.csproj b/Development.Net_4_0.UnitTests/Development.Net_4_0.UnitTests.csproj index 620e2725b..d65e5c8d0 100644 --- a/Development.Net_4_0.UnitTests/Development.Net_4_0.UnitTests.csproj +++ b/Development.Net_4_0.UnitTests/Development.Net_4_0.UnitTests.csproj @@ -40,8 +40,9 @@ ..\remotion.snk - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + ..\packages\NUnit.2.7.1\lib\nunit.framework.dll + True diff --git a/Development.Net_4_0.UnitTests/packages.config b/Development.Net_4_0.UnitTests/packages.config index ad37a5282..1a805bdaa 100644 --- a/Development.Net_4_0.UnitTests/packages.config +++ b/Development.Net_4_0.UnitTests/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/Development.UnitTests/Development.UnitTests.csproj b/Development.UnitTests/Development.UnitTests.csproj index 4ec1feb05..7354c4040 100644 --- a/Development.UnitTests/Development.UnitTests.csproj +++ b/Development.UnitTests/Development.UnitTests.csproj @@ -40,8 +40,9 @@ ..\remotion.snk - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + ..\packages\NUnit.2.7.1\lib\nunit.framework.dll + True diff --git a/Development.UnitTests/packages.config b/Development.UnitTests/packages.config index ad37a5282..1a805bdaa 100644 --- a/Development.UnitTests/packages.config +++ b/Development.UnitTests/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/UnitTests.Net_3_5/Parsing/ExpressionVisitorTests/ExpressionVisitorTest.cs b/UnitTests.Net_3_5/Parsing/ExpressionVisitorTests/ExpressionVisitorTest.cs index a37c08a1e..d52c93a9d 100644 --- a/UnitTests.Net_3_5/Parsing/ExpressionVisitorTests/ExpressionVisitorTest.cs +++ b/UnitTests.Net_3_5/Parsing/ExpressionVisitorTests/ExpressionVisitorTest.cs @@ -233,14 +233,6 @@ public void VisitAndConvert_Single_NewExpression () } [Test] -#if !NET_3_5 - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "When called from 'VisitMethod', rewriting a node of type 'System.Linq.Expressions.BinaryExpression' must return a non-null value of the same type. " - + "Alternatively, override 'VisitMethod' and change it to not visit children of this type.")] -#else - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "When called from 'VisitMethod', expressions of type 'BinaryExpression' can only be replaced with other non-null expressions of type " - + "'BinaryExpression'.")] #endif public void VisitAndConvert_Single_ThrowsOnInvalidType () { @@ -248,27 +240,27 @@ public void VisitAndConvert_Single_ThrowsOnInvalidType () var newExpression = (NewExpression) ExpressionInstanceCreator.GetExpressionInstance (ExpressionType.New); Expect.Call (VisitorMock.Visit (expression)).Return (newExpression); - - InvokeVisitAndConvert (expression, "VisitMethod"); + Assert.That ( + () => InvokeVisitAndConvert (expression, "VisitMethod"), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "When called from 'VisitMethod', expressions of type 'BinaryExpression' can only be replaced with other non-null expressions of type " + + "'BinaryExpression'.")); } [Test] -#if !NET_3_5 - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "When called from 'VisitMethod', rewriting a node of type 'System.Linq.Expressions.BinaryExpression' must return a non-null value of the same type. " - + "Alternatively, override 'VisitMethod' and change it to not visit children of this type.")] -#else - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "When called from 'VisitMethod', expressions of type 'BinaryExpression' can only be replaced with other non-null expressions of type " - + "'BinaryExpression'.")] #endif public void VisitAndConvert_Single_ThrowsOnNull () { var expression = (BinaryExpression) ExpressionInstanceCreator.GetExpressionInstance (ExpressionType.Add); Expect.Call (VisitorMock.Visit (expression)).Return (null); - - InvokeVisitAndConvert (expression, "VisitMethod"); + Assert.That ( + () => InvokeVisitAndConvert (expression, "VisitMethod"), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "When called from 'VisitMethod', expressions of type 'BinaryExpression' can only be replaced with other non-null expressions of type " + + "'BinaryExpression'.")); } [Test] diff --git a/UnitTests.Net_3_5/UnitTests.Net_3_5.csproj b/UnitTests.Net_3_5/UnitTests.Net_3_5.csproj index 8e976ab5a..ec86d3a3d 100644 --- a/UnitTests.Net_3_5/UnitTests.Net_3_5.csproj +++ b/UnitTests.Net_3_5/UnitTests.Net_3_5.csproj @@ -104,8 +104,9 @@ - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + ..\packages\NUnit.2.7.1\lib\nunit.framework.dll + True ..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll diff --git a/UnitTests.Net_3_5/packages.config b/UnitTests.Net_3_5/packages.config index 380a0933c..83a81c518 100644 --- a/UnitTests.Net_3_5/packages.config +++ b/UnitTests.Net_3_5/packages.config @@ -1,6 +1,6 @@  - + diff --git a/UnitTests.Net_4_0/UnitTests.Net_4_0.csproj b/UnitTests.Net_4_0/UnitTests.Net_4_0.csproj index 50fcd8286..2bc9affe3 100644 --- a/UnitTests.Net_4_0/UnitTests.Net_4_0.csproj +++ b/UnitTests.Net_4_0/UnitTests.Net_4_0.csproj @@ -105,8 +105,9 @@ - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + ..\packages\NUnit.2.7.1\lib\nunit.framework.dll + True ..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll diff --git a/UnitTests.Net_4_0/packages.config b/UnitTests.Net_4_0/packages.config index 5e7bbeb94..4e798cfd3 100644 --- a/UnitTests.Net_4_0/packages.config +++ b/UnitTests.Net_4_0/packages.config @@ -1,6 +1,6 @@  - + diff --git a/UnitTests.Net_4_5/UnitTests.Net_4_5.csproj b/UnitTests.Net_4_5/UnitTests.Net_4_5.csproj index 6457ff229..f610496de 100644 --- a/UnitTests.Net_4_5/UnitTests.Net_4_5.csproj +++ b/UnitTests.Net_4_5/UnitTests.Net_4_5.csproj @@ -107,8 +107,9 @@ - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + ..\packages\NUnit.2.7.1\lib\nunit.framework.dll + True ..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll diff --git a/UnitTests.Net_4_5/packages.config b/UnitTests.Net_4_5/packages.config index 5e7bbeb94..cb0b8edfb 100644 --- a/UnitTests.Net_4_5/packages.config +++ b/UnitTests.Net_4_5/packages.config @@ -1,6 +1,6 @@  - + diff --git a/UnitTests/Clauses/ExpressionVisitors/AccessorFindingExpressionVisitorTest.cs b/UnitTests/Clauses/ExpressionVisitors/AccessorFindingExpressionVisitorTest.cs index e79060122..3c47b56db 100644 --- a/UnitTests/Clauses/ExpressionVisitors/AccessorFindingExpressionVisitorTest.cs +++ b/UnitTests/Clauses/ExpressionVisitors/AccessorFindingExpressionVisitorTest.cs @@ -228,44 +228,48 @@ public void NestedMemberBindingExpressionWithDerivedType () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = "The given expression 'new AnonymousType() {a = 3, b = 1}' does not contain the " - + "searched expression '0' in a nested NewExpression with member assignments or a MemberBindingExpression.\r\nParameter name: fullExpression")] public void SearchedExpressionNotFound () { var fullExpression = Expression.MemberInit ( Expression.New (_anonymousTypeCtorWithoutArgs), Expression.Bind (_anonymousTypeAProperty, Expression.Constant (3)), Expression.Bind (_anonymousTypeBProperty, Expression.Constant (1))); - - AccessorFindingExpressionVisitor.FindAccessorLambda (_searchedExpression, fullExpression, _simpleInputParameter); + Assert.That ( + () => AccessorFindingExpressionVisitor.FindAccessorLambda (_searchedExpression, fullExpression, _simpleInputParameter), + Throws.ArgumentException + .With.Message.EqualTo ( + "The given expression 'new AnonymousType() {a = 3, b = 1}' does not contain the " + + "searched expression '0' in a nested NewExpression with member assignments or a MemberBindingExpression.\r\nParameter name: fullExpression")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = "The given expression 'new AnonymousType() {a = (0 + 0), b = 1}' does not contain the " - + "searched expression '0' in a nested NewExpression with member assignments or a MemberBindingExpression.\r\nParameter name: fullExpression")] public void SearchedExpressionNotFound_AlthoughInOtherExpression () { var fullExpression = Expression.MemberInit ( Expression.New (_anonymousTypeCtorWithoutArgs), Expression.Bind (_anonymousTypeAProperty, Expression.MakeBinary (ExpressionType.Add, _searchedExpression, _searchedExpression)), Expression.Bind (_anonymousTypeBProperty, Expression.Constant (1))); - - AccessorFindingExpressionVisitor.FindAccessorLambda (_searchedExpression, fullExpression, _simpleInputParameter); + Assert.That ( + () => AccessorFindingExpressionVisitor.FindAccessorLambda (_searchedExpression, fullExpression, _simpleInputParameter), + Throws.ArgumentException + .With.Message.EqualTo ( + "The given expression 'new AnonymousType() {a = (0 + 0), b = 1}' does not contain the " + + "searched expression '0' in a nested NewExpression with member assignments or a MemberBindingExpression.\r\nParameter name: fullExpression")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = "The given expression 'new AnonymousType(0, 0)' does not contain the " - + "searched expression '0' in a nested NewExpression with member assignments or a MemberBindingExpression.\r\nParameter name: fullExpression")] public void SearchedExpressionNotFound_AlthoughInNewExpressionWithoutMember () { var fullExpression = Expression.New (_anonymousTypeCtorWithArgs, _searchedExpression, _searchedExpression); - - AccessorFindingExpressionVisitor.FindAccessorLambda (_searchedExpression, fullExpression, _simpleInputParameter); + Assert.That ( + () => AccessorFindingExpressionVisitor.FindAccessorLambda (_searchedExpression, fullExpression, _simpleInputParameter), + Throws.ArgumentException + .With.Message.EqualTo ( + "The given expression 'new AnonymousType(0, 0)' does not contain the " + + "searched expression '0' in a nested NewExpression with member assignments or a MemberBindingExpression.\r\nParameter name: fullExpression")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = "The given expression 'new AnonymousType() {List = {Void Add(Int32)(0)}, b = 1}' does not contain the " - + "searched expression '0' in a nested NewExpression with member assignments or a MemberBindingExpression.\r\nParameter name: fullExpression")] public void SearchedExpressionNotFound_AlthoughInOtherMemberBinding () { var anonymousTypeListProperty = typeof (AnonymousType).GetProperty ("List"); @@ -275,17 +279,24 @@ public void SearchedExpressionNotFound_AlthoughInOtherMemberBinding () Expression.New (_anonymousTypeCtorWithoutArgs), Expression.ListBind (anonymousTypeListProperty, Expression.ElementInit (listAddMethod, _searchedExpression)), Expression.Bind (_anonymousTypeBProperty, Expression.Constant (1))); - - AccessorFindingExpressionVisitor.FindAccessorLambda (_searchedExpression, fullExpression, _simpleInputParameter); + Assert.That ( + () => AccessorFindingExpressionVisitor.FindAccessorLambda (_searchedExpression, fullExpression, _simpleInputParameter), + Throws.ArgumentException + .With.Message.EqualTo ( + "The given expression 'new AnonymousType() {List = {Void Add(Int32)(0)}, b = 1}' does not contain the " + + "searched expression '0' in a nested NewExpression with member assignments or a MemberBindingExpression.\r\nParameter name: fullExpression")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = "The given expression '+0' does not contain the searched expression '0' in a " - + "nested NewExpression with member assignments or a MemberBindingExpression.\r\nParameter name: fullExpression")] public void SearchedExpressionNotFound_AlthoughInUnaryPlusExpression () { var fullExpression = Expression.UnaryPlus (_searchedExpression); - AccessorFindingExpressionVisitor.FindAccessorLambda (_searchedExpression, fullExpression, _intInputParameter); + Assert.That ( + () => AccessorFindingExpressionVisitor.FindAccessorLambda (_searchedExpression, fullExpression, _intInputParameter), + Throws.ArgumentException + .With.Message.EqualTo ( + "The given expression '+0' does not contain the searched expression '0' in a " + + "nested NewExpression with member assignments or a MemberBindingExpression.\r\nParameter name: fullExpression")); } } } diff --git a/UnitTests/Clauses/ExpressionVisitors/ReferenceReplacingExpressionVisitorTest.cs b/UnitTests/Clauses/ExpressionVisitors/ReferenceReplacingExpressionVisitorTest.cs index fcb5d5911..afa08c32d 100644 --- a/UnitTests/Clauses/ExpressionVisitors/ReferenceReplacingExpressionVisitorTest.cs +++ b/UnitTests/Clauses/ExpressionVisitors/ReferenceReplacingExpressionVisitorTest.cs @@ -89,12 +89,13 @@ public void Replaces_SubQueryExpressions_WithCorrectCloneContext () } [Test] - [ExpectedException (typeof (InvalidOperationException))] public void VisitSubQuery_PassesFlagToInner_Throw () { var expression = new SubQueryExpression (ExpressionHelper.CreateQueryModel ()); expression.QueryModel.SelectClause.Selector = new QuerySourceReferenceExpression (expression.QueryModel.MainFromClause); - ReferenceReplacingExpressionVisitor.ReplaceClauseReferences (expression, _querySourceMapping, true); + Assert.That ( + () => ReferenceReplacingExpressionVisitor.ReplaceClauseReferences (expression, _querySourceMapping, true), + Throws.InvalidOperationException); } @@ -127,19 +128,21 @@ public void VisitExtensionExpression_ChildrenAreProcessed () } [Test] - [ExpectedException (typeof (InvalidOperationException))] public void VisitUnmappedReference_Throws () { var expression = new QuerySourceReferenceExpression (ExpressionHelper.CreateMainFromClause_Int ()); - ReferenceReplacingExpressionVisitor.ReplaceClauseReferences (expression, _querySourceMapping, true); + Assert.That ( + () => ReferenceReplacingExpressionVisitor.ReplaceClauseReferences (expression, _querySourceMapping, true), + Throws.InvalidOperationException); } [Test] - [ExpectedException (typeof (InvalidOperationException))] public void VisitUnmappedReference_IgnoreFalse_Throws () { var expression = new QuerySourceReferenceExpression (ExpressionHelper.CreateMainFromClause_Int ()); - ReferenceReplacingExpressionVisitor.ReplaceClauseReferences (expression, _querySourceMapping, true); + Assert.That ( + () => ReferenceReplacingExpressionVisitor.ReplaceClauseReferences (expression, _querySourceMapping, true), + Throws.InvalidOperationException); } [Test] diff --git a/UnitTests/Clauses/ExpressionVisitors/ReverseResolvingExpressionVisitorTest.cs b/UnitTests/Clauses/ExpressionVisitors/ReverseResolvingExpressionVisitorTest.cs index 43070f7af..15a33d4b2 100644 --- a/UnitTests/Clauses/ExpressionVisitors/ReverseResolvingExpressionVisitorTest.cs +++ b/UnitTests/Clauses/ExpressionVisitors/ReverseResolvingExpressionVisitorTest.cs @@ -88,9 +88,6 @@ public void ReverseResolve_TopLevelReferenceExpression () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Cannot create a LambdaExpression that retrieves the value of '[s3]' " - + "from items with a structure of 'new AnonymousType`2(a = [s1], b = [s2])'. The item expression does not contain the value or it is too " - + "complex.")] public void ReverseResolve_NonAccessibleReferenceExpression_Throws () { // itemExpression: new AnonymousType ( a = [s1], b = [s2] ) @@ -99,8 +96,13 @@ public void ReverseResolve_NonAccessibleReferenceExpression_Throws () var fromClause3 = ExpressionHelper.CreateMainFromClause_Int ("s3", typeof (Cook), ExpressionHelper.CreateQueryable()); var resolvedExpression = new QuerySourceReferenceExpression (fromClause3); - - ReverseResolvingExpressionVisitor.ReverseResolve (_itemExpression, resolvedExpression); + Assert.That ( + () => ReverseResolvingExpressionVisitor.ReverseResolve (_itemExpression, resolvedExpression), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Cannot create a LambdaExpression that retrieves the value of '[s3]' " + + "from items with a structure of 'new AnonymousType`2(a = [s1], b = [s2])'. The item expression does not contain the value or it is too " + + "complex.")); } [Test] @@ -136,7 +138,6 @@ public void ReverseResolveLambda () } [Test] - [ExpectedException (typeof (ArgumentOutOfRangeException))] public void ReverseResolveLambda_InvalidPosition_TooBig () { // itemExpression: new AnonymousType ( a = [s1], b = [s2] ) @@ -146,12 +147,12 @@ public void ReverseResolveLambda_InvalidPosition_TooBig () var parameter1 = Expression.Parameter (typeof (int), "x"); var parameter2 = Expression.Parameter (typeof (string), "y"); var resolvedExpression = Expression.Lambda (Expression.Constant (0), parameter1, parameter2); - - ReverseResolvingExpressionVisitor.ReverseResolveLambda (_itemExpression, resolvedExpression, 3); + Assert.That ( + () => ReverseResolvingExpressionVisitor.ReverseResolveLambda (_itemExpression, resolvedExpression, 3), + Throws.InstanceOf()); } [Test] - [ExpectedException (typeof (ArgumentOutOfRangeException))] public void ReverseResolveLambda_InvalidPosition_TooSmall () { // itemExpression: new AnonymousType ( a = [s1], b = [s2] ) @@ -161,8 +162,9 @@ public void ReverseResolveLambda_InvalidPosition_TooSmall () var parameter1 = Expression.Parameter (typeof (int), "x"); var parameter2 = Expression.Parameter (typeof (string), "y"); var resolvedExpression = Expression.Lambda (Expression.Constant (0), parameter1, parameter2); - - ReverseResolvingExpressionVisitor.ReverseResolveLambda (_itemExpression, resolvedExpression, -1); + Assert.That ( + () => ReverseResolvingExpressionVisitor.ReverseResolveLambda (_itemExpression, resolvedExpression, -1), + Throws.InstanceOf()); } } } diff --git a/UnitTests/Clauses/GroupJoinClauseTest.cs b/UnitTests/Clauses/GroupJoinClauseTest.cs index dd76354c7..6db5a5eca 100644 --- a/UnitTests/Clauses/GroupJoinClauseTest.cs +++ b/UnitTests/Clauses/GroupJoinClauseTest.cs @@ -52,11 +52,13 @@ public void Intialize () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Expected a closed generic type implementing IEnumerable, but found 'Remotion.Linq.UnitTests.TestDomain.Cook'.\r\nParameter name: value")] public void Intialize_WithNonEnumerableType_Throws () { - new GroupJoinClause ("x", typeof (Cook), _joinClause); + Assert.That ( + () => new GroupJoinClause ("x", typeof (Cook), _joinClause), + Throws.ArgumentException + .With.Message.EqualTo ( + "Expected a closed generic type implementing IEnumerable, but found 'Remotion.Linq.UnitTests.TestDomain.Cook'.\r\nParameter name: value")); } [Test] diff --git a/UnitTests/Clauses/OrderByClauseTest.cs b/UnitTests/Clauses/OrderByClauseTest.cs index 7914ab109..b7d7727a2 100644 --- a/UnitTests/Clauses/OrderByClauseTest.cs +++ b/UnitTests/Clauses/OrderByClauseTest.cs @@ -58,19 +58,21 @@ public void AddOrderings() } [Test] - [ExpectedException(typeof(ArgumentNullException))] public void AddOrderings_Null_ThrowsArgumentNullException () { - _orderByClause.Orderings.Add (null); + Assert.That ( + () => _orderByClause.Orderings.Add (null), + Throws.ArgumentNullException); } [Test] - [ExpectedException (typeof (ArgumentNullException))] public void ChangeOrdering_WithNull_ThrowsArgumentNullException () { Ordering ordering1 = ExpressionHelper.CreateOrdering (); _orderByClause.Orderings.Add (ordering1); - _orderByClause.Orderings[0] = null; + Assert.That ( + () => _orderByClause.Orderings[0] = null, + Throws.ArgumentNullException); } [Test] diff --git a/UnitTests/Clauses/QuerySourceMappingTest.cs b/UnitTests/Clauses/QuerySourceMappingTest.cs index dcce70c42..3a7987c52 100644 --- a/UnitTests/Clauses/QuerySourceMappingTest.cs +++ b/UnitTests/Clauses/QuerySourceMappingTest.cs @@ -56,12 +56,13 @@ public void AddMapping () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "Query source (from Int32 main in TestQueryable()) has already been associated with an expression.")] public void AddMapping_Twice () { _mapping.AddMapping (_clause1, _querySourceReferenceExpression1); - _mapping.AddMapping (_clause1, _querySourceReferenceExpression2); + Assert.That ( + () => _mapping.AddMapping (_clause1, _querySourceReferenceExpression2), + Throws.InvalidOperationException + .With.Message.EqualTo ("Query source (from Int32 main in TestQueryable()) has already been associated with an expression.")); } [Test] @@ -74,11 +75,13 @@ public void ReplaceMapping () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "Query source (from Int32 main in TestQueryable()) has not been associated with an expression, cannot replace its mapping.")] public void ReplaceMapping_WithoutAdding () { - _mapping.ReplaceMapping (_clause1, _querySourceReferenceExpression2); + Assert.That ( + () => _mapping.ReplaceMapping (_clause1, _querySourceReferenceExpression2), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Query source (from Int32 main in TestQueryable()) has not been associated with an expression, cannot replace its mapping.")); } [Test] @@ -91,11 +94,13 @@ public void RemoveMapping () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "Query source (from Int32 main in TestQueryable()) has not been associated with an expression, cannot remove its mapping.")] public void RemoveMapping_WithoutAdding () { - _mapping.RemoveMapping (_clause1); + Assert.That ( + () => _mapping.RemoveMapping (_clause1), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Query source (from Int32 main in TestQueryable()) has not been associated with an expression, cannot remove its mapping.")); } [Test] @@ -112,11 +117,12 @@ public void ContainsMapping_False () } [Test] - [ExpectedException (typeof (KeyNotFoundException), ExpectedMessage = - "Query source (from Int32 main in TestQueryable()) has not been associated with an expression.")] public void GetExpression_WithoutAssociatedClause () { - _mapping.GetExpression (_clause1); + Assert.That ( + () => _mapping.GetExpression (_clause1), + Throws.InstanceOf() + .With.Message.EqualTo ("Query source (from Int32 main in TestQueryable()) has not been associated with an expression.")); } } } \ No newline at end of file diff --git a/UnitTests/Clauses/ResultOperators/AggregateFromSeedResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/AggregateFromSeedResultOperatorTest.cs index 7b33de3cc..9c3bcb260 100644 --- a/UnitTests/Clauses/ResultOperators/AggregateFromSeedResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/AggregateFromSeedResultOperatorTest.cs @@ -72,9 +72,6 @@ public void Func () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " - + "'System.Reflection.MemberFilter'.\r\nParameter name: value")] public void Func_NonGeneric () { var func = Expression.Lambda ( @@ -82,30 +79,36 @@ public void Func_NonGeneric () Expression.Constant (true), Expression.Parameter (typeof (MemberInfo), "m"), Expression.Parameter (typeof (object), "filterCriteria")); - - _resultOperatorWithResultSelector.Func = func; + Assert.That ( + () => _resultOperatorWithResultSelector.Func = func, + Throws.ArgumentException + .With.Message.EqualTo ( + "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " + + "'System.Reflection.MemberFilter'.\r\nParameter name: value")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " - + "'System.Func`1[System.Boolean]'.\r\nParameter name: value")] public void Func_Generic_WrongDefinition () { var func = Expression.Lambda (typeof (Func), Expression.Constant (true)); - - _resultOperatorWithResultSelector.Func = func; + Assert.That ( + () => _resultOperatorWithResultSelector.Func = func, + Throws.ArgumentException + .With.Message.EqualTo ( + "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " + + "'System.Func`1[System.Boolean]'.\r\nParameter name: value")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " - + "'System.Func`2[System.Int32,System.Boolean]'.\r\nParameter name: value")] public void Func_Generic_WrongReturnType () { var func = Expression.Lambda (typeof (Func), Expression.Constant (true), Expression.Parameter (typeof (int), "i")); - - _resultOperatorWithResultSelector.Func = func; + Assert.That ( + () => _resultOperatorWithResultSelector.Func = func, + Throws.ArgumentException + .With.Message.EqualTo ( + "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " + + "'System.Func`2[System.Int32,System.Boolean]'.\r\nParameter name: value")); } [Test] @@ -115,23 +118,27 @@ public void GetConstantSeed () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The seed expression ('[main]') is no ConstantExpression, it is a QuerySourceReferenceExpression.\r\nParameter name: expression")] public void GetConstantSeed_NoConstantExpression () { var resultOperator = new AggregateFromSeedResultOperator ( new QuerySourceReferenceExpression (ExpressionHelper.CreateMainFromClause_Int ()), _func, _resultSelector); - resultOperator.GetConstantSeed (); + Assert.That ( + () => resultOperator.GetConstantSeed (), + Throws.ArgumentException + .With.Message.EqualTo ( + "The seed expression ('[main]') is no ConstantExpression, it is a QuerySourceReferenceExpression.\r\nParameter name: expression")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The value stored by the seed expression ('12') is not of type 'System.DateTime', it is of type 'System.Int32'.\r\nParameter name: expression")] public void GetConstantSeed_NotExpectedType () { - _resultOperatorWithResultSelector.GetConstantSeed (); + Assert.That ( + () => _resultOperatorWithResultSelector.GetConstantSeed (), + Throws.ArgumentException + .With.Message.EqualTo ( + "The value stored by the seed expression ('12') is not of type 'System.DateTime', it is of type 'System.Int32'.\r\nParameter name: expression")); } [Test] @@ -155,9 +162,6 @@ public void ResultSelector_Null () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The result selector must be a LambdaExpression that describes an instantiation of 'Func', but it is " - + "'System.Reflection.MemberFilter'.\r\nParameter name: value")] public void ResultSelector_NonGeneric () { var resultSelector = Expression.Lambda ( @@ -165,19 +169,24 @@ public void ResultSelector_NonGeneric () Expression.Constant (true), Expression.Parameter (typeof (MemberInfo), "m"), Expression.Parameter (typeof (object), "filterCriteria")); - - _resultOperatorWithResultSelector.OptionalResultSelector = resultSelector; + Assert.That ( + () => _resultOperatorWithResultSelector.OptionalResultSelector = resultSelector, + Throws.ArgumentException + .With.Message.EqualTo ( + "The result selector must be a LambdaExpression that describes an instantiation of 'Func', but it is " + + "'System.Reflection.MemberFilter'.\r\nParameter name: value")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The result selector must be a LambdaExpression that describes an instantiation of 'Func', but it is " - + "'System.Func`1[System.Boolean]'.\r\nParameter name: value")] public void ResultSelector_Generic_WrongDefinition () { var resultSelector = Expression.Lambda (typeof (Func), Expression.Constant (true)); - - _resultOperatorWithResultSelector.OptionalResultSelector = resultSelector; + Assert.That ( + () => _resultOperatorWithResultSelector.OptionalResultSelector = resultSelector, + Throws.ArgumentException + .With.Message.EqualTo ( + "The result selector must be a LambdaExpression that describes an instantiation of 'Func', but it is " + + "'System.Func`1[System.Boolean]'.\r\nParameter name: value")); } [Test] @@ -221,33 +230,34 @@ public void GetOutputDataInfo_WithDifferentAssignableSeedType () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperatorWithResultSelector.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperatorWithResultSelector.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "The seed expression and the aggregating function don't have matching types. The seed is of type 'System.String', but the function aggregates " - + "'System.Int32'.")] public void GetOutputDataInfo_NonMatchingFunc () { _resultOperatorWithResultSelector.Seed = Expression.Constant ("0"); var itemExpression = Expression.Constant (0); var input = new StreamedSequenceInfo (typeof (int[]), itemExpression); - _resultOperatorWithResultSelector.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperatorWithResultSelector.GetOutputDataInfo (input), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "The seed expression and the aggregating function don't have matching types. The seed is of type 'System.String', but the function aggregates " + + "'System.Int32'.")); } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "The aggregating function and the result selector don't have matching types. The function aggregates type 'System.Int32', but the " - + "result selector takes 'System.String'.")] public void GetOutputDataInfo_NonMatchingResultSelector () { var resultSelector = Expression.Lambda ( @@ -258,7 +268,12 @@ public void GetOutputDataInfo_NonMatchingResultSelector () var itemExpression = Expression.Constant (0); var input = new StreamedSequenceInfo (typeof (int[]), itemExpression); - _resultOperatorWithResultSelector.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperatorWithResultSelector.GetOutputDataInfo (input), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "The aggregating function and the result selector don't have matching types. The function aggregates type 'System.Int32', but the " + + "result selector takes 'System.String'.")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/AggregateResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/AggregateResultOperatorTest.cs index 6661a3608..166458ff0 100644 --- a/UnitTests/Clauses/ResultOperators/AggregateResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/AggregateResultOperatorTest.cs @@ -67,9 +67,6 @@ public void Func_ResultTypeAssignableToParameterType () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " - + "'System.Reflection.MemberFilter'.\r\nParameter name: value")] public void Func_NonGeneric () { var func = Expression.Lambda ( @@ -77,30 +74,36 @@ public void Func_NonGeneric () Expression.Constant (true), Expression.Parameter (typeof (MemberInfo), "m"), Expression.Parameter (typeof (object), "filterCriteria")); - - _resultOperator.Func = func; + Assert.That ( + () => _resultOperator.Func = func, + Throws.ArgumentException + .With.Message.EqualTo ( + "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " + + "'System.Reflection.MemberFilter'.\r\nParameter name: value")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " - + "'System.Func`1[System.Boolean]'.\r\nParameter name: value")] public void Func_Generic_WrongDefinition () { var func = Expression.Lambda (typeof (Func), Expression.Constant (true)); - - _resultOperator.Func = func; + Assert.That ( + () => _resultOperator.Func = func, + Throws.ArgumentException + .With.Message.EqualTo ( + "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " + + "'System.Func`1[System.Boolean]'.\r\nParameter name: value")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " - + "'System.Func`2[System.Int32,System.Boolean]'.\r\nParameter name: value")] public void Func_Generic_WrongReturnType () { var func = Expression.Lambda (typeof (Func), Expression.Constant (true), Expression.Parameter (typeof (int), "i")); - - _resultOperator.Func = func; + Assert.That ( + () => _resultOperator.Func = func, + Throws.ArgumentException + .With.Message.EqualTo ( + "The aggregating function must be a LambdaExpression that describes an instantiation of 'Func', but it is " + + "'System.Func`2[System.Int32,System.Boolean]'.\r\nParameter name: value")); } [Test] @@ -129,20 +132,24 @@ public void GetOutputDataInfo_Covariant () } [Test] - [ExpectedException (typeof (ArgumentException))] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = "The input sequence must have items of type 'System.Int32', but it has " - + "items of type 'Remotion.Linq.UnitTests.TestDomain.Cook'.\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput_DoesntMatchItem () { var input = new StreamedSequenceInfo (typeof (Cook[]), Expression.Constant (new Cook ())); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "The input sequence must have items of type 'System.Int32', but it has " + + "items of type 'Remotion.Linq.UnitTests.TestDomain.Cook'.\r\nParameter name: inputInfo")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/AllResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/AllResultOperatorTest.cs index dc98d913a..d78f333e4 100644 --- a/UnitTests/Clauses/ResultOperators/AllResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/AllResultOperatorTest.cs @@ -87,14 +87,16 @@ public void GetOutputDataInfo () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo'" - + " when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo'" + + " when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/AnyResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/AnyResultOperatorTest.cs index d4a6a8f50..c2676e9c3 100644 --- a/UnitTests/Clauses/ResultOperators/AnyResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/AnyResultOperatorTest.cs @@ -75,14 +75,16 @@ public void GetOutputDataInfo () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/AverageResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/AverageResultOperatorTest.cs index 1472890bb..b19f6484c 100644 --- a/UnitTests/Clauses/ResultOperators/AverageResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/AverageResultOperatorTest.cs @@ -56,11 +56,14 @@ public void ExecuteInMemory () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Cannot calculate the average of objects of type 'System.String' in memory.")] public void ExecuteInMemory_UnsupportedType () { var input = new StreamedSequence (new[] { "1", "2", "3" }, new StreamedSequenceInfo (typeof (string[]), Expression.Constant ("0"))); - _resultOperator.ExecuteInMemory (input); + Assert.That ( + () => _resultOperator.ExecuteInMemory (input), + Throws.InstanceOf() + .With.Message.EqualTo ( + "Cannot calculate the average of objects of type 'System.String' in memory.")); } [Test] @@ -84,14 +87,16 @@ public void GetOutputDataInfo_IntegerTypesGoToDouble () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } private void CheckOutputDataInfo (Type itemType, Type expectedOutputType) diff --git a/UnitTests/Clauses/ResultOperators/CastResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/CastResultOperatorTest.cs index 2b84adda1..8e68e685e 100644 --- a/UnitTests/Clauses/ResultOperators/CastResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/CastResultOperatorTest.cs @@ -81,14 +81,16 @@ public void GetOutputDataInfo () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/ChoiceResultOperatorBaseTest.cs b/UnitTests/Clauses/ResultOperators/ChoiceResultOperatorBaseTest.cs index 8c1b3b6f2..01bf7e5da 100644 --- a/UnitTests/Clauses/ResultOperators/ChoiceResultOperatorBaseTest.cs +++ b/UnitTests/Clauses/ResultOperators/ChoiceResultOperatorBaseTest.cs @@ -57,14 +57,16 @@ public void GetOutputDataInfo_DefaultWhenEmpty () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperatorNoDefaultWhenEmpty.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperatorNoDefaultWhenEmpty.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } } } diff --git a/UnitTests/Clauses/ResultOperators/ConcatResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/ConcatResultOperatorTest.cs index 43fd29dbc..fc2207bb6 100644 --- a/UnitTests/Clauses/ResultOperators/ConcatResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/ConcatResultOperatorTest.cs @@ -124,23 +124,27 @@ public void GetOutputDataInfo_AssignableSource2 () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInputType () { var input = new StreamedScalarValueInfo (typeof (int)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The input sequence must have items of type 'System.Int32', but it has items of type 'System.String'.\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInputItemType () { var input = new StreamedSequenceInfo (typeof (string[]), Expression.Constant ("")); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "The input sequence must have items of type 'System.Int32', but it has items of type 'System.String'.\r\nParameter name: inputInfo")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/ContainsResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/ContainsResultOperatorTest.cs index ca27d2ee7..273e41d72 100644 --- a/UnitTests/Clauses/ResultOperators/ContainsResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/ContainsResultOperatorTest.cs @@ -73,24 +73,28 @@ public void GetOutputDataInfo () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The items of the input sequence of type 'Remotion.Linq.UnitTests.TestDomain.Cook' are not compatible with the item expression " - + "of type 'System.Int32'.\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput_DoesntMatchItem () { var input = new StreamedSequenceInfo (typeof (Cook[]), Expression.Constant (new Cook())); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "The items of the input sequence of type 'Remotion.Linq.UnitTests.TestDomain.Cook' are not compatible with the item expression " + + "of type 'System.Int32'.\r\nParameter name: inputInfo")); } [Test] @@ -100,20 +104,24 @@ public void GetConstantItem () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The item expression ('[main]') is no ConstantExpression, it is a QuerySourceReferenceExpression.\r\nParameter name: expression")] public void GetConstantItem_NoConstantExpression () { var resultOperator = new ContainsResultOperator (new QuerySourceReferenceExpression (ExpressionHelper.CreateMainFromClause_Int ())); - resultOperator.GetConstantItem (); + Assert.That ( + () => resultOperator.GetConstantItem (), + Throws.ArgumentException + .With.Message.EqualTo ( + "The item expression ('[main]') is no ConstantExpression, it is a QuerySourceReferenceExpression.\r\nParameter name: expression")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The value stored by the item expression ('2') is not of type 'System.DateTime', it is of type 'System.Int32'.\r\nParameter name: expression")] public void GetConstantItem_NotExpectedType () { - _resultOperator.GetConstantItem (); + Assert.That ( + () => _resultOperator.GetConstantItem (), + Throws.ArgumentException + .With.Message.EqualTo ( + "The value stored by the item expression ('2') is not of type 'System.DateTime', it is of type 'System.Int32'.\r\nParameter name: expression")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/CountResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/CountResultOperatorTest.cs index 9db098aa7..33a5c1ee9 100644 --- a/UnitTests/Clauses/ResultOperators/CountResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/CountResultOperatorTest.cs @@ -66,14 +66,16 @@ public void GetOutputDataInfo () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } } } diff --git a/UnitTests/Clauses/ResultOperators/DefaultIfEmptyResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/DefaultIfEmptyResultOperatorTest.cs index e615d1f74..aaa156309 100644 --- a/UnitTests/Clauses/ResultOperators/DefaultIfEmptyResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/DefaultIfEmptyResultOperatorTest.cs @@ -47,12 +47,14 @@ public void GetConstantOptionalDefaultValue_WithDefaultValue () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The default value expression ('[main]') is no ConstantExpression, it is a QuerySourceReferenceExpression.\r\nParameter name: expression")] public void GetConstantOptionalDefaultValue_WithDefaultValue_NoConstantExpression () { var resultOperator = new DefaultIfEmptyResultOperator (new QuerySourceReferenceExpression (ExpressionHelper.CreateMainFromClause_Int ())); - resultOperator.GetConstantOptionalDefaultValue (); + Assert.That ( + () => resultOperator.GetConstantOptionalDefaultValue (), + Throws.ArgumentException + .With.Message.EqualTo ( + "The default value expression ('[main]') is no ConstantExpression, it is a QuerySourceReferenceExpression.\r\nParameter name: expression")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/FirstResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/FirstResultOperatorTest.cs index 855175487..ad575a956 100644 --- a/UnitTests/Clauses/ResultOperators/FirstResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/FirstResultOperatorTest.cs @@ -80,12 +80,14 @@ public void ExecuteInMemory_Empty_Default () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Sequence contains no elements")] public void ExecuteInMemory_Empty_NoDefault () { IEnumerable items = new int[0]; var input = new StreamedSequence (items, new StreamedSequenceInfo (typeof (int[]), Expression.Constant (0))); - _resultOperatorNoDefault.ExecuteInMemory (input); + Assert.That ( + () => _resultOperatorNoDefault.ExecuteInMemory (input), + Throws.InvalidOperationException + .With.Message.EqualTo ("Sequence contains no elements")); } } } diff --git a/UnitTests/Clauses/ResultOperators/GroupResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/GroupResultOperatorTest.cs index 2793dc235..5db3336ef 100644 --- a/UnitTests/Clauses/ResultOperators/GroupResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/GroupResultOperatorTest.cs @@ -129,14 +129,16 @@ public void GetOutputDataInfo () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/LastResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/LastResultOperatorTest.cs index 65e4fcd76..6044e13d6 100644 --- a/UnitTests/Clauses/ResultOperators/LastResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/LastResultOperatorTest.cs @@ -80,12 +80,14 @@ public void ExecuteInMemory_Empty_Default () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Sequence contains no elements")] public void ExecuteInMemory_Empty_NoDefault () { IEnumerable items = new int[0]; var input = new StreamedSequence (items, new StreamedSequenceInfo (typeof (int[]), Expression.Constant (0))); - _resultOperatorNoDefault.ExecuteInMemory (input); + Assert.That ( + () => _resultOperatorNoDefault.ExecuteInMemory (input), + Throws.InvalidOperationException + .With.Message.EqualTo ("Sequence contains no elements")); } } } diff --git a/UnitTests/Clauses/ResultOperators/LongCountResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/LongCountResultOperatorTest.cs index 2bb66ccd6..b67b081e2 100644 --- a/UnitTests/Clauses/ResultOperators/LongCountResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/LongCountResultOperatorTest.cs @@ -68,14 +68,16 @@ public void GetOutputDataInfo () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } } } diff --git a/UnitTests/Clauses/ResultOperators/OfTypeResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/OfTypeResultOperatorTest.cs index e7d24d246..fc9ed6fb6 100644 --- a/UnitTests/Clauses/ResultOperators/OfTypeResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/OfTypeResultOperatorTest.cs @@ -82,14 +82,16 @@ public void GetOutputDataInfo () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/SequenceTypePreservingResultOperatorBaseTest.cs b/UnitTests/Clauses/ResultOperators/SequenceTypePreservingResultOperatorBaseTest.cs index e366e8f91..3524cf441 100644 --- a/UnitTests/Clauses/ResultOperators/SequenceTypePreservingResultOperatorBaseTest.cs +++ b/UnitTests/Clauses/ResultOperators/SequenceTypePreservingResultOperatorBaseTest.cs @@ -49,14 +49,16 @@ public void GetOutputDataInfo () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (Cook)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } } } diff --git a/UnitTests/Clauses/ResultOperators/SingleResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/SingleResultOperatorTest.cs index 2ae178952..08b94874f 100644 --- a/UnitTests/Clauses/ResultOperators/SingleResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/SingleResultOperatorTest.cs @@ -80,21 +80,26 @@ public void ExecuteInMemory_Empty_Default () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Sequence contains no elements")] public void ExecuteInMemory_Empty_NoDefault () { IEnumerable items = new int[0]; var input = new StreamedSequence (items, new StreamedSequenceInfo (typeof (int[]), Expression.Constant (0))); - _resultOperatorNoDefault.ExecuteInMemory (input); + Assert.That ( + () => _resultOperatorNoDefault.ExecuteInMemory (input), + Throws.InvalidOperationException + .With.Message.EqualTo ("Sequence contains no elements")); } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Sequence contains more than one element")] public void ExecuteInMemory_TooManyItems () { IEnumerable items = new[] { 1, 2 }; var input = new StreamedSequence (items, new StreamedSequenceInfo (typeof (int[]), Expression.Constant (0))); - _resultOperatorWithDefault.ExecuteInMemory (input); + Assert.That ( + () => _resultOperatorWithDefault.ExecuteInMemory (input), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Sequence contains more than one element")); } } } diff --git a/UnitTests/Clauses/ResultOperators/SkipResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/SkipResultOperatorTest.cs index 5e3940757..783a35629 100644 --- a/UnitTests/Clauses/ResultOperators/SkipResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/SkipResultOperatorTest.cs @@ -39,10 +39,11 @@ public void SetUp () } [Test] - [ExpectedException (typeof (ArgumentException))] public void Initialization_NoIntExpression () { - new SkipResultOperator (Expression.Constant ("12")); + Assert.That ( + () => new SkipResultOperator (Expression.Constant ("12")), + Throws.ArgumentException); } [Test] @@ -73,12 +74,14 @@ public void GetConstantCount () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The count expression ('[main]') is no ConstantExpression, it is a QuerySourceReferenceExpression.\r\nParameter name: expression")] public void GetConstantCount_NoConstantExpression () { var resultOperator = new SkipResultOperator (new QuerySourceReferenceExpression (ExpressionHelper.CreateMainFromClause_Int ())); - resultOperator.GetConstantCount (); + Assert.That ( + () => resultOperator.GetConstantCount (), + Throws.ArgumentException + .With.Message.EqualTo ( + "The count expression ('[main]') is no ConstantExpression, it is a QuerySourceReferenceExpression.\r\nParameter name: expression")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/SumResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/SumResultOperatorTest.cs index e1baa69f7..105114efb 100644 --- a/UnitTests/Clauses/ResultOperators/SumResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/SumResultOperatorTest.cs @@ -54,11 +54,14 @@ public void ExecuteInMemory () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Cannot calculate the sum of objects of type 'System.String' in memory.")] public void ExecuteInMemory_UnsupportedType () { var input = new StreamedSequence (new[] { "1", "2", "3" }, new StreamedSequenceInfo (typeof (string[]), Expression.Constant ("0"))); - _resultOperator.ExecuteInMemory (input); + Assert.That ( + () => _resultOperator.ExecuteInMemory (input), + Throws.InstanceOf() + .With.Message.EqualTo ( + "Cannot calculate the sum of objects of type 'System.String' in memory.")); } [Test] @@ -84,14 +87,16 @@ public void GetOutputDataInfo_CovariantSequence () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInput () { var input = new StreamedScalarValueInfo (typeof (float)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } } } diff --git a/UnitTests/Clauses/ResultOperators/TakeResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/TakeResultOperatorTest.cs index c707a46d2..de8b98173 100644 --- a/UnitTests/Clauses/ResultOperators/TakeResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/TakeResultOperatorTest.cs @@ -39,10 +39,11 @@ public void SetUp () } [Test] - [ExpectedException (typeof (ArgumentException))] public void Initialization_NoIntExpression () { - new TakeResultOperator (Expression.Constant ("12")); + Assert.That ( + () => new TakeResultOperator (Expression.Constant ("12")), + Throws.ArgumentException); } [Test] @@ -72,12 +73,14 @@ public void GetConstantCount () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The count expression ('[main]') is no ConstantExpression, it is a QuerySourceReferenceExpression.\r\nParameter name: expression")] public void GetConstantCount_NoConstantExpression () { var resultOperator = new TakeResultOperator (new QuerySourceReferenceExpression (ExpressionHelper.CreateMainFromClause_Int ())); - resultOperator.GetConstantCount (); + Assert.That ( + () => resultOperator.GetConstantCount (), + Throws.ArgumentException + .With.Message.EqualTo ( + "The count expression ('[main]') is no ConstantExpression, it is a QuerySourceReferenceExpression.\r\nParameter name: expression")); } [Test] diff --git a/UnitTests/Clauses/ResultOperators/UnionResultOperatorTest.cs b/UnitTests/Clauses/ResultOperators/UnionResultOperatorTest.cs index 5190e91e4..720476555 100644 --- a/UnitTests/Clauses/ResultOperators/UnionResultOperatorTest.cs +++ b/UnitTests/Clauses/ResultOperators/UnionResultOperatorTest.cs @@ -124,23 +124,27 @@ public void GetOutputDataInfo_AssignableSource2 () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " - + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." - + "\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInputType () { var input = new StreamedScalarValueInfo (typeof (int)); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'inputInfo' has type 'Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo' " + + "when type 'Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo' was expected." + + "\r\nParameter name: inputInfo")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "The input sequence must have items of type 'System.Int32', but it has items of type 'System.String'.\r\nParameter name: inputInfo")] public void GetOutputDataInfo_InvalidInputItemType () { var input = new StreamedSequenceInfo (typeof (string[]), Expression.Constant ("")); - _resultOperator.GetOutputDataInfo (input); + Assert.That ( + () => _resultOperator.GetOutputDataInfo (input), + Throws.ArgumentException + .With.Message.EqualTo ( + "The input sequence must have items of type 'System.Int32', but it has items of type 'System.String'.\r\nParameter name: inputInfo")); } [Test] diff --git a/UnitTests/Clauses/StreamedData/StreamedScalarValueInfoTest.cs b/UnitTests/Clauses/StreamedData/StreamedScalarValueInfoTest.cs index 276501b9d..049e4602d 100644 --- a/UnitTests/Clauses/StreamedData/StreamedScalarValueInfoTest.cs +++ b/UnitTests/Clauses/StreamedData/StreamedScalarValueInfoTest.cs @@ -76,15 +76,16 @@ public void ExecuteQueryModel () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Test")] public void ExecuteQueryModel_WithException () { var queryModel = ExpressionHelper.CreateQueryModel (); var executorMock = MockRepository.GenerateMock (); executorMock.Expect (mock => mock.ExecuteScalar (queryModel)).Throw (new InvalidOperationException ("Test")); - - _streamedScalarValueInfo.ExecuteQueryModel (queryModel, executorMock); + Assert.That ( + () => _streamedScalarValueInfo.ExecuteQueryModel (queryModel, executorMock), + Throws.InvalidOperationException + .With.Message.EqualTo ("Test")); } [Test] diff --git a/UnitTests/Clauses/StreamedData/StreamedSequenceInfoTest.cs b/UnitTests/Clauses/StreamedData/StreamedSequenceInfoTest.cs index 01449d472..3c3a706ff 100644 --- a/UnitTests/Clauses/StreamedData/StreamedSequenceInfoTest.cs +++ b/UnitTests/Clauses/StreamedData/StreamedSequenceInfoTest.cs @@ -179,15 +179,16 @@ public void ExecuteQueryModel () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Test")] public void ExecuteQueryModel_WithException () { var queryModel = ExpressionHelper.CreateQueryModel(); var executorMock = MockRepository.GenerateMock(); executorMock.Expect (mock => mock.ExecuteCollection (queryModel)).Throw (new InvalidOperationException ("Test")); - - _infoWithStringSequence.ExecuteQueryModel (queryModel, executorMock); + Assert.That ( + () => _infoWithStringSequence.ExecuteQueryModel (queryModel, executorMock), + Throws.InvalidOperationException + .With.Message.EqualTo ("Test")); } [Test] diff --git a/UnitTests/Clauses/StreamedData/StreamedSequenceTest.cs b/UnitTests/Clauses/StreamedData/StreamedSequenceTest.cs index 15c2fd5e3..57a822b47 100644 --- a/UnitTests/Clauses/StreamedData/StreamedSequenceTest.cs +++ b/UnitTests/Clauses/StreamedData/StreamedSequenceTest.cs @@ -38,18 +38,21 @@ public void SetUp () } [Test] - [ExpectedException (typeof (ArgumentNullException))] public void Initialization_CurrentSequence_WithoutItemExpression () { - new StreamedSequence (_stringSequence, null); + Assert.That ( + () => new StreamedSequence (_stringSequence, null), + Throws.ArgumentNullException); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'sequence' has type 'System.String[]' when type 'System.Int32[]' was expected.\r\nParameter name: sequence")] public void Initialization_CurrentSequence_WrongItemExpression () { - new StreamedSequence (new[] { "1", "2", "3" }, new StreamedSequenceInfo (typeof (int[]), _stringExpression)); + Assert.That ( + () => new StreamedSequence (new[] { "1", "2", "3" }, new StreamedSequenceInfo (typeof (int[]), _stringExpression)), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'sequence' has type 'System.String[]' when type 'System.Int32[]' was expected.\r\nParameter name: sequence")); } [Test] @@ -71,11 +74,13 @@ public void GetTypedSequence () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "Cannot retrieve the current value as a sequence with item type 'System.Int32' because its items are of type 'System.Object'.")] public void GetTypedSequence_InvalidItemType () { - _dataWithCovariantSequence.GetTypedSequence(); + Assert.That ( + () => _dataWithCovariantSequence.GetTypedSequence(), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Cannot retrieve the current value as a sequence with item type 'System.Int32' because its items are of type 'System.Object'.")); } } } diff --git a/UnitTests/Clauses/StreamedData/StreamedSingleValueInfoTest.cs b/UnitTests/Clauses/StreamedData/StreamedSingleValueInfoTest.cs index 10fa88987..30e58acb0 100644 --- a/UnitTests/Clauses/StreamedData/StreamedSingleValueInfoTest.cs +++ b/UnitTests/Clauses/StreamedData/StreamedSingleValueInfoTest.cs @@ -120,15 +120,16 @@ public void ExecuteQueryModel_WithValueType () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Test")] public void ExecuteQueryModel_WithException () { var queryModel = ExpressionHelper.CreateQueryModel (); var executorMock = MockRepository.GenerateMock (); executorMock.Expect (mock => mock.ExecuteSingle (queryModel, true)).Throw (new InvalidOperationException ("Test")); - - _streamedSingleValueInfoWithDefault.ExecuteQueryModel (queryModel, executorMock); + Assert.That ( + () => _streamedSingleValueInfoWithDefault.ExecuteQueryModel (queryModel, executorMock), + Throws.InvalidOperationException + .With.Message.EqualTo ("Test")); } [Test] diff --git a/UnitTests/Clauses/StreamedData/StreamedValueTest.cs b/UnitTests/Clauses/StreamedData/StreamedValueTest.cs index c5402f659..6d9b19a89 100644 --- a/UnitTests/Clauses/StreamedData/StreamedValueTest.cs +++ b/UnitTests/Clauses/StreamedData/StreamedValueTest.cs @@ -59,19 +59,21 @@ public void GetCurrentSingleValue () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "Cannot retrieve the current value as type 'System.String' because it is of type 'System.Int32'.")] public void GetCurrentSingleValue_InvalidType () { - _dataWithIntValue.GetTypedValue (); + Assert.That ( + () => _dataWithIntValue.GetTypedValue (), + Throws.InvalidOperationException + .With.Message.EqualTo ("Cannot retrieve the current value as type 'System.String' because it is of type 'System.Int32'.")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'value' has type 'System.Int32' when type 'System.String' was expected.\r\nParameter name: value")] public void Initialization_CurrentValue_WrongItemExpression () { - new StreamedValue (0, new StreamedScalarValueInfo (typeof (string))); + Assert.That ( + () => new StreamedValue (0, new StreamedScalarValueInfo (typeof (string))), + Throws.ArgumentException + .With.Message.EqualTo ("Parameter 'value' has type 'System.Int32' when type 'System.String' was expected.\r\nParameter name: value")); } } } diff --git a/UnitTests/Collections/ChangeResistantObservableCollectionEnumeratorTest.cs b/UnitTests/Collections/ChangeResistantObservableCollectionEnumeratorTest.cs index 523a0e7b3..885613697 100644 --- a/UnitTests/Collections/ChangeResistantObservableCollectionEnumeratorTest.cs +++ b/UnitTests/Collections/ChangeResistantObservableCollectionEnumeratorTest.cs @@ -110,11 +110,12 @@ public void MoveNext_ReturnValue () } [Test] - [ExpectedException (typeof (ObjectDisposedException))] public void MoveNext_AfterDispose () { _enumerator.Dispose(); - _enumerator.MoveNext(); + Assert.That ( + () => _enumerator.MoveNext(), + Throws.InstanceOf()); } [Test] @@ -131,11 +132,12 @@ public void Reset () } [Test] - [ExpectedException (typeof (ObjectDisposedException))] public void Reset_AfterDispose () { _enumerator.Dispose(); - _enumerator.Reset(); + Assert.That ( + () => _enumerator.Reset(), + Throws.InstanceOf()); } [Test] diff --git a/UnitTests/DefaultQueryProviderTest.cs b/UnitTests/DefaultQueryProviderTest.cs index d187e82cd..31c906f2a 100644 --- a/UnitTests/DefaultQueryProviderTest.cs +++ b/UnitTests/DefaultQueryProviderTest.cs @@ -39,40 +39,48 @@ public void SetUp () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'queryableType' is a 'System.Int32', which cannot be assigned to type 'System.Linq.IQueryable'.\r\nParameter name: queryableType")] public void Initialization_NonGeneric () { - new DefaultQueryProvider (typeof (int), _parserStub, _executorStub); + Assert.That ( + () => new DefaultQueryProvider (typeof (int), _parserStub, _executorStub), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'queryableType' is a 'System.Int32', which cannot be assigned to type 'System.Linq.IQueryable'.\r\nParameter name: queryableType")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Expected the generic type definition of an implementation of IQueryable, " - + "but was 'Remotion.Linq.Development.UnitTesting.TestQueryable`1[System.Int32]'." - + "\r\nParameter name: queryableType")] public void Initialization_NonGenericTypeDefinition () { - new DefaultQueryProvider (typeof (TestQueryable), _parserStub, _executorStub); + Assert.That ( + () => new DefaultQueryProvider (typeof (TestQueryable), _parserStub, _executorStub), + Throws.ArgumentException + .With.Message.EqualTo ( + "Expected the generic type definition of an implementation of IQueryable, " + + "but was 'Remotion.Linq.Development.UnitTesting.TestQueryable`1[System.Int32]'." + + "\r\nParameter name: queryableType")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Expected the generic type definition of an implementation of IQueryable with exactly one type argument, " - + "but found 2 arguments on 'Remotion.Linq.UnitTests.TestDomain.QueryableWithTooManyArguments`2[T1,T2]." - + "\r\nParameter name: queryableType")] public void Initialization_TooManyGenericArguments () { - new DefaultQueryProvider (typeof (QueryableWithTooManyArguments<,>), _parserStub, _executorStub); + Assert.That ( + () => new DefaultQueryProvider (typeof (QueryableWithTooManyArguments<,>), _parserStub, _executorStub), + Throws.ArgumentException + .With.Message.EqualTo ( + "Expected the generic type definition of an implementation of IQueryable with exactly one type argument, " + + "but found 2 arguments on 'Remotion.Linq.UnitTests.TestDomain.QueryableWithTooManyArguments`2[T1,T2]." + + "\r\nParameter name: queryableType")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'queryableType' is a 'System.Collections.Generic.List`1[System.Int32]', which cannot be assigned to type 'System.Linq.IQueryable'." - + "\r\nParameter name: queryableType")] public void Initialization_NonQueryable () { - new DefaultQueryProvider (typeof (List), _parserStub, _executorStub); + Assert.That ( + () => new DefaultQueryProvider (typeof (List), _parserStub, _executorStub), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'queryableType' is a 'System.Collections.Generic.List`1[System.Int32]', which cannot be assigned to type 'System.Linq.IQueryable'." + + "\r\nParameter name: queryableType")); } [Test] diff --git a/UnitTests/Parsing/ExpressionVisitors/Transformation/ExpressionTransformerRegistryTest.cs b/UnitTests/Parsing/ExpressionVisitors/Transformation/ExpressionTransformerRegistryTest.cs index 0e34070b3..424d56c8a 100644 --- a/UnitTests/Parsing/ExpressionVisitors/Transformation/ExpressionTransformerRegistryTest.cs +++ b/UnitTests/Parsing/ExpressionVisitors/Transformation/ExpressionTransformerRegistryTest.cs @@ -254,20 +254,18 @@ public void GetTransformers_GenericTransformerRegistered_WithCustomExpressionTyp } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Cannot register an IExpressionTransformer as a generic transformer. Generic transformers must implement " - +"IExpressionTransformer.\r\nParameter name: transformer")] public void Register_CheckGenericHandlerType () { var transformerStub = CreateTransformerStub (1, null); - - _registry.Register (transformerStub); + Assert.That ( + () => _registry.Register (transformerStub), + Throws.ArgumentException + .With.Message.EqualTo ( + "Cannot register an IExpressionTransformer as a generic transformer. Generic transformers must implement " + +"IExpressionTransformer.\r\nParameter name: transformer")); } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "A 'ConstantExpression' with node type 'Constant' cannot be handled by the IExpressionTransformer. " - + "The transformer was probably registered for a wrong ExpressionType.")] public void Register_AddsExpressionTypeCheck () { var expression = CreateSimpleExpression (0); @@ -276,8 +274,12 @@ public void Register_AddsExpressionTypeCheck () _registry.Register (transformerStub); var result = _registry.GetTransformations (expression).ToArray (); - - result[0] (expression); + Assert.That ( + () => result[0] (expression), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "A 'ConstantExpression' with node type 'Constant' cannot be handled by the IExpressionTransformer. " + + "The transformer was probably registered for a wrong ExpressionType.")); } private IExpressionTransformer CreateTransformerStub (int id, params ExpressionType[] expressionTypes) diff --git a/UnitTests/Parsing/ExpressionVisitors/Transformation/PredefinedTransformations/VBCompareStringExpressionTransformerTest.cs b/UnitTests/Parsing/ExpressionVisitors/Transformation/PredefinedTransformations/VBCompareStringExpressionTransformerTest.cs index 6c78a8de2..594cca7c7 100644 --- a/UnitTests/Parsing/ExpressionVisitors/Transformation/PredefinedTransformations/VBCompareStringExpressionTransformerTest.cs +++ b/UnitTests/Parsing/ExpressionVisitors/Transformation/PredefinedTransformations/VBCompareStringExpressionTransformerTest.cs @@ -183,16 +183,16 @@ public void Transform_LessThanOrEqual_LeftSideIsCompareStringExpression_ReturnsV } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "Binary expression with node type 'Add' is not supported in a VB string comparison.")] public void Transform_UnsupportedNodeType_LeftSideIsCompareStringExpression_ReturnsVBStringComparisonExpression () { var left = Expression.Constant ("left"); var right = Expression.Constant ("right"); var expression = Expression.Add ( Expression.Call (typeof (Operators).GetMethod ("CompareString"), left, right, Expression.Constant (true)), Expression.Constant (0)); - - _transformer.Transform (expression); + Assert.That ( + () => _transformer.Transform (expression), + Throws.InstanceOf() + .With.Message.EqualTo ("Binary expression with node type 'Add' is not supported in a VB string comparison.")); } diff --git a/UnitTests/Parsing/Structure/ExpressionTreeParserTest.cs b/UnitTests/Parsing/Structure/ExpressionTreeParserTest.cs index 31ed8e40d..23546d299 100644 --- a/UnitTests/Parsing/Structure/ExpressionTreeParserTest.cs +++ b/UnitTests/Parsing/Structure/ExpressionTreeParserTest.cs @@ -159,11 +159,14 @@ public void ParseTree_NonQueryOperatorExpression_IsPreprocessed () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Cannot parse expression '0' as it has an unsupported type. " - + "Only query sources (that is, expressions that implement IEnumerable) and query operators can be parsed.")] public void ParseTree_InvalidNonQueryOperatorExpression () { - _expressionTreeParser.ParseTree (Expression.Constant (0)); + Assert.That ( + () => _expressionTreeParser.ParseTree (Expression.Constant (0)), + Throws.InstanceOf() + .With.Message.EqualTo ( + "Cannot parse expression '0' as it has an unsupported type. " + + "Only query sources (that is, expressions that implement IEnumerable) and query operators can be parsed.")); } [Test] @@ -304,20 +307,25 @@ public void ParseTree_MemberExpression_WithProperty () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Expressions of type void ('WriteLine()') are not supported.")] public void ParseTree_VoidExpression () { MethodCallExpression expression = Expression.Call (typeof (Console), "WriteLine", Type.EmptyTypes); - _expressionTreeParser.ParseTree (expression); + Assert.That ( + () => _expressionTreeParser.ParseTree (expression), + Throws.InstanceOf() + .With.Message.EqualTo ( + "Expressions of type void ('WriteLine()') are not supported.")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "Could not parse expression 'System.Int32[].Sum()': This overload of the method 'System.Linq.Queryable.Sum' is currently not supported.")] public void ParseTree_InvalidMethodCall_UnknownMethod () { var methodCallExpression = (MethodCallExpression) ExpressionHelper.MakeExpression (() => _intSource.Sum()); - _expressionTreeParser.ParseTree (methodCallExpression); + Assert.That ( + () => _expressionTreeParser.ParseTree (methodCallExpression), + Throws.InstanceOf() + .With.Message.EqualTo ( + "Could not parse expression 'System.Int32[].Sum()': This overload of the method 'System.Linq.Queryable.Sum' is currently not supported.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/AggregateExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/AggregateExpressionNodeTest.cs index a5cab07e1..d56891ab8 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/AggregateExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/AggregateExpressionNodeTest.cs @@ -61,19 +61,24 @@ public void Initialization () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = "Func must have exactly two parameters.\r\nParameter name: func")] public void Initialization_WrongNumberOfParameters () { var parseInfo = CreateParseInfo (); - new AggregateExpressionNode (parseInfo, ExpressionHelper.CreateLambdaExpression (i => false)); + Assert.That ( + () => new AggregateExpressionNode (parseInfo, ExpressionHelper.CreateLambdaExpression (i => false)), + Throws.ArgumentException + .With.Message.EqualTo ( + "Func must have exactly two parameters.\r\nParameter name: func")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "AggregateExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "AggregateExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/AggregateFromSeedExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/AggregateFromSeedExpressionNodeTest.cs index d95016bb6..1b366b4aa 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/AggregateFromSeedExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/AggregateFromSeedExpressionNodeTest.cs @@ -85,28 +85,34 @@ public void Initialization_WithResultSelector () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = "Func must have exactly two parameters.\r\nParameter name: func")] public void Initialization_WrongNumberOfParametersInFunc () { var parseInfo = CreateParseInfo (); - new AggregateFromSeedExpressionNode (parseInfo, _seed, ExpressionHelper.CreateLambdaExpression (i => false), _resultSelector); + Assert.That ( + () => new AggregateFromSeedExpressionNode (parseInfo, _seed, ExpressionHelper.CreateLambdaExpression (i => false), _resultSelector), + Throws.ArgumentException + .With.Message.EqualTo ( + "Func must have exactly two parameters.\r\nParameter name: func")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Result selector must have exactly one parameter.\r\nParameter name: optionalResultSelector")] public void Initialization_WrongNumberOfParametersInResultSelector () { var parseInfo = CreateParseInfo (); - new AggregateFromSeedExpressionNode (parseInfo, _seed, _func, ExpressionHelper.CreateLambdaExpression ((i, j) => false)); + Assert.That ( + () => new AggregateFromSeedExpressionNode (parseInfo, _seed, _func, ExpressionHelper.CreateLambdaExpression ((i, j) => false)), + Throws.ArgumentException + .With.Message.EqualTo ("Result selector must have exactly one parameter.\r\nParameter name: optionalResultSelector")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "AggregateFromSeedExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _nodeWithResultSelector.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _nodeWithResultSelector.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "AggregateFromSeedExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/AllExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/AllExpressionNodeTest.cs index bf1646920..7d2fabfa3 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/AllExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/AllExpressionNodeTest.cs @@ -52,11 +52,13 @@ public void GetSupportedMethods () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "AllExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "AllExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/AnyExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/AnyExpressionNodeTest.cs index 4befc4e36..145d4105b 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/AnyExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/AnyExpressionNodeTest.cs @@ -71,11 +71,13 @@ public void Initialization_WithoutPredicate () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "AnyExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "AnyExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/AverageExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/AverageExpressionNodeTest.cs index f29553fc7..64a75a4f4 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/AverageExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/AverageExpressionNodeTest.cs @@ -89,11 +89,13 @@ public void GetSupportedMethods () [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "AverageExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "AverageExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/ClauseGenerationContextTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/ClauseGenerationContextTest.cs index 4dc308c39..c41afe360 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/ClauseGenerationContextTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/ClauseGenerationContextTest.cs @@ -56,11 +56,14 @@ public void AddContextInfo_IncreasesCount () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Node already has associated context info.")] public void AddContextInfoTwice () { _context.AddContextInfo (_node, _clause); - _context.AddContextInfo (_node, _clause); + Assert.That ( + () => _context.AddContextInfo (_node, _clause), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Node already has associated context info.")); } [Test] @@ -72,10 +75,12 @@ public void GetContextInfo () } [Test] - [ExpectedException (typeof (KeyNotFoundException), ExpectedMessage = "Node has no associated context info.")] public void GetContextInfo_ThrowsException () { - _context.GetContextInfo (_node); + Assert.That ( + () => _context.GetContextInfo (_node), + Throws.InstanceOf() + .With.Message.EqualTo ("Node has no associated context info.")); } } diff --git a/UnitTests/Parsing/Structure/IntermediateModel/ContainsExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/ContainsExpressionNodeTest.cs index b0b3f49db..04a90842e 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/ContainsExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/ContainsExpressionNodeTest.cs @@ -66,11 +66,13 @@ public void GetSupportedMethodNames () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "ContainsExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "ContainsExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/CountExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/CountExpressionNodeTest.cs index e36e22d20..f4c415bfa 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/CountExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/CountExpressionNodeTest.cs @@ -79,11 +79,13 @@ public void Initialization_WithoutPredicate () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "CountExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "CountExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/FirstExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/FirstExpressionNodeTest.cs index 149b32ad0..9249801f9 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/FirstExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/FirstExpressionNodeTest.cs @@ -58,11 +58,13 @@ public void GetSupportedMethods () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "FirstExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "FirstExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/GroupByExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/GroupByExpressionNodeTest.cs index 83ea31e29..9420bf5ee 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/GroupByExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/GroupByExpressionNodeTest.cs @@ -60,19 +60,21 @@ public void GetSupportedMethods () } [Test] - [ExpectedException (typeof (ArgumentException))] public void Initialization_InvalidKeySelector () { var keySelector = ExpressionHelper.CreateLambdaExpression ((i, s) => true); - new GroupByExpressionNode (CreateParseInfo (), keySelector, _elementSelector); + Assert.That ( + () => new GroupByExpressionNode (CreateParseInfo (), keySelector, _elementSelector), + Throws.ArgumentException); } [Test] - [ExpectedException (typeof (ArgumentException))] public void Initialization_InvalidElementSelector () { var elementSelector = ExpressionHelper.CreateLambdaExpression ((i, s) => true); - new GroupByExpressionNode (CreateParseInfo (), _keySelector, elementSelector); + Assert.That ( + () => new GroupByExpressionNode (CreateParseInfo (), _keySelector, elementSelector), + Throws.ArgumentException); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/GroupByWithResultSelectorExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/GroupByWithResultSelectorExpressionNodeTest.cs index a26959afb..5df33e559 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/GroupByWithResultSelectorExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/GroupByWithResultSelectorExpressionNodeTest.cs @@ -130,14 +130,13 @@ public void Initialization_WithoutElementSelector () } [Test] - [ExpectedException ( - typeof (ArgumentException), - ExpectedMessage = "ResultSelector must have exactly two parameters.", - MatchType = MessageMatch.Contains)] public void Initialization_InvalidResultSelector_WrongNumberOfParameters () { var resultSelector = ExpressionHelper.CreateLambdaExpression ((i, s, d) => true); - new GroupByWithResultSelectorExpressionNode (_parseInfoWithElementSelector, _keySelector, _elementSelector, resultSelector); + Assert.That ( + () => new GroupByWithResultSelectorExpressionNode (_parseInfoWithElementSelector, _keySelector, _elementSelector, resultSelector), + Throws.ArgumentException + .With.Message.Contains ("ResultSelector must have exactly two parameters.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/GroupJoinExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/GroupJoinExpressionNodeTest.cs index 9d15820bb..2b355434f 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/GroupJoinExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/GroupJoinExpressionNodeTest.cs @@ -79,11 +79,14 @@ public void GetResolvedResultSelector () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Cannot retrieve an IQuerySource for the given GroupJoinExpressionNode. " - + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")] public void GetResolvedResultSelector_WithoutClause () { - _node.GetResolvedResultSelector (ClauseGenerationContext); + Assert.That ( + () => _node.GetResolvedResultSelector (ClauseGenerationContext), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Cannot retrieve an IQuerySource for the given GroupJoinExpressionNode. " + + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/JoinExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/JoinExpressionNodeTest.cs index 969284d66..72c0acc66 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/JoinExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/JoinExpressionNodeTest.cs @@ -85,11 +85,14 @@ public void GetResolvedInnerKeySelector () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Cannot retrieve an IQuerySource for the given JoinExpressionNode. " - + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")] public void GetResolvedInnerKeySelector_WithoutClause () { - _node.GetResolvedInnerKeySelector (ClauseGenerationContext); + Assert.That ( + () => _node.GetResolvedInnerKeySelector (ClauseGenerationContext), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Cannot retrieve an IQuerySource for the given JoinExpressionNode. " + + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")); } [Test] @@ -104,11 +107,14 @@ public void GetResolvedResultSelector () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Cannot retrieve an IQuerySource for the given JoinExpressionNode. " - + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")] public void GetResolvedResultSelector_WithoutClause () { - _node.GetResolvedResultSelector (ClauseGenerationContext); + Assert.That ( + () => _node.GetResolvedResultSelector (ClauseGenerationContext), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Cannot retrieve an IQuerySource for the given JoinExpressionNode. " + + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/LastExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/LastExpressionNodeTest.cs index ad08849b0..f41f67de5 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/LastExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/LastExpressionNodeTest.cs @@ -58,11 +58,13 @@ public void GetSupportedMethods () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "LastExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "LastExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/LongCountExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/LongCountExpressionNodeTest.cs index a6fe692f3..b1072c5e1 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/LongCountExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/LongCountExpressionNodeTest.cs @@ -52,11 +52,13 @@ public void GetSupportedMethods () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "LongCountExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "LongCountExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/MainSourceExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/MainSourceExpressionNodeTest.cs index cd7935411..bbff78aca 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/MainSourceExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/MainSourceExpressionNodeTest.cs @@ -41,12 +41,14 @@ public void Initialization_QuerySourceElementType () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'expression.Type' is a 'System.Int32', which cannot be assigned to type 'System.Collections.IEnumerable'." - + "\r\nParameter name: expression.Type")] public void Initialization_TypeNotEnumerable () { - new MainSourceExpressionNode ("x", Expression.Constant(5)); + Assert.That ( + () => new MainSourceExpressionNode ("x", Expression.Constant(5)), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'expression.Type' is a 'System.Int32', which cannot be assigned to type 'System.Collections.IEnumerable'." + + "\r\nParameter name: expression.Type")); } [Test] @@ -63,12 +65,15 @@ public void Resolve_ReplacesParameter_WithQuerySourceReference () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Cannot retrieve an IQuerySource for the given MainSourceExpressionNode. " - + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")] public void Resolve_WithoutClause () { var expression = ExpressionHelper.CreateLambdaExpression (i => i > 5); - _node.Resolve (expression.Parameters[0], expression.Body, ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (expression.Parameters[0], expression.Body, ClauseGenerationContext), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Cannot retrieve an IQuerySource for the given MainSourceExpressionNode. " + + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")); } [Test] @@ -86,10 +91,11 @@ public void Apply () } [Test] - [ExpectedException(typeof(ArgumentException))] public void Apply_Throws () { - _node.Apply (QueryModel, ClauseGenerationContext); + Assert.That ( + () => _node.Apply (QueryModel, ClauseGenerationContext), + Throws.ArgumentException); } } } diff --git a/UnitTests/Parsing/Structure/IntermediateModel/MaxExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/MaxExpressionNodeTest.cs index bb6257fa1..0efdf2949 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/MaxExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/MaxExpressionNodeTest.cs @@ -72,11 +72,13 @@ public void GetSupportedMethods () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "MaxExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "MaxExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/MethodCallExpressionNodeFactoryTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/MethodCallExpressionNodeFactoryTest.cs index fdaa151c7..e9de6c853 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/MethodCallExpressionNodeFactoryTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/MethodCallExpressionNodeFactoryTest.cs @@ -69,54 +69,64 @@ public void CreateExpressionNode_OnlyOnePublicInstanceCtor () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'nodeType' is a 'Remotion.Linq.UnitTests.Parsing.Structure.IntermediateModel.MethodCallExpressionNodeFactoryTest', " - + "which cannot be assigned to type 'Remotion.Linq.Parsing.Structure.IntermediateModel.IExpressionNode'." - + "\r\nParameter name: nodeType")] public void CreateExpressionNode_InvalidType () { - MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (MethodCallExpressionNodeFactoryTest), _parseInfo, new object[0]); + Assert.That ( + () => MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (MethodCallExpressionNodeFactoryTest), _parseInfo, new object[0]), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'nodeType' is a 'Remotion.Linq.UnitTests.Parsing.Structure.IntermediateModel.MethodCallExpressionNodeFactoryTest', " + + "which cannot be assigned to type 'Remotion.Linq.Parsing.Structure.IntermediateModel.IExpressionNode'." + + "\r\nParameter name: nodeType")); } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Expression node type 'Remotion.Linq.UnitTests.Parsing.Structure.IntermediateModel.TestDomain.ExpressionNodeWithTooManyCtors' " - + "contains too many constructors. It must only contain a single constructor, allowing null to be passed for any optional arguments." - + "\r\nParameter name: nodeType")] public void CreateExpressionNode_MoreThanOneCtor () { - MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (ExpressionNodeWithTooManyCtors), _parseInfo, new object[0]); + Assert.That ( + () => MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (ExpressionNodeWithTooManyCtors), _parseInfo, new object[0]), + Throws.ArgumentException + .With.Message.EqualTo ( + "Expression node type 'Remotion.Linq.UnitTests.Parsing.Structure.IntermediateModel.TestDomain.ExpressionNodeWithTooManyCtors' " + + "contains too many constructors. It must only contain a single constructor, allowing null to be passed for any optional arguments." + + "\r\nParameter name: nodeType")); } [Test] - [ExpectedException (typeof (ExpressionNodeInstantiationException), ExpectedMessage = - "The constructor of expression node type 'Remotion.Linq.Parsing.Structure.IntermediateModel.SelectExpressionNode' " - + "only takes 2 parameters, but you specified 3 (including the parse info parameter).")] public void CreateExpressionNode_TooManyParameters () { var selector = ExpressionHelper.CreateLambdaExpression (); - MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (SelectExpressionNode), _parseInfo, new object[] { selector, selector }); + Assert.That ( + () => MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (SelectExpressionNode), _parseInfo, new object[] { selector, selector }), + Throws.InstanceOf() + .With.Message.EqualTo ( + "The constructor of expression node type 'Remotion.Linq.Parsing.Structure.IntermediateModel.SelectExpressionNode' " + + "only takes 2 parameters, but you specified 3 (including the parse info parameter).")); } [Test] - [ExpectedException (typeof (ExpressionNodeInstantiationException), ExpectedMessage = - "The given arguments did not match the expected arguments: Object of type " - + "'Remotion.Linq.Development.UnitTesting.Clauses.Expressions.ReducibleExtensionExpression' cannot be converted to type " - + "'System.Linq.Expressions.LambdaExpression'.")] public void CreateExpressionNode_InvalidNodeParameterType () { var selector = new ReducibleExtensionExpression (Expression.Constant (0)); - MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (SelectExpressionNode), _parseInfo, new object[] { selector }); + Assert.That ( + () => MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (SelectExpressionNode), _parseInfo, new object[] { selector }), + Throws.InstanceOf() + .With.Message.EqualTo ( + "The given arguments did not match the expected arguments: Object of type " + + "'Remotion.Linq.Development.UnitTesting.Clauses.Expressions.ReducibleExtensionExpression' cannot be converted to type " + + "'System.Linq.Expressions.LambdaExpression'.")); } [Test] - [ExpectedException (typeof (ExpressionNodeInstantiationException), ExpectedMessage = - "Object of type 'System.Linq.Expressions.ConstantExpression' cannot be converted to type 'System.Linq.Expressions.LambdaExpression'. " - + "If you tried to pass a delegate instead of a LambdaExpression, this is not supported because delegates are not parsable expressions.")] public void CreateExpressionNode_InvalidNodeParameterType_ConstantDelegateInsteadOfLambda () { var selector = Expression.Constant ((Func) (i => i)); - MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (SelectExpressionNode), _parseInfo, new object[] { selector }); + Assert.That ( + () => MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (SelectExpressionNode), _parseInfo, new object[] { selector }), + Throws.InstanceOf() + .With.Message.EqualTo ( + "Object of type 'System.Linq.Expressions.ConstantExpression' cannot be converted to type 'System.Linq.Expressions.LambdaExpression'. " + + "If you tried to pass a delegate instead of a LambdaExpression, this is not supported because delegates are not parsable expressions.")); } } } diff --git a/UnitTests/Parsing/Structure/IntermediateModel/MinExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/MinExpressionNodeTest.cs index 50e6ce1c2..ef67be7f9 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/MinExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/MinExpressionNodeTest.cs @@ -72,11 +72,13 @@ public void GetSupportedMethods () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "MinExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "MinExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/QuerySourceExpressionNodeUtilityTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/QuerySourceExpressionNodeUtilityTest.cs index f4ca27cd6..4800b15d1 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/QuerySourceExpressionNodeUtilityTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/QuerySourceExpressionNodeUtilityTest.cs @@ -48,11 +48,14 @@ public void GetQuerySourceForNode () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Cannot retrieve an IQuerySource for the given MainSourceExpressionNode. " - + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")] public void GetQuerySourceForNode_NoClauseRegistered () { - QuerySourceExpressionNodeUtility.GetQuerySourceForNode (_node, _context); + Assert.That ( + () => QuerySourceExpressionNodeUtility.GetQuerySourceForNode (_node, _context), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Cannot retrieve an IQuerySource for the given MainSourceExpressionNode. " + + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")); } [Test] @@ -70,13 +73,16 @@ public void ReplaceParameterWithReference () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Cannot retrieve an IQuerySource for the given MainSourceExpressionNode. " - + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")] public void ReplaceParameterWithReference_NoClauseRegistered () { var parameter = Expression.Parameter (typeof (int), "x"); var expression = Expression.MakeBinary (ExpressionType.Add, Expression.Constant (1), parameter); - QuerySourceExpressionNodeUtility.ReplaceParameterWithReference (_node, parameter, expression, _context); + Assert.That ( + () => QuerySourceExpressionNodeUtility.ReplaceParameterWithReference (_node, parameter, expression, _context), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Cannot retrieve an IQuerySource for the given MainSourceExpressionNode. " + + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")); } } } diff --git a/UnitTests/Parsing/Structure/IntermediateModel/SelectManyExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/SelectManyExpressionNodeTest.cs index e1851ca49..b48a7f585 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/SelectManyExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/SelectManyExpressionNodeTest.cs @@ -116,11 +116,14 @@ public void GetResolvedResultSelector () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = "Cannot retrieve an IQuerySource for the given SelectManyExpressionNode. " - + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")] public void GetResolvedResultSelector_WithoutClause () { - _nodeWithResultSelector.GetResolvedResultSelector (ClauseGenerationContext); + Assert.That ( + () => _nodeWithResultSelector.GetResolvedResultSelector (ClauseGenerationContext), + Throws.InvalidOperationException + .With.Message.EqualTo ( + "Cannot retrieve an IQuerySource for the given SelectManyExpressionNode. " + + "Be sure to call Apply before calling methods that require IQuerySources, and pass in the same QuerySourceClauseMapping to both.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/SingleExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/SingleExpressionNodeTest.cs index e6e2524e9..b4a17a425 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/SingleExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/SingleExpressionNodeTest.cs @@ -58,11 +58,13 @@ public void GetSupportedMethods () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "SingleExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression (), ExpressionHelper.CreateExpression (), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "SingleExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/SumExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/SumExpressionNodeTest.cs index 19672ddaf..030e743ed 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/SumExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/SumExpressionNodeTest.cs @@ -87,11 +87,13 @@ public void GetSupportedMethods () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "SumExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")] public void Resolve_ThrowsInvalidOperationException () { - _node.Resolve (ExpressionHelper.CreateParameterExpression(), ExpressionHelper.CreateExpression(), ClauseGenerationContext); + Assert.That ( + () => _node.Resolve (ExpressionHelper.CreateParameterExpression(), ExpressionHelper.CreateExpression(), ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ( + "SumExpressionNode does not support resolving of expressions, because it does not stream any data to the following node.")); } [Test] diff --git a/UnitTests/Parsing/Structure/IntermediateModel/ThenByDescendingExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/ThenByDescendingExpressionNodeTest.cs index 51c89c720..8078d3815 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/ThenByDescendingExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/ThenByDescendingExpressionNodeTest.cs @@ -105,20 +105,22 @@ public void Apply_UsesLastClause () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "ThenByDescending expressions must follow OrderBy, OrderByDescending, ThenBy, or ThenByDescending expressions.")] public void Apply_NoPreviousClause () { - _node.Apply (QueryModel, ClauseGenerationContext); + Assert.That ( + () => _node.Apply (QueryModel, ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ("ThenByDescending expressions must follow OrderBy, OrderByDescending, ThenBy, or ThenByDescending expressions.")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "ThenByDescending expressions must follow OrderBy, OrderByDescending, ThenBy, or ThenByDescending expressions.")] public void Apply_InvalidPreviousClause () { QueryModel.BodyClauses.Add (new WhereClause (ExpressionHelper.CreateExpression ())); - _node.Apply (QueryModel, ClauseGenerationContext); + Assert.That ( + () => _node.Apply (QueryModel, ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ("ThenByDescending expressions must follow OrderBy, OrderByDescending, ThenBy, or ThenByDescending expressions.")); } } } diff --git a/UnitTests/Parsing/Structure/IntermediateModel/ThenByExpressionNodeTest.cs b/UnitTests/Parsing/Structure/IntermediateModel/ThenByExpressionNodeTest.cs index ca61c38aa..3b3906942 100644 --- a/UnitTests/Parsing/Structure/IntermediateModel/ThenByExpressionNodeTest.cs +++ b/UnitTests/Parsing/Structure/IntermediateModel/ThenByExpressionNodeTest.cs @@ -105,20 +105,22 @@ public void Apply_UsesLastClause () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "ThenByDescending expressions must follow OrderBy, OrderByDescending, ThenBy, or ThenByDescending expressions.")] public void Apply_NoPreviousClause () { - _node.Apply (QueryModel, ClauseGenerationContext); + Assert.That ( + () => _node.Apply (QueryModel, ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ("ThenByDescending expressions must follow OrderBy, OrderByDescending, ThenBy, or ThenByDescending expressions.")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "ThenByDescending expressions must follow OrderBy, OrderByDescending, ThenBy, or ThenByDescending expressions.")] public void Apply_InvalidPreviousClause () { QueryModel.BodyClauses.Add (new WhereClause (ExpressionHelper.CreateExpression ())); - _node.Apply (QueryModel, ClauseGenerationContext); + Assert.That ( + () => _node.Apply (QueryModel, ClauseGenerationContext), + Throws.InstanceOf() + .With.Message.EqualTo ("ThenByDescending expressions must follow OrderBy, OrderByDescending, ThenBy, or ThenByDescending expressions.")); } } } diff --git a/UnitTests/Parsing/Structure/MethodCallExpressionParserTest.cs b/UnitTests/Parsing/Structure/MethodCallExpressionParserTest.cs index 24904ebde..d78dcd6d9 100644 --- a/UnitTests/Parsing/Structure/MethodCallExpressionParserTest.cs +++ b/UnitTests/Parsing/Structure/MethodCallExpressionParserTest.cs @@ -202,13 +202,14 @@ public void Parse_WithSubQuery_UsesNodeTypeRegistry () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "Could not parse expression 'q.First()': This overload of the method 'System.Linq.Queryable.First' is currently not supported.")] public void Parse_UnknownMethod_ThrowsNotSupportedException () { var methodCallExpression = (MethodCallExpression) ExpressionHelper.MakeExpression, int> (q => q.First()); - - ParseMethodCallExpression (methodCallExpression); + Assert.That ( + () => ParseMethodCallExpression (methodCallExpression), + Throws.InstanceOf() + .With.Message.EqualTo ( + "Could not parse expression 'q.First()': This overload of the method 'System.Linq.Queryable.First' is currently not supported.")); } [Test] @@ -222,14 +223,15 @@ public void Parse_UnknownMethod_ExceptionCanBeSerialized () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "Could not parse expression 'q.Select((i, j) => i)': This overload of the method 'System.Linq.Queryable.Select' is currently not supported.")] public void Parse_UnknownOverload_ThrowsNotSupportedException () { var methodCallExpression = (MethodCallExpression) ExpressionHelper.MakeExpression, IQueryable> (q => q.Select ((i, j) => i)); - - ParseMethodCallExpression (methodCallExpression); + Assert.That ( + () => ParseMethodCallExpression (methodCallExpression), + Throws.InstanceOf() + .With.Message.EqualTo ( + "Could not parse expression 'q.Select((i, j) => i)': This overload of the method 'System.Linq.Queryable.Select' is currently not supported.")); } [Test] @@ -244,10 +246,6 @@ public void Parse_UnknownOverload_ExceptionCanBeSerialized () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "Could not parse expression 'q.Select(value(System.Func`2[System.Int32,System.Int32]))': " - + "Object of type 'System.Linq.Expressions.ConstantExpression' cannot be converted to type 'System.Linq.Expressions.LambdaExpression'. " - + "If you tried to pass a delegate instead of a LambdaExpression, this is not supported because delegates are not parsable expressions.")] public void Parse_InvalidParameters_ThrowsNotSupportedException () { Func func = i => i; @@ -255,8 +253,13 @@ public void Parse_InvalidParameters_ThrowsNotSupportedException () PartialEvaluatingExpressionVisitor.EvaluateIndependentSubtrees ( ExpressionHelper.MakeExpression, IEnumerable> (q => q.Select (func)), new TestEvaluatableExpressionFilter()); - - ParseMethodCallExpression (methodCallExpression); + Assert.That ( + () => ParseMethodCallExpression (methodCallExpression), + Throws.InstanceOf() + .With.Message.EqualTo ( + "Could not parse expression 'q.Select(value(System.Func`2[System.Int32,System.Int32]))': " + + "Object of type 'System.Linq.Expressions.ConstantExpression' cannot be converted to type 'System.Linq.Expressions.LambdaExpression'. " + + "If you tried to pass a delegate instead of a LambdaExpression, this is not supported because delegates are not parsable expressions.")); } [Test] diff --git a/UnitTests/Parsing/Structure/QueryParserIntegrationTests/DelegateInvocationQueryParserIntegrationTest.cs b/UnitTests/Parsing/Structure/QueryParserIntegrationTests/DelegateInvocationQueryParserIntegrationTest.cs index 51b773b0b..24b38d4fd 100644 --- a/UnitTests/Parsing/Structure/QueryParserIntegrationTests/DelegateInvocationQueryParserIntegrationTest.cs +++ b/UnitTests/Parsing/Structure/QueryParserIntegrationTests/DelegateInvocationQueryParserIntegrationTest.cs @@ -27,15 +27,17 @@ namespace Remotion.Linq.UnitTests.Parsing.Structure.QueryParserIntegrationTests public class DelegateInvocationQueryParserIntegrationTest : QueryParserIntegrationTestBase { [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = - "Could not parse expression 'c.Assistants.Select(value(System.Func`2[Remotion.Linq.UnitTests.TestDomain.Cook,System.String]))': " - + "Object of type 'System.Linq.Expressions.ConstantExpression' cannot be converted to type 'System.Linq.Expressions.LambdaExpression'. " - + "If you tried to pass a delegate instead of a LambdaExpression, this is not supported because delegates are not parsable expressions.")] public void DelegateAsSelector () { Func expression = c => c.FirstName; var query = QuerySource.Select (c => c.Assistants.Select (expression)); - QueryParser.GetParsedQuery (query.Expression); + Assert.That ( + () => QueryParser.GetParsedQuery (query.Expression), + Throws.InstanceOf() + .With.Message.EqualTo ( + "Could not parse expression 'c.Assistants.Select(value(System.Func`2[Remotion.Linq.UnitTests.TestDomain.Cook,System.String]))': " + + "Object of type 'System.Linq.Expressions.ConstantExpression' cannot be converted to type 'System.Linq.Expressions.LambdaExpression'. " + + "If you tried to pass a delegate instead of a LambdaExpression, this is not supported because delegates are not parsable expressions.")); } [Test] diff --git a/UnitTests/Parsing/ThrowingExpressionVisitorTest.cs b/UnitTests/Parsing/ThrowingExpressionVisitorTest.cs index 63d8a43f0..3003db84e 100644 --- a/UnitTests/Parsing/ThrowingExpressionVisitorTest.cs +++ b/UnitTests/Parsing/ThrowingExpressionVisitorTest.cs @@ -54,7 +54,6 @@ public void VisitExtension_ReducedExpressionIsVisited () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitExtension: Test")] public void VisitExtension_NonReducibleExpression () { RelinqExpressionVisitor visitor = new TestThrowingConstantExpressionVisitor (); @@ -70,19 +69,22 @@ public void VisitExtension_NonReducibleExpression () .Return (nonReducibleExpression); nonReducibleExpression.Stub (stub => stub.CanReduce).Return (false); nonReducibleExpression.Stub (stub => stub.ToString ()).Return ("Test"); - - visitor.Visit (nonReducibleExpression); + Assert.That ( + () => visitor.Visit (nonReducibleExpression), + Throws.InstanceOf() + .With.Message.EqualTo ("Test of VisitExtension: Test")); } [Test] -#if !NET_3_5 - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitExtension: [-1]")] #else [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitUnknownNonExtension: [-1]")] #endif public void VisitUnknownNonExtension () { - Visit (_visitor, (ExpressionType) (-1)); + Assert.That ( + () => Visit (_visitor, (ExpressionType) (-1)), + Throws.InstanceOf() + .With.Message.EqualTo ("Test of VisitExtension: [-1]")); } [Test] @@ -93,45 +95,57 @@ public void Visit_Null () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitUnary", MatchType = MessageMatch.Contains)] public void VisitUnary () { - Visit (_visitor, ExpressionType.UnaryPlus); + Assert.That ( + () => Visit (_visitor, ExpressionType.UnaryPlus), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitUnary")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitBinary: ", MatchType = MessageMatch.Contains)] public void VisitBinary () { - Visit (_visitor, ExpressionType.And); + Assert.That ( + () => Visit (_visitor, ExpressionType.And), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitBinary: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitTypeBinary: ", MatchType = MessageMatch.Contains)] public void VisitTypeBinary () { - Visit (_visitor, ExpressionType.TypeIs); + Assert.That ( + () => Visit (_visitor, ExpressionType.TypeIs), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitTypeBinary: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitConstant: ", MatchType = MessageMatch.Contains)] public void VisitConstant () { - Visit (_visitor, ExpressionType.Constant); + Assert.That ( + () => Visit (_visitor, ExpressionType.Constant), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitConstant: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitConditional: ", MatchType = MessageMatch.Contains)] public void VisitConditional () { - Visit (_visitor, ExpressionType.Conditional); + Assert.That ( + () => Visit (_visitor, ExpressionType.Conditional), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitConditional: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitParameter: ", MatchType = MessageMatch.Contains)] public void VisitParameter () { - Visit (_visitor, ExpressionType.Parameter); + Assert.That ( + () => Visit (_visitor, ExpressionType.Parameter), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitParameter: ")); } [Test] @@ -145,189 +159,241 @@ public void VisitLambda () } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitMethodCall: ", MatchType = MessageMatch.Contains)] public void VisitMethodCall () { - Visit (_visitor, ExpressionType.Call); + Assert.That ( + () => Visit (_visitor, ExpressionType.Call), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitMethodCall: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitInvocation: ", MatchType = MessageMatch.Contains)] public void VisitInvocation () { - Visit (_visitor, ExpressionType.Invoke); + Assert.That ( + () => Visit (_visitor, ExpressionType.Invoke), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitInvocation: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitMember: ", MatchType = MessageMatch.Contains)] public void VisitMember () { - Visit (_visitor, ExpressionType.MemberAccess); + Assert.That ( + () => Visit (_visitor, ExpressionType.MemberAccess), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitMember: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitNew: ", MatchType = MessageMatch.Contains)] public void VisitNew () { - Visit (_visitor, ExpressionType.New); + Assert.That ( + () => Visit (_visitor, ExpressionType.New), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitNew: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitNewArray: ", MatchType = MessageMatch.Contains)] public void VisitNewArray () { - Visit (_visitor, ExpressionType.NewArrayInit); + Assert.That ( + () => Visit (_visitor, ExpressionType.NewArrayInit), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitNewArray: ")); } #if !NET_3_5 [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitBlock: ", MatchType = MessageMatch.Contains)] public void VisitBlock () { - Visit (_visitor, ExpressionType.Block); + Assert.That ( + () => Visit (_visitor, ExpressionType.Block), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitBlock: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitDebugInfo: ", MatchType = MessageMatch.Contains)] public void VisitDebugInfo () { - Visit (_visitor, ExpressionType.DebugInfo); + Assert.That ( + () => Visit (_visitor, ExpressionType.DebugInfo), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitDebugInfo: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitDefault: ", MatchType = MessageMatch.Contains)] public void VisitDefaultExpression () { - _visitor.Visit (Expression.Default (typeof (int))); + Assert.That ( + () => _visitor.Visit (Expression.Default (typeof (int))), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitDefault: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitGoto: ", MatchType = MessageMatch.Contains)] public void VisitGoto () { - Visit (_visitor, ExpressionType.Goto); + Assert.That ( + () => Visit (_visitor, ExpressionType.Goto), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitGoto: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitIndex: ", MatchType = MessageMatch.Contains)] public void VisitIndex () { - Visit (_visitor, ExpressionType.Index); + Assert.That ( + () => Visit (_visitor, ExpressionType.Index), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitIndex: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitLabel: ", MatchType = MessageMatch.Contains)] public void VisitLabel () { - Visit (_visitor, ExpressionType.Label); + Assert.That ( + () => Visit (_visitor, ExpressionType.Label), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitLabel: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitLoop: ", MatchType = MessageMatch.Contains)] public void VisitLoop () { - Visit (_visitor, ExpressionType.Loop); + Assert.That ( + () => Visit (_visitor, ExpressionType.Loop), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitLoop: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitRuntimeVariables: ", MatchType = MessageMatch.Contains)] public void VisitRuntimeVariables () { - Visit (_visitor, ExpressionType.RuntimeVariables); + Assert.That ( + () => Visit (_visitor, ExpressionType.RuntimeVariables), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitRuntimeVariables: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitSwitch: ", MatchType = MessageMatch.Contains)] public void VisitSwitch () { - Visit (_visitor, ExpressionType.Switch); + Assert.That ( + () => Visit (_visitor, ExpressionType.Switch), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitSwitch: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitTry: ", MatchType = MessageMatch.Contains)] public void VisitTry () { - Visit (_visitor, ExpressionType.Try); + Assert.That ( + () => Visit (_visitor, ExpressionType.Try), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitTry: ")); } #endif [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitMemberInit: ", MatchType = MessageMatch.Contains)] public void VisitMemberInit () { - Visit (_visitor, ExpressionType.MemberInit); + Assert.That ( + () => Visit (_visitor, ExpressionType.MemberInit), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitMemberInit: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitListInit: ", MatchType = MessageMatch.Contains)] public void VisitListInit () { - Visit (_visitor, ExpressionType.ListInit); + Assert.That ( + () => Visit (_visitor, ExpressionType.ListInit), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitListInit: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitElementInit: ", MatchType = MessageMatch.Contains)] public void VisitElementInit () { - _visitor.VisitElementInit (ExpressionInstanceCreator.CreateElementInit()); + Assert.That ( + () => _visitor.VisitElementInit (ExpressionInstanceCreator.CreateElementInit()), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitElementInit: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitMemberAssignment: ", MatchType = MessageMatch.Contains)] public void VisitMemberAssignment () { - _visitor.VisitMemberBinding (ExpressionInstanceCreator.CreateMemberAssignment ()); + Assert.That ( + () => _visitor.VisitMemberBinding (ExpressionInstanceCreator.CreateMemberAssignment ()), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitMemberAssignment: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitMemberMemberBinding: ", MatchType = MessageMatch.Contains)] public void VisitMemberMemberBinding () { - _visitor.VisitMemberBinding (ExpressionInstanceCreator.CreateMemberMemberBinding (new MemberBinding[0])); + Assert.That ( + () => _visitor.VisitMemberBinding (ExpressionInstanceCreator.CreateMemberMemberBinding (new MemberBinding[0])), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitMemberMemberBinding: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitMemberListBinding: ", MatchType = MessageMatch.Contains)] public void VisitMemberListBinding () { - _visitor.VisitMemberBinding (ExpressionInstanceCreator.CreateMemberListBinding (new ElementInit[0])); + Assert.That ( + () => _visitor.VisitMemberBinding (ExpressionInstanceCreator.CreateMemberListBinding (new ElementInit[0])), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitMemberListBinding: ")); } #if !NET_3_5 [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitCatchBlock: ", MatchType = MessageMatch.Contains)] public void VisitCatchBlock () { - _visitor.VisitCatchBlock (ExpressionInstanceCreator.CreateCatchBlock()); + Assert.That ( + () => _visitor.VisitCatchBlock (ExpressionInstanceCreator.CreateCatchBlock()), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitCatchBlock: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitLabelTarget: ", MatchType = MessageMatch.Contains)] public void VisitLabelTarget () { - _visitor.VisitLabelTarget (ExpressionInstanceCreator.CreateLabelTarget()); + Assert.That ( + () => _visitor.VisitLabelTarget (ExpressionInstanceCreator.CreateLabelTarget()), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitLabelTarget: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitSwitchCase: ", MatchType = MessageMatch.Contains)] public void VisitSwitchCase () { - _visitor.VisitSwitchCase (ExpressionInstanceCreator.CreateSwitchCase()); + Assert.That ( + () => _visitor.VisitSwitchCase (ExpressionInstanceCreator.CreateSwitchCase()), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitSwitchCase: ")); } #endif [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitSubQuery: ", MatchType = MessageMatch.Contains)] public void VisitSubQuery () { - _visitor.Visit (new SubQueryExpression (ExpressionHelper.CreateQueryModel ())); + Assert.That ( + () => _visitor.Visit (new SubQueryExpression (ExpressionHelper.CreateQueryModel ())), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitSubQuery: ")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Test of VisitQuerySourceReference: ", MatchType = MessageMatch.Contains)] public void VisitQuerySourceReference () { - _visitor.Visit (new QuerySourceReferenceExpression (ExpressionHelper.CreateMainFromClause_Int ())); + Assert.That ( + () => _visitor.Visit (new QuerySourceReferenceExpression (ExpressionHelper.CreateMainFromClause_Int ())), + Throws.InstanceOf() + .With.Message.Contains ("Test of VisitQuerySourceReference: ")); } private void Visit (TestThrowingExpressionVisitor visitor, ExpressionType nodeType) diff --git a/UnitTests/QueryModelBuilderTest.cs b/UnitTests/QueryModelBuilderTest.cs index 4b5872e20..e0540b5ff 100644 --- a/UnitTests/QueryModelBuilderTest.cs +++ b/UnitTests/QueryModelBuilderTest.cs @@ -62,11 +62,12 @@ public void AddClause_SelectClause () } [Test] - [ExpectedException (typeof (InvalidOperationException))] public void AddClause_SelectClause_Twice () { _builder.AddClause (_selectClause); - _builder.AddClause (_selectClause); + Assert.That ( + () => _builder.AddClause (_selectClause), + Throws.InvalidOperationException); } [Test] @@ -78,11 +79,12 @@ public void AddClause_MainFromClause () } [Test] - [ExpectedException (typeof (InvalidOperationException))] public void AddClause_MainFromClause_Twice () { _builder.AddClause (_mainFromClause); - _builder.AddClause (_mainFromClause); + Assert.That ( + () => _builder.AddClause (_mainFromClause), + Throws.InvalidOperationException); } [Test] @@ -131,25 +133,25 @@ public void Build () } [Test] - [ExpectedException (typeof (InvalidOperationException))] public void Build_WithoutMainFromClause () { _builder.AddClause (_whereClause1); _builder.AddClause (_whereClause2); _builder.AddClause (_selectClause); - - _builder.Build (); + Assert.That ( + () => _builder.Build (), + Throws.InvalidOperationException); } [Test] - [ExpectedException (typeof (InvalidOperationException))] public void Build_WithoutSelectOrGroupClause () { _builder.AddClause (_whereClause1); _builder.AddClause (_whereClause2); _builder.AddClause (_mainFromClause); - - _builder.Build (); + Assert.That ( + () => _builder.Build (), + Throws.InvalidOperationException); } } } diff --git a/UnitTests/QueryModelTest.cs b/UnitTests/QueryModelTest.cs index e632db7b8..015a1f6d8 100644 --- a/UnitTests/QueryModelTest.cs +++ b/UnitTests/QueryModelTest.cs @@ -497,10 +497,11 @@ public void SelectOrGroupClause_Set () } [Test] - [ExpectedException (typeof (ArgumentNullException))] public void SelectOrGroupClause_Set_Null () { - _queryModel.SelectClause = null; + Assert.That ( + () => _queryModel.SelectClause = null, + Throws.ArgumentNullException); } [Test] @@ -606,34 +607,38 @@ public void AddBodyClause () } [Test] - [ExpectedException (typeof (ArgumentNullException))] public void AddBodyClause_Null () { - _queryModel.BodyClauses.Add (null); + Assert.That ( + () => _queryModel.BodyClauses.Add (null), + Throws.ArgumentNullException); } [Test] - [ExpectedException (typeof (ArgumentNullException))] public void SetBodyClause_Null () { _queryModel.BodyClauses.Add (ExpressionHelper.CreateWhereClause()); - _queryModel.BodyClauses[0] = null; + Assert.That ( + () => _queryModel.BodyClauses[0] = null, + Throws.ArgumentNullException); } [Test] - [ExpectedException (typeof (ArgumentNullException))] public void AddResultOperator_Null_ThrowsArgumentNullException () { - _queryModel.ResultOperators.Add (null); + Assert.That ( + () => _queryModel.ResultOperators.Add (null), + Throws.ArgumentNullException); } [Test] - [ExpectedException (typeof (ArgumentNullException))] public void SetResultOperator_Null_ThrowsArgumentNullException () { var resultOperator = new DistinctResultOperator (); _queryModel.ResultOperators.Add (resultOperator); - _queryModel.ResultOperators[0] = null; + Assert.That ( + () => _queryModel.ResultOperators[0] = null, + Throws.ArgumentNullException); } [Test] @@ -717,14 +722,14 @@ public void ConvertToSubquery_CovariantSubquery () } [Test] - [ExpectedException (typeof (InvalidOperationException), ExpectedMessage = - "The query must return a sequence of items, but it selects a single object of type 'System.Int32'.")] public void ConvertToSubquery_NoStreamedSequenceInfo () { var queryModel = new QueryModel (_mainFromClause, new SelectClause (new QuerySourceReferenceExpression (_mainFromClause))); queryModel.ResultOperators.Add (new CountResultOperator()); - - queryModel.ConvertToSubQuery ("test"); + Assert.That ( + () => queryModel.ConvertToSubQuery ("test"), + Throws.InvalidOperationException + .With.Message.EqualTo ("The query must return a sequence of items, but it selects a single object of type 'System.Int32'.")); } } } diff --git a/UnitTests/QueryProviderBaseTest.cs b/UnitTests/QueryProviderBaseTest.cs index f11ce081d..ebce1acbe 100644 --- a/UnitTests/QueryProviderBaseTest.cs +++ b/UnitTests/QueryProviderBaseTest.cs @@ -72,12 +72,14 @@ public void CreateQueryReturnsIQueryable() } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Expected a closed generic type implementing IEnumerable, but found 'System.Func`1[System.Int32]'.\r\nParameter name: expression")] public void CreateQuery_NonEnumerableExpression () { Expression expression = ExpressionHelper.CreateLambdaExpression (); - _queryProvider.CreateQuery (expression); + Assert.That ( + () => _queryProvider.CreateQuery (expression), + Throws.ArgumentException + .With.Message.EqualTo ( + "Expected a closed generic type implementing IEnumerable, but found 'System.Func`1[System.Int32]'.\r\nParameter name: expression")); } [Test] diff --git a/UnitTests/QueryableBaseTest.cs b/UnitTests/QueryableBaseTest.cs index 06e8ca00f..805e0f028 100644 --- a/UnitTests/QueryableBaseTest.cs +++ b/UnitTests/QueryableBaseTest.cs @@ -81,12 +81,14 @@ public void Initialize_WithParserAndExecutor () } [Test] - [ExpectedException (typeof (ArgumentException), ExpectedMessage = - "Parameter 'expression' is a 'System.Int32[]', which cannot be assigned to type 'System.Collections.Generic.IEnumerable`1[System.String]'." - + "\r\nParameter name: expression")] public void ConstructorThrowsTypeException () { - new TestQueryable (_providerMock, _intArrayExpression); + Assert.That ( + () => new TestQueryable (_providerMock, _intArrayExpression), + Throws.ArgumentException + .With.Message.EqualTo ( + "Parameter 'expression' is a 'System.Int32[]', which cannot be assigned to type 'System.Collections.Generic.IEnumerable`1[System.String]'." + + "\r\nParameter name: expression")); } [Test] diff --git a/UnitTests/Transformations/SubQueryFromClauseFlattenerTest.cs b/UnitTests/Transformations/SubQueryFromClauseFlattenerTest.cs index 882943f7e..93417576e 100644 --- a/UnitTests/Transformations/SubQueryFromClauseFlattenerTest.cs +++ b/UnitTests/Transformations/SubQueryFromClauseFlattenerTest.cs @@ -134,21 +134,21 @@ public void VisitAdditionalFromClause_AdaptsReferencesToFromClause_WithInnerSele } [Test] - [ExpectedException (typeof(NotSupportedException), ExpectedMessage = "The subquery " - + "'TestQueryable() => Distinct()' cannot be flattened and pulled out of the from clause because it " - + "contains result operators.")] public void VisitAdditionalFromClause_ThrowsOnResultOperator () { var queryModel = ExpressionHelper.CreateQueryModel (); queryModel.ResultOperators.Add (new DistinctResultOperator ()); var clause = new AdditionalFromClause ("x", typeof (Cook), new SubQueryExpression (queryModel)); - _visitor.VisitAdditionalFromClause (clause, _queryModel, 0); + Assert.That ( + () => _visitor.VisitAdditionalFromClause (clause, _queryModel, 0), + Throws.InstanceOf() + .With.Message.EqualTo ( + "The subquery " + + "'TestQueryable() => Distinct()' cannot be flattened and pulled out of the from clause because it " + + "contains result operators.")); } [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "The subquery " - + "'from Cook s in TestQueryable() orderby 0 asc select [s]' cannot be flattened and pulled out of the from clause because it " - + "contains an OrderByClause.")] public void VisitAdditionalFromClause_ThrowsOnOrderBy () { var queryModel = ExpressionHelper.CreateQueryModel (); @@ -156,7 +156,13 @@ public void VisitAdditionalFromClause_ThrowsOnOrderBy () orderByClause.Orderings.Add (new Ordering (Expression.Constant (0), OrderingDirection.Asc)); queryModel.BodyClauses.Add (orderByClause); var clause = new AdditionalFromClause ("x", typeof (Cook), new SubQueryExpression (queryModel)); - _visitor.VisitAdditionalFromClause (clause, _queryModel, 0); + Assert.That ( + () => _visitor.VisitAdditionalFromClause (clause, _queryModel, 0), + Throws.InstanceOf() + .With.Message.EqualTo ( + "The subquery " + + "'from Cook s in TestQueryable() orderby 0 asc select [s]' cannot be flattened and pulled out of the from clause because it " + + "contains an OrderByClause.")); } [Test] diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index 750ee6de6..93cdd9039 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -103,8 +103,9 @@ - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + ..\packages\NUnit.2.7.1\lib\nunit.framework.dll + True ..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll diff --git a/UnitTests/Utilities/ReflectionUtilityTest.cs b/UnitTests/Utilities/ReflectionUtilityTest.cs index 1eba1cc95..1484779af 100644 --- a/UnitTests/Utilities/ReflectionUtilityTest.cs +++ b/UnitTests/Utilities/ReflectionUtilityTest.cs @@ -41,10 +41,11 @@ public void GetMethod_PropertyAccess () } [Test] - [ExpectedException (typeof (ArgumentException))] public void GetMethod_InvalidExpression () { - ReflectionUtility.GetMethod (() => "x"); + Assert.That ( + () => ReflectionUtility.GetMethod (() => "x"), + Throws.ArgumentException); } [Test] diff --git a/UnitTests/packages.config b/UnitTests/packages.config index 36da663b4..c76e89bb3 100644 --- a/UnitTests/packages.config +++ b/UnitTests/packages.config @@ -1,6 +1,6 @@  - + From dd46b0e891359b23dd0dc9bb59cc2db513fa835e Mon Sep 17 00:00:00 2001 From: "Frackiewicz, Fillip" Date: Wed, 20 May 2020 05:08:33 +0200 Subject: [PATCH 03/11] RMLNQ-129 Features=ExpectedException manual fixes --- ...pressionVisitor_SpecificExpressionsTest.cs | 65 ++++++++++--------- UnitTests/QueryModelTest.cs | 2 +- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/UnitTests.Net_3_5/Parsing/ExpressionVisitorTests/ExpressionVisitor_SpecificExpressionsTest.cs b/UnitTests.Net_3_5/Parsing/ExpressionVisitorTests/ExpressionVisitor_SpecificExpressionsTest.cs index 35efd73fe..830044305 100644 --- a/UnitTests.Net_3_5/Parsing/ExpressionVisitorTests/ExpressionVisitor_SpecificExpressionsTest.cs +++ b/UnitTests.Net_3_5/Parsing/ExpressionVisitorTests/ExpressionVisitor_SpecificExpressionsTest.cs @@ -447,8 +447,6 @@ public void VisitMemberInit_Unchanged () "When called from 'VisitMemberInit', rewriting a node of type 'System.Linq.Expressions.NewExpression' must return a non-null value of the same type. " + "Alternatively, override 'VisitMemberInit' and change it to not visit children of this type.")] #else - [ExpectedException (typeof (NotSupportedException), - ExpectedMessage = "MemberInitExpressions only support non-null instances of type 'NewExpression' as their NewExpression member.")] #endif public void VisitMemberInit_InvalidNewExpression () { @@ -456,14 +454,18 @@ public void VisitMemberInit_InvalidNewExpression () var binding = expression.Bindings.Single(); Expect.Call (VisitorMock.Visit (expression.NewExpression)).Return (Expression.Constant (0)); Expect.Call (InvokeVisitMethod ("VisitMemberBinding", binding)).Return (binding); - try - { - InvokeAndCheckVisit ("VisitMemberInit", expression); - } - catch (TargetInvocationException ex) - { - throw ex.InnerException; - } + Assert.Throws ( + () => + { + try + { + InvokeAndCheckVisit ("VisitMemberInit", expression); + } + catch (TargetInvocationException ex) + { + throw ex.InnerException; + } + }, "MemberInitExpressions only support non-null instances of type 'NewExpression' as their NewExpression member."); } [Test] @@ -515,8 +517,6 @@ public void VisitListInit_Unchanged () "When called from 'VisitListInit', rewriting a node of type 'System.Linq.Expressions.NewExpression' must return a non-null value of the same type. " + "Alternatively, override 'VisitListInit' and change it to not visit children of this type.")] #else - [ExpectedException (typeof (NotSupportedException), - ExpectedMessage = "ListInitExpressions only support non-null instances of type 'NewExpression' as their NewExpression member.")] #endif public void VisitListInit_InvalidNewExpression () { @@ -524,14 +524,18 @@ public void VisitListInit_InvalidNewExpression () var elementInit = expression.Initializers.Single(); Expect.Call (VisitorMock.Visit (expression.NewExpression)).Return (Expression.Constant (0)); Expect.Call (InvokeVisitMethod ("VisitElementInit", elementInit)).Return (elementInit); - try - { - InvokeAndCheckVisit ("VisitListInit", expression); - } - catch (TargetInvocationException ex) - { - throw ex.InnerException; - } + Assert.Throws ( + () => + { + try + { + InvokeAndCheckVisit ("VisitListInit", expression); + } + catch (TargetInvocationException ex) + { + throw ex.InnerException; + } + }, "ListInitExpressions only support non-null instances of type 'NewExpression' as their NewExpression member."); } [Test] @@ -722,21 +726,24 @@ public void VisitMemberListBinding_Changed () #if NET_3_5 [Test] - [ExpectedException (typeof (NotSupportedException), ExpectedMessage = "Expression type 'SpecialExpressionNode' is not supported by this ExpressionVisitor.*\\.", MatchType = MessageMatch.Regex)] public void VisitUnknownNonExtension () { var expressionNode = new SpecialExpressionNode ((ExpressionType) (-1), typeof (int)); Expect.Call (InvokeVisitMethod ("VisitUnknownNonExtension", expressionNode)).CallOriginalMethod (OriginalCallOptions.CreateExpectation); MockRepository.ReplayAll(); - try - { - InvokeVisitMethod ("VisitUnknownNonExtension", expressionNode); - } - catch (TargetInvocationException ex) - { - throw ex.InnerException; - } + Assert.Throws( + () => + { + try + { + InvokeVisitMethod ("VisitUnknownNonExtension", expressionNode); + } + catch (TargetInvocationException ex) + { + throw ex.InnerException; + } + }, "Expression type 'SpecialExpressionNode' is not supported by this ExpressionVisitor.*\\."); //TODO , MatchType = MessageMatch.Regex) } #endif diff --git a/UnitTests/QueryModelTest.cs b/UnitTests/QueryModelTest.cs index 015a1f6d8..32ccff8d5 100644 --- a/UnitTests/QueryModelTest.cs +++ b/UnitTests/QueryModelTest.cs @@ -501,7 +501,7 @@ public void SelectOrGroupClause_Set_Null () { Assert.That ( () => _queryModel.SelectClause = null, - Throws.ArgumentNullException); + Throws.ArgumentNullException); //TODO ArgumentNullException not a valid constraint? } [Test] From 2f9525ec21f03090e614378798795fc40e999d7f Mon Sep 17 00:00:00 2001 From: "Frackiewicz, Fillip" Date: Wed, 20 May 2020 05:09:48 +0200 Subject: [PATCH 04/11] RMLNQ-129 Features=AssertRenaming --- UnitTests/Parsing/Structure/ExpressionTreeParserTest.cs | 4 ++-- .../EmptyParametersQueryParserIntegrationTest.cs | 4 ++-- .../GroupByQueryParserIntegrationTest.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/UnitTests/Parsing/Structure/ExpressionTreeParserTest.cs b/UnitTests/Parsing/Structure/ExpressionTreeParserTest.cs index 23546d299..ca5fc946b 100644 --- a/UnitTests/Parsing/Structure/ExpressionTreeParserTest.cs +++ b/UnitTests/Parsing/Structure/ExpressionTreeParserTest.cs @@ -195,7 +195,7 @@ public void ParseTree_MethodCallExpression_GetsGeneratedIdentifier () var result = _expressionTreeParser.ParseTree (expression); - Assert.That (((SelectExpressionNode) result).AssociatedIdentifier, Is.StringStarting ("_")); + Assert.That (((SelectExpressionNode) result).AssociatedIdentifier, Does.StartWith ("_")); } [Test] @@ -227,7 +227,7 @@ public void ParseTree_MethodCallExpression_PropagatesNameToSourceNode_EmptyNameI var source = ((SelectExpressionNode) result).Source; Assert.That (source, Is.InstanceOf (typeof (MainSourceExpressionNode))); - Assert.That (((MainSourceExpressionNode) source).AssociatedIdentifier, Is.StringStarting ("_")); + Assert.That (((MainSourceExpressionNode) source).AssociatedIdentifier, Does.StartWith ("_")); } [Test] diff --git a/UnitTests/Parsing/Structure/QueryParserIntegrationTests/EmptyParametersQueryParserIntegrationTest.cs b/UnitTests/Parsing/Structure/QueryParserIntegrationTests/EmptyParametersQueryParserIntegrationTest.cs index e2fabd3fa..a497b885c 100644 --- a/UnitTests/Parsing/Structure/QueryParserIntegrationTests/EmptyParametersQueryParserIntegrationTest.cs +++ b/UnitTests/Parsing/Structure/QueryParserIntegrationTests/EmptyParametersQueryParserIntegrationTest.cs @@ -1,4 +1,4 @@ -// Copyright (c) rubicon IT GmbH, www.rubicon.eu +// Copyright (c) rubicon IT GmbH, www.rubicon.eu // // See the NOTICE file distributed with this work for additional information // regarding copyright ownership. rubicon licenses this file to you under @@ -47,7 +47,7 @@ public void EmptyParameterNames_CanBeParsed () var selectClause = queryModel.SelectClause; CheckResolvedExpression (selectClause.Selector, queryModel.MainFromClause, c => c.ID); - Assert.That (queryModel.MainFromClause.ItemName, Is.StringStarting ("_")); + Assert.That (queryModel.MainFromClause.ItemName, Does.StartWith ("_")); } } diff --git a/UnitTests/Parsing/Structure/QueryParserIntegrationTests/GroupByQueryParserIntegrationTest.cs b/UnitTests/Parsing/Structure/QueryParserIntegrationTests/GroupByQueryParserIntegrationTest.cs index 30e37d2db..fac7e3723 100644 --- a/UnitTests/Parsing/Structure/QueryParserIntegrationTests/GroupByQueryParserIntegrationTest.cs +++ b/UnitTests/Parsing/Structure/QueryParserIntegrationTests/GroupByQueryParserIntegrationTest.cs @@ -245,7 +245,7 @@ where x.Count() > 0 Assert.That (predicateLeftSide, Is.InstanceOf (typeof (SubQueryExpression))); var predicateSubQueryModel = ((SubQueryExpression) predicateLeftSide).QueryModel; Assert.That (predicateSubQueryModel.MainFromClause.ItemType, Is.SameAs (typeof (int))); - Assert.That (predicateSubQueryModel.MainFromClause.ItemName, Is.StringStarting ("")); + Assert.That (predicateSubQueryModel.MainFromClause.ItemName, Does.StartWith ("")); Assert.That (((QuerySourceReferenceExpression) predicateSubQueryModel.MainFromClause.FromExpression).ReferencedQuerySource, Is.SameAs (mainFromClause)); Assert.That (((QuerySourceReferenceExpression) predicateSubQueryModel.SelectClause.Selector).ReferencedQuerySource, Is.SameAs (predicateSubQueryModel.MainFromClause)); From 33ed645fb4ae108083865d1fbac6870281786188 Mon Sep 17 00:00:00 2001 From: "Frackiewicz, Fillip" Date: Wed, 20 May 2020 05:12:53 +0200 Subject: [PATCH 05/11] RMLNQ-129 NUnit3 to 3.12 --- .../Development.Net_3_5.UnitTests.csproj | 11 +++++++++-- Development.Net_3_5.UnitTests/packages.config | 2 +- .../Development.Net_4_0.UnitTests.csproj | 11 +++++++++-- Development.Net_4_0.UnitTests/packages.config | 2 +- Development.UnitTests/Development.UnitTests.csproj | 11 +++++++++-- Development.UnitTests/packages.config | 2 +- UnitTests.Net_3_5/UnitTests.Net_3_5.csproj | 11 +++++++++-- UnitTests.Net_3_5/packages.config | 2 +- UnitTests.Net_4_0/UnitTests.Net_4_0.csproj | 11 +++++++++-- UnitTests.Net_4_0/packages.config | 2 +- UnitTests.Net_4_5/UnitTests.Net_4_5.csproj | 11 +++++++++-- UnitTests.Net_4_5/packages.config | 2 +- UnitTests/UnitTests.csproj | 11 +++++++++-- UnitTests/packages.config | 2 +- 14 files changed, 70 insertions(+), 21 deletions(-) diff --git a/Development.Net_3_5.UnitTests/Development.Net_3_5.UnitTests.csproj b/Development.Net_3_5.UnitTests/Development.Net_3_5.UnitTests.csproj index 190808a04..030aaf1c0 100644 --- a/Development.Net_3_5.UnitTests/Development.Net_3_5.UnitTests.csproj +++ b/Development.Net_3_5.UnitTests/Development.Net_3_5.UnitTests.csproj @@ -1,5 +1,6 @@  + Debug @@ -41,8 +42,8 @@ ..\remotion.snk - - ..\packages\NUnit.2.7.1\lib\nunit.framework.dll + + ..\packages\NUnit.3.12.0\lib\net35\nunit.framework.dll True @@ -111,6 +112,12 @@ + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}. + + +