This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 6f9e42a44546d179859f2a60d8d07dac5e0be886 Author: Shad Storhaug <[email protected]> AuthorDate: Wed Dec 8 04:33:14 2021 +0700 SWEEP: Migrated all exception serialization tests to Lucene.Net.AllProjects and refactored to provide base classes for additional assembly scanning tests --- .../Support/ExceptionSerializationTestBase.cs | 61 --- .../Support/Util/LuceneTestCase.Serialization.cs | 7 +- .../Support/AssemblyScanningTestCase.cs | 91 ++++ .../ExceptionScanningTestCase.cs} | 512 ++------------------- .../ExceptionHandling/TestExceptionExtensions.cs | 428 +++++++++++++++++ .../TestExceptionSerialization.cs | 32 +- .../Support/TestExceptionSerialization.cs | 56 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 58 --- .../Support/TestExceptionSerialization.cs | 55 --- .../Support/TestExceptionSerialization.cs | 55 --- 29 files changed, 561 insertions(+), 1839 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Support/ExceptionSerializationTestBase.cs b/src/Lucene.Net.TestFramework/Support/ExceptionSerializationTestBase.cs deleted file mode 100644 index c5c0596..0000000 --- a/src/Lucene.Net.TestFramework/Support/ExceptionSerializationTestBase.cs +++ /dev/null @@ -1,61 +0,0 @@ -#if FEATURE_SERIALIZABLE -using System; -using System.Globalization; -using System.Reflection; -using Assert = Lucene.Net.TestFramework.Assert; - -namespace Lucene.Net.Util -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - public abstract class ExceptionSerializationTestBase : LuceneTestCase -#if TESTFRAMEWORK_XUNIT - , Xunit.IClassFixture<BeforeAfterClass> - { - public ExceptionSerializationTestBase(BeforeAfterClass beforeAfter) - : base(beforeAfter) - { - } -#else - { -#endif - - protected static object TryInstantiate(Type type) - { - object instance = null; - BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; - try - { - instance = Activator.CreateInstance(type, flags, null, new object[] { "A message" }, CultureInfo.InvariantCulture); - } - catch (MissingMethodException) - { - try - { - instance = Activator.CreateInstance(type, flags, null, null, CultureInfo.InvariantCulture); - } - catch (MissingMethodException) - { - Assert.Fail("Can't instantiate type {0}, it's missing the necessary constructors.", type.FullName); - } - } - return instance; - } - } -} -#endif diff --git a/src/Lucene.Net.TestFramework/Support/Util/LuceneTestCase.Serialization.cs b/src/Lucene.Net.TestFramework/Support/Util/LuceneTestCase.Serialization.cs index 922d544..a684a13 100644 --- a/src/Lucene.Net.TestFramework/Support/Util/LuceneTestCase.Serialization.cs +++ b/src/Lucene.Net.TestFramework/Support/Util/LuceneTestCase.Serialization.cs @@ -79,18 +79,21 @@ namespace Lucene.Net.Util /// </summary> /// <typeparam name="T">The type of <paramref name="source"/>.</typeparam> /// <param name="source">An object to serialize. It must be serializable.</param> + /// <param name="exception">The output <see cref="SerializationException"/> throw if serialization fails.</param> /// <returns><c>true</c> if the serialization operation was successful; otherwise <c>false</c>.</returns> - internal static bool TypeCanSerialize<T>(T source) + internal static bool TypeCanSerialize<T>(T source, out SerializationException exception) { try { Clone(source); } - catch (SerializationException) + catch (SerializationException e) { + exception = e; return false; } + exception = null; return true; } } diff --git a/src/Lucene.Net.Tests.AllProjects/Support/AssemblyScanningTestCase.cs b/src/Lucene.Net.Tests.AllProjects/Support/AssemblyScanningTestCase.cs new file mode 100644 index 0000000..9672ff9 --- /dev/null +++ b/src/Lucene.Net.Tests.AllProjects/Support/AssemblyScanningTestCase.cs @@ -0,0 +1,91 @@ +using J2N.Text; +using Lucene.Net.Util; +using System; +using System.Collections.Generic; +using System.Reflection; +using JCG = J2N.Collections.Generic; + +namespace Lucene.Net.Support +{ + /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + public abstract class AssemblyScanningTestCase : LuceneTestCase + { + // Load exception types from all assemblies + public static readonly Assembly[] LuceneAssemblies = new Assembly[] + { + typeof(Lucene.Net.Analysis.Analyzer).Assembly, // Lucene.Net + typeof(Lucene.Net.Analysis.Standard.ClassicAnalyzer).Assembly, // Lucene.Net.Analysis.Common + typeof(Lucene.Net.Analysis.Ja.GraphvizFormatter).Assembly, // Lucene.Net.Analysis.Kuromoji + typeof(Lucene.Net.Analysis.Morfologik.MorfologikAnalyzer).Assembly, // Lucene.Net.Analysis.Morfologik +#if FEATURE_OPENNLP + typeof(Lucene.Net.Analysis.OpenNlp.OpenNLPTokenizer).Assembly, // Lucene.Net.Analysis.OpenNLP +#endif + typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter).Assembly, // Lucene.Net.Analysis.Phonetic + typeof(Lucene.Net.Analysis.Cn.Smart.AnalyzerProfile).Assembly, // Lucene.Net.Analysis.SmartCn + typeof(Lucene.Net.Analysis.Stempel.StempelFilter).Assembly, // Lucene.Net.Analysis.Stempel + typeof(Lucene.Net.Benchmarks.Constants).Assembly, // Lucene.Net.Benchmark + typeof(Lucene.Net.Classification.KNearestNeighborClassifier).Assembly, // Lucene.Net.Classification + typeof(Lucene.Net.Codecs.BlockTerms.BlockTermsReader).Assembly, // Lucene.Net.Codecs + typeof(Lucene.Net.Expressions.Bindings).Assembly, // Lucene.Net.Expressions + typeof(Lucene.Net.Facet.Facets).Assembly, // Lucene.Net.Facet + typeof(Lucene.Net.Search.Grouping.ICollectedSearchGroup).Assembly, // Lucene.Net.Grouping + typeof(Lucene.Net.Search.Highlight.DefaultEncoder).Assembly, // Lucene.Net.Highlighter + typeof(Lucene.Net.Analysis.Icu.ICUFoldingFilter).Assembly, // Lucene.Net.ICU + typeof(Lucene.Net.Search.Join.JoinUtil).Assembly, // Lucene.Net.Join + typeof(Lucene.Net.Index.Memory.MemoryIndex).Assembly, // Lucene.Net.Memory + typeof(Lucene.Net.Misc.SweetSpotSimilarity).Assembly, // Lucene.Net.Misc + typeof(Lucene.Net.Queries.BooleanFilter).Assembly, // Lucene.Net.Queries + typeof(Lucene.Net.QueryParsers.Classic.QueryParser).Assembly, // Lucene.Net.QueryParser + typeof(Lucene.Net.Replicator.IReplicator).Assembly, // Lucene.Net.Replicator + typeof(Lucene.Net.Sandbox.Queries.DuplicateFilter).Assembly, // Lucene.Net.Sandbox + typeof(Lucene.Net.Spatial.DisjointSpatialFilter).Assembly, // Lucene.Net.Spatial + typeof(Lucene.Net.Util.LuceneTestCase).Assembly, // Lucene.Net.TestFramework + }; + + + public static readonly Assembly[] DotNetAssemblies = new Assembly[] + { + typeof(Exception).Assembly + }; + + public static readonly Assembly[] NUnitAssemblies = new Assembly[] + { + typeof(NUnit.Framework.AssertionException).Assembly + }; + + public static ISet<Type> LoadTypesSubclassing(Type baseClass, params Assembly[] assemblies) + { + if (baseClass is null) + throw new ArgumentNullException(nameof(baseClass)); + if (assemblies is null) + throw new ArgumentNullException(nameof(assemblies)); + + var result = new JCG.SortedSet<Type>(Comparer<Type>.Create((left, right) => left.FullName.CompareToOrdinal(right.FullName))); + foreach (var assembly in assemblies) + { + foreach (var type in assembly.GetTypes()) + { + if (baseClass.IsAssignableFrom(type)) + result.Add(type); + } + } + return result; + } + } +} \ No newline at end of file diff --git a/src/Lucene.Net.Tests/Support/ExceptionHandling/TestExceptionExtensions.cs b/src/Lucene.Net.Tests.AllProjects/Support/ExceptionHandling/ExceptionScanningTestCase.cs similarity index 52% rename from src/Lucene.Net.Tests/Support/ExceptionHandling/TestExceptionExtensions.cs rename to src/Lucene.Net.Tests.AllProjects/Support/ExceptionHandling/ExceptionScanningTestCase.cs index 2a9257f..d352559 100644 --- a/src/Lucene.Net.Tests/Support/ExceptionHandling/TestExceptionExtensions.cs +++ b/src/Lucene.Net.Tests.AllProjects/Support/ExceptionHandling/ExceptionScanningTestCase.cs @@ -1,5 +1,4 @@ -using J2N.Text; -using Lucene.Net.Attributes; +using Lucene.Net.Attributes; using Lucene.Net.Index; using Lucene.Net.Queries.Function.DocValues; using Lucene.Net.Search; @@ -14,11 +13,9 @@ using System.Linq; using System.Reflection; using System.Resources; using System.Security; -using System.Threading; using Assert = Lucene.Net.TestFramework.Assert; -using JCG = J2N.Collections.Generic; -namespace Lucene +namespace Lucene.Net.Support.ExceptionHandling { /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -37,9 +34,8 @@ namespace Lucene * limitations under the License. */ -#pragma warning disable IDE0001 // Name can be simplified [LuceneNetSpecific] - public class TestExceptionExtensions : LuceneTestCase + public abstract class ExceptionScanningTestCase : AssemblyScanningTestCase { // Internal types references private static readonly Type DebugAssertExceptionType = @@ -106,65 +102,23 @@ namespace Lucene Type.GetType("NUnit.Framework.Internal.InvalidPlatformException, NUnit.Framework"); - // Load exception types from all assemblies - private static readonly Assembly[] LuceneAssemblies = new Assembly[] - { - typeof(Lucene.Net.Analysis.Analyzer).Assembly, // Lucene.Net - typeof(Lucene.Net.Analysis.Standard.ClassicAnalyzer).Assembly, // Lucene.Net.Analysis.Common - typeof(Lucene.Net.Analysis.Ja.GraphvizFormatter).Assembly, // Lucene.Net.Analysis.Kuromoji - typeof(Lucene.Net.Analysis.Morfologik.MorfologikAnalyzer).Assembly, // Lucene.Net.Analysis.Morfologik -#if FEATURE_OPENNLP - typeof(Lucene.Net.Analysis.OpenNlp.OpenNLPTokenizer).Assembly, // Lucene.Net.Analysis.OpenNlp -#endif - typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter).Assembly, // Lucene.Net.Analysis.Phonetic - typeof(Lucene.Net.Analysis.Cn.Smart.AnalyzerProfile).Assembly, // Lucene.Net.Analysis.SmartCn - typeof(Lucene.Net.Analysis.Stempel.StempelFilter).Assembly, // Lucene.Net.Analysis.Stempel - typeof(Lucene.Net.Benchmarks.Constants).Assembly, // Lucene.Net.Benchmark - typeof(Lucene.Net.Classification.KNearestNeighborClassifier).Assembly, // Lucene.Net.Classification - typeof(Lucene.Net.Codecs.BlockTerms.BlockTermsReader).Assembly, // Lucene.Net.Codecs - typeof(Lucene.Net.Expressions.Bindings).Assembly, // Lucene.Net.Expressions - typeof(Lucene.Net.Facet.Facets).Assembly, // Lucene.Net.Facet - typeof(Lucene.Net.Search.Grouping.ICollectedSearchGroup).Assembly, // Lucene.Net.Grouping - typeof(Lucene.Net.Search.Highlight.DefaultEncoder).Assembly, // Lucene.Net.Highlighter - typeof(Lucene.Net.Search.Join.JoinUtil).Assembly, // Lucene.Net.Join - typeof(Lucene.Net.Index.Memory.MemoryIndex).Assembly, // Lucene.Net.Memory - typeof(Lucene.Net.Misc.SweetSpotSimilarity).Assembly, // Lucene.Net.Misc - typeof(Lucene.Net.Queries.BooleanFilter).Assembly, // Lucene.Net.Queries - typeof(Lucene.Net.QueryParsers.Classic.QueryParser).Assembly, // Lucene.Net.QueryParser - typeof(Lucene.Net.Replicator.IReplicator).Assembly, // Lucene.Net.Replicator - typeof(Lucene.Net.Sandbox.Queries.DuplicateFilter).Assembly, // Lucene.Net.Sandbox - typeof(Lucene.Net.Spatial.DisjointSpatialFilter).Assembly, // Lucene.Net.Spatial - typeof(Lucene.Net.Util.LuceneTestCase).Assembly, // Lucene.Net.TestFramework - }; - - - private static readonly Assembly[] DotNetAssemblies = new Assembly[] - { - typeof(Exception).Assembly - }; - - private static readonly Assembly[] NUnitAssemblies = new Assembly[] - { - typeof(NUnit.Framework.AssertionException).Assembly - }; - // Base class Exception - private static readonly ICollection<Type> DotNetExceptionTypes = LoadTypesSubclassing(baseClass: typeof(Exception), DotNetAssemblies); - private static readonly ICollection<Type> NUnitExceptionTypes = LoadTypesSubclassing(baseClass: typeof(Exception), NUnitAssemblies); - private static readonly ICollection<Type> LuceneExceptionTypes = LoadTypesSubclassing(baseClass: typeof(Exception), LuceneAssemblies); + public static readonly ICollection<Type> DotNetExceptionTypes = LoadTypesSubclassing(baseClass: typeof(Exception), DotNetAssemblies); + public static readonly ICollection<Type> NUnitExceptionTypes = LoadTypesSubclassing(baseClass: typeof(Exception), NUnitAssemblies); + public static readonly ICollection<Type> LuceneExceptionTypes = LoadTypesSubclassing(baseClass: typeof(Exception), LuceneAssemblies); - private static readonly ICollection<Type> AllExceptionTypes = DotNetExceptionTypes.Union(NUnitExceptionTypes).Union(LuceneExceptionTypes).ToList(); + public static readonly ICollection<Type> AllExceptionTypes = DotNetExceptionTypes.Union(NUnitExceptionTypes).Union(LuceneExceptionTypes).ToList(); // Base class IOException - private static readonly ICollection<Type> DotNetIOExceptionTypes = LoadTypesSubclassing(baseClass: typeof(IOException), DotNetAssemblies); - private static readonly ICollection<Type> NUnitIOExceptionTypes = LoadTypesSubclassing(baseClass: typeof(IOException), NUnitAssemblies); - private static readonly ICollection<Type> LuceneIOExceptionTypes = LoadTypesSubclassing(baseClass: typeof(IOException), LuceneAssemblies); + public static readonly ICollection<Type> DotNetIOExceptionTypes = LoadTypesSubclassing(baseClass: typeof(IOException), DotNetAssemblies); + public static readonly ICollection<Type> NUnitIOExceptionTypes = LoadTypesSubclassing(baseClass: typeof(IOException), NUnitAssemblies); + public static readonly ICollection<Type> LuceneIOExceptionTypes = LoadTypesSubclassing(baseClass: typeof(IOException), LuceneAssemblies); - private static readonly ICollection<Type> AllIOExceptionTypes = DotNetIOExceptionTypes.Union(NUnitIOExceptionTypes).Union(LuceneIOExceptionTypes).ToList(); + public static readonly ICollection<Type> AllIOExceptionTypes = DotNetIOExceptionTypes.Union(NUnitIOExceptionTypes).Union(LuceneIOExceptionTypes).ToList(); #region Known types of exception families - private static readonly IEnumerable<Type> KnownAssertionErrorTypes = LoadKnownAssertionErrorTypes(); + public static readonly IEnumerable<Type> KnownAssertionErrorTypes = LoadKnownAssertionErrorTypes(); private static IEnumerable<Type> LoadKnownAssertionErrorTypes() { @@ -186,7 +140,7 @@ namespace Lucene return result; } - private static readonly IEnumerable<Type> KnownErrorExceptionTypes = LoadKnownErrorExceptionTypes(); + public static readonly IEnumerable<Type> KnownErrorExceptionTypes = LoadKnownErrorExceptionTypes(); private static IEnumerable<Type> LoadKnownErrorExceptionTypes() { @@ -215,26 +169,26 @@ namespace Lucene }; } - private static readonly IEnumerable<Type> KnownExceptionTypes = AllExceptionTypes + public static readonly IEnumerable<Type> KnownExceptionTypes = AllExceptionTypes // Exceptions in Java exclude Errors .Except(KnownErrorExceptionTypes) // Special Case: We never want to catch this NUnit exception .Where(t => !Type.Equals(t, NUnitFrameworkInternalInvalidPlatformExceptionType)); - private static readonly IEnumerable<Type> KnownThrowableExceptionTypes = AllExceptionTypes + public static readonly IEnumerable<Type> KnownThrowableExceptionTypes = AllExceptionTypes // Special Case: We never want to catch this NUnit exception .Where(t => !Type.Equals(t, NUnitFrameworkInternalInvalidPlatformExceptionType)); - private static readonly IEnumerable<Type> KnownIOExceptionTypes = new Type[] { - typeof(UnauthorizedAccessException), - typeof(ObjectDisposedException), - typeof(Lucene.AlreadyClosedException), - }.Union(AllIOExceptionTypes) + public static readonly IEnumerable<Type> KnownIOExceptionTypes = new Type[] { + typeof(UnauthorizedAccessException), + typeof(ObjectDisposedException), + typeof(Lucene.AlreadyClosedException), + }.Union(AllIOExceptionTypes) // .NET Framework only - Subclasses UnauthorizedAccessException .Union(new[] { PrivilegeNotHeldExceptionType }); - private static readonly IEnumerable<Type> KnownIndexOutOfBoundsExceptionTypes = new Type[] { + public static readonly IEnumerable<Type> KnownIndexOutOfBoundsExceptionTypes = new Type[] { typeof(ArgumentOutOfRangeException), typeof(IndexOutOfRangeException), @@ -244,7 +198,7 @@ namespace Lucene typeof(IndexOutOfBoundsException), }; - private static readonly IEnumerable<Type> KnownNullPointerExceptionTypes = new Type[] { + public static readonly IEnumerable<Type> KnownNullPointerExceptionTypes = new Type[] { typeof(ArgumentNullException), typeof(NullReferenceException), @@ -252,7 +206,7 @@ namespace Lucene typeof(NullPointerException), }; - private static readonly IEnumerable<Type> KnownIllegalArgumentExceptionTypes = new Type[] { + public static readonly IEnumerable<Type> KnownIllegalArgumentExceptionTypes = new Type[] { typeof(ArgumentException), typeof(ArgumentNullException), typeof(ArgumentOutOfRangeException), @@ -271,7 +225,7 @@ namespace Lucene typeof(System.Text.EncoderFallbackException), }; - private static readonly IEnumerable<Type> KnownIllegalArgumentExceptionTypes_TestEnvironment = new Type[] { + public static readonly IEnumerable<Type> KnownIllegalArgumentExceptionTypes_TestEnvironment = new Type[] { typeof(ArgumentException), // Types for use as Java Aliases in .NET @@ -284,7 +238,7 @@ namespace Lucene typeof(System.Text.EncoderFallbackException), }; - private static readonly IEnumerable<Type> KnownRuntimeExceptionTypes = LoadKnownRuntimeExceptionTypes(); + public static readonly IEnumerable<Type> KnownRuntimeExceptionTypes = LoadKnownRuntimeExceptionTypes(); private static IEnumerable<Type> LoadKnownRuntimeExceptionTypes() { @@ -475,7 +429,7 @@ namespace Lucene #region Special case constructors - private static readonly IDictionary<Type, Func<Type, string, object>> NonStandardExceptionConstructors = LoadNonStandardExceptionConstructors(); + public static readonly IDictionary<Type, Func<Type, string, object>> NonStandardExceptionConstructors = LoadNonStandardExceptionConstructors(); private static IDictionary<Type, Func<Type, string, object>> LoadNonStandardExceptionConstructors() { @@ -552,7 +506,7 @@ namespace Lucene return result; } - public class NUnitExceptionMessage : NUnit.Framework.Interfaces.ITestResult + private class NUnitExceptionMessage : ITestResult { private readonly string message; @@ -613,182 +567,7 @@ namespace Lucene #endregion Special case constructors - private static ICollection<Type> LoadTypesSubclassing(Type baseClass, params Assembly[] assemblies) - { - if (baseClass is null) - throw new ArgumentNullException(nameof(baseClass)); - if (assemblies is null) - throw new ArgumentNullException(nameof(assemblies)); - - var result = new JCG.SortedSet<Type>(Comparer<Type>.Create((left, right) => left.Name.CompareToOrdinal(right.Name))); - foreach (var assembly in assemblies) - { - result.UnionWith(assembly.GetTypes().Where(exceptionType => baseClass.IsAssignableFrom(exceptionType))); - } - return result; - } - - public static IEnumerable<TestCaseData> ThrowableTypeExpressions - { - get - { - foreach (var exceptionType in AllExceptionTypes) - { - // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught - yield return new TestCaseData( - exceptionType, // exception type (to make NUnit display them all) - !KnownThrowableExceptionTypes.Contains(exceptionType), // expectedToThrow - new Action(() => ThrowException(exceptionType))); // throw exception expression - } - } - } - - - public static IEnumerable<TestCaseData> ErrorTypeExpressions - { - get - { - foreach (var exceptionType in AllExceptionTypes) - { - // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught - yield return new TestCaseData( - exceptionType, // exception type (to make NUnit display them all) - !KnownErrorExceptionTypes.Contains(exceptionType), // expectedToThrow - new Action(() => ThrowException(exceptionType))); // throw exception expression - } - } - } - - public static IEnumerable<TestCaseData> ExceptionTypeExpressions - { - get - { - foreach (var exceptionType in AllExceptionTypes) - { - // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught - yield return new TestCaseData( - exceptionType, // exception type (to make NUnit display them all) - !KnownExceptionTypes.Contains(exceptionType), // expectedToThrow - new Action(() => ThrowException(exceptionType))); // throw exception expression - } - } - } - - public static IEnumerable<TestCaseData> RuntimeExceptionTypeExpressions - { - get - { - foreach (var exceptionType in AllExceptionTypes) - { -#if NETCOREAPP2_1 - // These don't seem to match on .NET Core 2.1, but we don't care - if (exceptionType.FullName.Equals("System.CrossAppDomainMarshaledException") || - exceptionType.FullName.Equals("System.AppDomainUnloadedException")) - { - continue; - } -#endif - - // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught - yield return new TestCaseData( - exceptionType, // exception type (to make NUnit display them all) - !KnownRuntimeExceptionTypes.Contains(exceptionType),// expectedToThrow - new Action(() => ThrowException(exceptionType))); // throw exception expression - } - } - } - - public static IEnumerable<TestCaseData> IOExceptionTypeExpressions - { - get - { - foreach (var exceptionType in AllExceptionTypes) - { - // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught - yield return new TestCaseData( - exceptionType, // exception type (to make NUnit display them all) - !KnownIOExceptionTypes.Contains(exceptionType), // expectedToThrow - new Action(() => ThrowException(exceptionType))); // throw exception expression - } - } - } - - public static IEnumerable<TestCaseData> AssertionErrorTypeExpressions - { - get - { - foreach (var exceptionType in AllExceptionTypes) - { - // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught - yield return new TestCaseData( - exceptionType, // exception type (to make NUnit display them all) - !KnownAssertionErrorTypes.Contains(exceptionType), // expectedToThrow - new Action(() => ThrowException(exceptionType))); // throw exception expression - } - } - } - - public static IEnumerable<TestCaseData> IndexOutOfBoundsExceptionTypeExpressions - { - get - { - foreach (var exceptionType in AllExceptionTypes) - { - // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught - yield return new TestCaseData( - exceptionType, // exception type (to make NUnit display them all) - !KnownIndexOutOfBoundsExceptionTypes.Contains(exceptionType), // expectedToThrow - new Action(() => ThrowException(exceptionType))); // throw exception expression - } - } - } - - public static IEnumerable<TestCaseData> NullPointerExceptionTypeExpressions - { - get - { - foreach (var exceptionType in AllExceptionTypes) - { - // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught - yield return new TestCaseData( - exceptionType, // exception type (to make NUnit display them all) - !KnownNullPointerExceptionTypes.Contains(exceptionType), // expectedToThrow - new Action(() => ThrowException(exceptionType))); // throw exception expression - } - } - } - - public static IEnumerable<TestCaseData> IllegalArgumentExceptionTypeExpressions - { - get - { - foreach (var exceptionType in AllExceptionTypes) - { - // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught - yield return new TestCaseData( - exceptionType, // exception type (to make NUnit display them all) - !KnownIllegalArgumentExceptionTypes.Contains(exceptionType), // expectedToThrow - new Action(() => ThrowException(exceptionType))); // throw exception expression - } - } - } - - public static IEnumerable<TestCaseData> IllegalArgumentExceptionTypeExpressions_TestEnvironment - { - get - { - foreach (var exceptionType in AllExceptionTypes) - { - // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught - yield return new TestCaseData( - exceptionType, // exception type (to make NUnit display them all) - !KnownIllegalArgumentExceptionTypes_TestEnvironment.Contains(exceptionType), // expectedToThrow - new Action(() => ThrowException(exceptionType))); // throw exception expression - } - } - } - - private static void ThrowException(Type exceptionType) + protected static Exception TryInstantiate(Type exceptionType) { object exception = null; if (NonStandardExceptionConstructors.TryGetValue(exceptionType, out Func<Type, string, object> constructionFactory)) @@ -821,238 +600,7 @@ namespace Lucene } } } - throw (Exception)exception; - } - - [Test] - [TestCaseSource("ThrowableTypeExpressions")] - public void TestIsThrowable(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all - { - static bool extensionMethod(Exception e) => e.IsThrowable(); - - if (expectedToThrow) - { - AssertDoesNotCatch(expression, extensionMethod); - } - else - { - AssertCatches(expression, extensionMethod); - } - } - - [Test] - [TestCaseSource("ErrorTypeExpressions")] - public void TestIsError(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all - { - static bool extensionMethod(Exception e) => e.IsError(); - - if (expectedToThrow) - { - AssertDoesNotCatch(expression, extensionMethod); - } - else - { - AssertCatches(expression, extensionMethod); - } - } - - // This test ensures that all known Error types from Java are not caught by - // our IsException() handler. - [Test] - [TestCaseSource("ExceptionTypeExpressions")] - public void TestIsException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all - { - static bool extensionMethod(Exception e) => e.IsException(); - - if (expectedToThrow) - { - AssertDoesNotCatch(expression, extensionMethod); - } - else - { - AssertCatches(expression, extensionMethod); - } - } - - // This test ensures that all known Error types from Java are not caught by - // our IsRuntimeException() handler. - [Test] - [TestCaseSource("RuntimeExceptionTypeExpressions")] - public void TestIsRuntimeException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all - { - static bool extensionMethod(Exception e) => e.IsRuntimeException(); - - if (expectedToThrow) - { - AssertDoesNotCatch(expression, extensionMethod); - } - else - { - AssertCatches(expression, extensionMethod); - } - } - - [Test] - [TestCaseSource("IOExceptionTypeExpressions")] - public void TestIsIOException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all - { - static bool extensionMethod(Exception e) => e.IsIOException(); - - if (expectedToThrow) - { - AssertDoesNotCatch(expression, extensionMethod); - } - else - { - AssertCatches(expression, extensionMethod); - } - } - - // This test ensures that Lucene.NET's AssertionException, the .NET platform's DebugAssertException, and - // NUnit's AssertionException and MultipleAssertException types are all treated as if they were AssertionError - // in Java. - [Test] - [TestCaseSource("AssertionErrorTypeExpressions")] - public void TestIsAssertionError(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all - { - static bool extensionMethod(Exception e) => e.IsAssertionError(); - - if (expectedToThrow) - { - AssertDoesNotCatch(expression, extensionMethod); - } - else - { - AssertCatches(expression, extensionMethod); - } - } - - // This test ensures that ArgumentOutOfRangeException and IndexOutOfRangeException are both caught by our - // IndexOutOfBoundsException handler, because they both correspond to IndexOutOfBoundsException in Java. - // Java has 2 other types ArrayIndexOutOfBoundsException and StringIndexOutOfBoundsException, whose alias - // exception types are also part of the test. - [Test] - [TestCaseSource("IndexOutOfBoundsExceptionTypeExpressions")] - public void TestIsIndexOutOfBoundsException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all - { - static bool extensionMethod(Exception e) => e.IsIndexOutOfBoundsException(); - - if (expectedToThrow) - { - AssertDoesNotCatch(expression, extensionMethod); - } - else - { - AssertCatches(expression, extensionMethod); - } - } - - // This test ensures that ArgumentNullException and NullReferenceException are both caught by our - // NullPointerException handler, because they both correspond to NullPointerException in Java - [Test] - [TestCaseSource("NullPointerExceptionTypeExpressions")] - public void TestIsNullPointerException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all - { - static bool extensionMethod(Exception e) => e.IsNullPointerException(); - - if (expectedToThrow) - { - AssertDoesNotCatch(expression, extensionMethod); - } - else - { - AssertCatches(expression, extensionMethod); - } - } - - // This test ensures that any known ArgumentException will be caught. - // We do it this way in production to ensure that if we "upgrade" to a .NET - // ArgumentNullException or ArgumentOutOfRangeException it won't break the code. - [Test] - [TestCaseSource("IllegalArgumentExceptionTypeExpressions")] - public void TestIsIllegalArgumentException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all - { - // Make sure we are testing the production code - static bool extensionMethod(Exception e) => Lucene.ExceptionExtensions.IsIllegalArgumentException(e); - - if (expectedToThrow) - { - AssertDoesNotCatch(expression, extensionMethod); - } - else - { - AssertCatches(expression, extensionMethod); - } - } - - // This test ensures that ArgumentNullException and ArgumentOutOfRangeException are not caught by our - // IllegalArgumentException handler in tests, because they wouldn't be in Java. We do this differently - // in the test environment to ensure that if a test is specified wrong it will fail and should be updated - // and commented to indicate we diverged from Lucene. - [Test] - [TestCaseSource("IllegalArgumentExceptionTypeExpressions_TestEnvironment")] - public void TestIsIllegalArgumentException_TestEnvironment(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all - { - // Make sure we are testing the test environment code - static bool extensionMethod(Exception e) => Lucene.Net.ExceptionExtensions.IsIllegalArgumentException(e); - - if (expectedToThrow) - { - AssertDoesNotCatch(expression, extensionMethod); - } - else - { - AssertCatches(expression, extensionMethod); - } - } - - private void AssertCatches(Action action, Func<Exception, bool> extensionMethodExpression) - { - try - { - try - { - action(); - } - catch (Exception e) when (extensionMethodExpression(e)) - { - // expected - Assert.Pass($"Expected: Caught exception {e.GetType().FullName}"); - } - } - catch (Exception e) when (!(e is NUnit.Framework.SuccessException)) - { - // not expected - Assert.Fail($"Exception thrown when expected to be caught: {e.GetType().FullName}"); - } - } - - private void AssertDoesNotCatch(Action action, Func<Exception, bool> extensionMethodExpression) - { - try - { - try - { - action(); - } - catch (NUnit.Framework.AssertionException e) - { - // Special case - need to suppress this from being thrown to the outer catch - // or we will get a false failure - Assert.IsFalse(extensionMethodExpression(e)); - Assert.Pass($"Expected: Did not catch exception {e.GetType().FullName}"); - } - catch (Exception e) when (extensionMethodExpression(e)) - { - // not expected - Assert.Fail($"Exception caught when expected to be thrown: {e.GetType().FullName}"); - } - } - catch (Exception e) when (!(e is NUnit.Framework.AssertionException)) - { - // expected - Assert.Pass($"Expected: Did not catch exception {e.GetType().FullName}"); - } + return (Exception)exception; } } -} +} \ No newline at end of file diff --git a/src/Lucene.Net.Tests.AllProjects/Support/ExceptionHandling/TestExceptionExtensions.cs b/src/Lucene.Net.Tests.AllProjects/Support/ExceptionHandling/TestExceptionExtensions.cs new file mode 100644 index 0000000..7b205a6 --- /dev/null +++ b/src/Lucene.Net.Tests.AllProjects/Support/ExceptionHandling/TestExceptionExtensions.cs @@ -0,0 +1,428 @@ +using J2N.Text; +using Lucene.Net.Attributes; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using Assert = Lucene.Net.TestFramework.Assert; + +namespace Lucene.Net.Support.ExceptionHandling +{ + /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma warning disable IDE0001 // Name can be simplified + [LuceneNetSpecific] + public class TestExceptionExtensions : ExceptionScanningTestCase + { + public static IEnumerable<TestCaseData> ThrowableTypeExpressions + { + get + { + foreach (var exceptionType in AllExceptionTypes) + { + // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught + yield return new TestCaseData( + exceptionType, // exception type (to make NUnit display them all) + !KnownThrowableExceptionTypes.Contains(exceptionType), // expectedToThrow + new Action(() => ThrowException(exceptionType))); // throw exception expression + } + } + } + + + public static IEnumerable<TestCaseData> ErrorTypeExpressions + { + get + { + foreach (var exceptionType in AllExceptionTypes) + { + // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught + yield return new TestCaseData( + exceptionType, // exception type (to make NUnit display them all) + !KnownErrorExceptionTypes.Contains(exceptionType), // expectedToThrow + new Action(() => ThrowException(exceptionType))); // throw exception expression + } + } + } + + public static IEnumerable<TestCaseData> ExceptionTypeExpressions + { + get + { + foreach (var exceptionType in AllExceptionTypes) + { + // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught + yield return new TestCaseData( + exceptionType, // exception type (to make NUnit display them all) + !KnownExceptionTypes.Contains(exceptionType), // expectedToThrow + new Action(() => ThrowException(exceptionType))); // throw exception expression + } + } + } + + public static IEnumerable<TestCaseData> RuntimeExceptionTypeExpressions + { + get + { + foreach (var exceptionType in AllExceptionTypes) + { +#if NETCOREAPP2_1 + // These don't seem to match on .NET Core 2.1, but we don't care + if (exceptionType.FullName.Equals("System.CrossAppDomainMarshaledException") || + exceptionType.FullName.Equals("System.AppDomainUnloadedException")) + { + continue; + } +#endif + + // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught + yield return new TestCaseData( + exceptionType, // exception type (to make NUnit display them all) + !KnownRuntimeExceptionTypes.Contains(exceptionType),// expectedToThrow + new Action(() => ThrowException(exceptionType))); // throw exception expression + } + } + } + + public static IEnumerable<TestCaseData> IOExceptionTypeExpressions + { + get + { + foreach (var exceptionType in AllExceptionTypes) + { + // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught + yield return new TestCaseData( + exceptionType, // exception type (to make NUnit display them all) + !KnownIOExceptionTypes.Contains(exceptionType), // expectedToThrow + new Action(() => ThrowException(exceptionType))); // throw exception expression + } + } + } + + public static IEnumerable<TestCaseData> AssertionErrorTypeExpressions + { + get + { + foreach (var exceptionType in AllExceptionTypes) + { + // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught + yield return new TestCaseData( + exceptionType, // exception type (to make NUnit display them all) + !KnownAssertionErrorTypes.Contains(exceptionType), // expectedToThrow + new Action(() => ThrowException(exceptionType))); // throw exception expression + } + } + } + + public static IEnumerable<TestCaseData> IndexOutOfBoundsExceptionTypeExpressions + { + get + { + foreach (var exceptionType in AllExceptionTypes) + { + // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught + yield return new TestCaseData( + exceptionType, // exception type (to make NUnit display them all) + !KnownIndexOutOfBoundsExceptionTypes.Contains(exceptionType), // expectedToThrow + new Action(() => ThrowException(exceptionType))); // throw exception expression + } + } + } + + public static IEnumerable<TestCaseData> NullPointerExceptionTypeExpressions + { + get + { + foreach (var exceptionType in AllExceptionTypes) + { + // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught + yield return new TestCaseData( + exceptionType, // exception type (to make NUnit display them all) + !KnownNullPointerExceptionTypes.Contains(exceptionType), // expectedToThrow + new Action(() => ThrowException(exceptionType))); // throw exception expression + } + } + } + + public static IEnumerable<TestCaseData> IllegalArgumentExceptionTypeExpressions + { + get + { + foreach (var exceptionType in AllExceptionTypes) + { + // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught + yield return new TestCaseData( + exceptionType, // exception type (to make NUnit display them all) + !KnownIllegalArgumentExceptionTypes.Contains(exceptionType), // expectedToThrow + new Action(() => ThrowException(exceptionType))); // throw exception expression + } + } + } + + public static IEnumerable<TestCaseData> IllegalArgumentExceptionTypeExpressions_TestEnvironment + { + get + { + foreach (var exceptionType in AllExceptionTypes) + { + // expectedToThrow is true when we expect the error to be thrown and false when we expect it to be caught + yield return new TestCaseData( + exceptionType, // exception type (to make NUnit display them all) + !KnownIllegalArgumentExceptionTypes_TestEnvironment.Contains(exceptionType), // expectedToThrow + new Action(() => ThrowException(exceptionType))); // throw exception expression + } + } + } + + private static void ThrowException(Type exceptionType) + { + throw TryInstantiate(exceptionType); + } + + [Test] + [TestCaseSource("ThrowableTypeExpressions")] + public void TestIsThrowable(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all + { + static bool extensionMethod(Exception e) => e.IsThrowable(); + + if (expectedToThrow) + { + AssertDoesNotCatch(expression, extensionMethod); + } + else + { + AssertCatches(expression, extensionMethod); + } + } + + [Test] + [TestCaseSource("ErrorTypeExpressions")] + public void TestIsError(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all + { + static bool extensionMethod(Exception e) => e.IsError(); + + if (expectedToThrow) + { + AssertDoesNotCatch(expression, extensionMethod); + } + else + { + AssertCatches(expression, extensionMethod); + } + } + + // This test ensures that all known Error types from Java are not caught by + // our IsException() handler. + [Test] + [TestCaseSource("ExceptionTypeExpressions")] + public void TestIsException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all + { + static bool extensionMethod(Exception e) => e.IsException(); + + if (expectedToThrow) + { + AssertDoesNotCatch(expression, extensionMethod); + } + else + { + AssertCatches(expression, extensionMethod); + } + } + + // This test ensures that all known Error types from Java are not caught by + // our IsRuntimeException() handler. + [Test] + [TestCaseSource("RuntimeExceptionTypeExpressions")] + public void TestIsRuntimeException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all + { + static bool extensionMethod(Exception e) => e.IsRuntimeException(); + + if (expectedToThrow) + { + AssertDoesNotCatch(expression, extensionMethod); + } + else + { + AssertCatches(expression, extensionMethod); + } + } + + [Test] + [TestCaseSource("IOExceptionTypeExpressions")] + public void TestIsIOException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all + { + static bool extensionMethod(Exception e) => e.IsIOException(); + + if (expectedToThrow) + { + AssertDoesNotCatch(expression, extensionMethod); + } + else + { + AssertCatches(expression, extensionMethod); + } + } + + // This test ensures that Lucene.NET's AssertionException, the .NET platform's DebugAssertException, and + // NUnit's AssertionException and MultipleAssertException types are all treated as if they were AssertionError + // in Java. + [Test] + [TestCaseSource("AssertionErrorTypeExpressions")] + public void TestIsAssertionError(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all + { + static bool extensionMethod(Exception e) => e.IsAssertionError(); + + if (expectedToThrow) + { + AssertDoesNotCatch(expression, extensionMethod); + } + else + { + AssertCatches(expression, extensionMethod); + } + } + + // This test ensures that ArgumentOutOfRangeException and IndexOutOfRangeException are both caught by our + // IndexOutOfBoundsException handler, because they both correspond to IndexOutOfBoundsException in Java. + // Java has 2 other types ArrayIndexOutOfBoundsException and StringIndexOutOfBoundsException, whose alias + // exception types are also part of the test. + [Test] + [TestCaseSource("IndexOutOfBoundsExceptionTypeExpressions")] + public void TestIsIndexOutOfBoundsException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all + { + static bool extensionMethod(Exception e) => e.IsIndexOutOfBoundsException(); + + if (expectedToThrow) + { + AssertDoesNotCatch(expression, extensionMethod); + } + else + { + AssertCatches(expression, extensionMethod); + } + } + + // This test ensures that ArgumentNullException and NullReferenceException are both caught by our + // NullPointerException handler, because they both correspond to NullPointerException in Java + [Test] + [TestCaseSource("NullPointerExceptionTypeExpressions")] + public void TestIsNullPointerException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all + { + static bool extensionMethod(Exception e) => e.IsNullPointerException(); + + if (expectedToThrow) + { + AssertDoesNotCatch(expression, extensionMethod); + } + else + { + AssertCatches(expression, extensionMethod); + } + } + + // This test ensures that any known ArgumentException will be caught. + // We do it this way in production to ensure that if we "upgrade" to a .NET + // ArgumentNullException or ArgumentOutOfRangeException it won't break the code. + [Test] + [TestCaseSource("IllegalArgumentExceptionTypeExpressions")] + public void TestIsIllegalArgumentException(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all + { + // Make sure we are testing the production code + static bool extensionMethod(Exception e) => Lucene.ExceptionExtensions.IsIllegalArgumentException(e); + + if (expectedToThrow) + { + AssertDoesNotCatch(expression, extensionMethod); + } + else + { + AssertCatches(expression, extensionMethod); + } + } + + // This test ensures that ArgumentNullException and ArgumentOutOfRangeException are not caught by our + // IllegalArgumentException handler in tests, because they wouldn't be in Java. We do this differently + // in the test environment to ensure that if a test is specified wrong it will fail and should be updated + // and commented to indicate we diverged from Lucene. + [Test] + [TestCaseSource("IllegalArgumentExceptionTypeExpressions_TestEnvironment")] + public void TestIsIllegalArgumentException_TestEnvironment(Type exceptionType, bool expectedToThrow, Action expression) // LUCENENET NOTE: exceptionType is only here to make NUnit display them all + { + // Make sure we are testing the test environment code + static bool extensionMethod(Exception e) => Lucene.Net.ExceptionExtensions.IsIllegalArgumentException(e); + + if (expectedToThrow) + { + AssertDoesNotCatch(expression, extensionMethod); + } + else + { + AssertCatches(expression, extensionMethod); + } + } + + private void AssertCatches(Action action, Func<Exception, bool> extensionMethodExpression) + { + try + { + try + { + action(); + } + catch (Exception e) when (extensionMethodExpression(e)) + { + // expected + Assert.Pass($"Expected: Caught exception {e.GetType().FullName}"); + } + } + catch (Exception e) when (!(e is NUnit.Framework.SuccessException)) + { + // not expected + Assert.Fail($"Exception thrown when expected to be caught: {e.GetType().FullName}"); + } + } + + private void AssertDoesNotCatch(Action action, Func<Exception, bool> extensionMethodExpression) + { + try + { + try + { + action(); + } + catch (NUnit.Framework.AssertionException e) + { + // Special case - need to suppress this from being thrown to the outer catch + // or we will get a false failure + Assert.IsFalse(extensionMethodExpression(e)); + Assert.Pass($"Expected: Did not catch exception {e.GetType().FullName}"); + } + catch (Exception e) when (extensionMethodExpression(e)) + { + // not expected + Assert.Fail($"Exception caught when expected to be thrown: {e.GetType().FullName}"); + } + } + catch (Exception e) when (!(e is NUnit.Framework.AssertionException)) + { + // expected + Assert.Pass($"Expected: Did not catch exception {e.GetType().FullName}"); + } + } + } +} diff --git a/src/Lucene.Net.Tests.Facet/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.AllProjects/Support/ExceptionHandling/TestExceptionSerialization.cs similarity index 50% rename from src/Lucene.Net.Tests.Facet/Support/TestExceptionSerialization.cs rename to src/Lucene.Net.Tests.AllProjects/Support/ExceptionHandling/TestExceptionSerialization.cs index b487317..175f85f 100644 --- a/src/Lucene.Net.Tests.Facet/Support/TestExceptionSerialization.cs +++ b/src/Lucene.Net.Tests.AllProjects/Support/ExceptionHandling/TestExceptionSerialization.cs @@ -1,12 +1,10 @@ #if FEATURE_SERIALIZABLE_EXCEPTIONS using Lucene.Net.Attributes; -using Lucene.Net.Util; using NUnit.Framework; using System; -using System.Collections.Generic; -using System.Linq; +using System.Runtime.Serialization; -namespace Lucene.Net.Support +namespace Lucene.Net.Support.ExceptionHandling { /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -25,30 +23,14 @@ namespace Lucene.Net.Support * limitations under the License. */ - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase + [LuceneNetSpecific] + public class TestExceptionSerialization : ExceptionScanningTestCase { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Facet.Facets).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) + [Test] + public void TestCanSerialize([ValueSource("LuceneExceptionTypes")] Type luceneException) { var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); + Assert.That(TypeCanSerialize(instance, out SerializationException se), $"Unable to serialize {luceneException.FullName}:\n\n{se}"); } } } diff --git a/src/Lucene.Net.Tests.Analysis.Common/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Analysis.Common/Support/TestExceptionSerialization.cs deleted file mode 100644 index 8d9429c..0000000 --- a/src/Lucene.Net.Tests.Analysis.Common/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Lucene version compatibility level 4.8.1 -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Analysis.Standard.ClassicAnalyzer).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Analysis.Kuromoji/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Analysis.Kuromoji/Support/TestExceptionSerialization.cs deleted file mode 100644 index c116cd1..0000000 --- a/src/Lucene.Net.Tests.Analysis.Kuromoji/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Analysis.Ja.GraphvizFormatter).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestExceptionSerialization.cs deleted file mode 100644 index c7c454d..0000000 --- a/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Analysis.SmartCn/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Analysis.SmartCn/Support/TestExceptionSerialization.cs deleted file mode 100644 index ca73e99..0000000 --- a/src/Lucene.Net.Tests.Analysis.SmartCn/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Analysis.Cn.Smart.AnalyzerProfile).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Analysis.Stempel/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Analysis.Stempel/Support/TestExceptionSerialization.cs deleted file mode 100644 index 9e489bc..0000000 --- a/src/Lucene.Net.Tests.Analysis.Stempel/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Analysis.Stempel.StempelFilter).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Benchmark/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Benchmark/Support/TestExceptionSerialization.cs deleted file mode 100644 index 3025feb..0000000 --- a/src/Lucene.Net.Tests.Benchmark/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Benchmarks.Constants).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Classification/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Classification/Support/TestExceptionSerialization.cs deleted file mode 100644 index e17feff..0000000 --- a/src/Lucene.Net.Tests.Classification/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Classification.KNearestNeighborClassifier).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Codecs/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Codecs/Support/TestExceptionSerialization.cs deleted file mode 100644 index c102597..0000000 --- a/src/Lucene.Net.Tests.Codecs/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Codecs.BlockTerms.BlockTermsReader).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Expressions/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Expressions/Support/TestExceptionSerialization.cs deleted file mode 100644 index 4823f9c..0000000 --- a/src/Lucene.Net.Tests.Expressions/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Expressions.Bindings).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Grouping/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Grouping/Support/TestExceptionSerialization.cs deleted file mode 100644 index 308eb4c..0000000 --- a/src/Lucene.Net.Tests.Grouping/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Search.Grouping.ICollectedSearchGroup).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Highlighter/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Highlighter/Support/TestExceptionSerialization.cs deleted file mode 100644 index 229c48a..0000000 --- a/src/Lucene.Net.Tests.Highlighter/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Search.Highlight.DefaultEncoder).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Join/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Join/Support/TestExceptionSerialization.cs deleted file mode 100644 index 72ee2bd..0000000 --- a/src/Lucene.Net.Tests.Join/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Search.Join.FakeScorer).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Memory/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Memory/Support/TestExceptionSerialization.cs deleted file mode 100644 index 6689715..0000000 --- a/src/Lucene.Net.Tests.Memory/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Index.Memory.MemoryIndex).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Misc/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Misc/Support/TestExceptionSerialization.cs deleted file mode 100644 index 67417b6..0000000 --- a/src/Lucene.Net.Tests.Misc/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Misc.SweetSpotSimilarity).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Queries/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Queries/Support/TestExceptionSerialization.cs deleted file mode 100644 index 7730181..0000000 --- a/src/Lucene.Net.Tests.Queries/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Queries.BooleanFilter).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.QueryParser/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.QueryParser/Support/TestExceptionSerialization.cs deleted file mode 100644 index db0a09c..0000000 --- a/src/Lucene.Net.Tests.QueryParser/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.QueryParsers.Classic.ICharStream).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Replicator/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Replicator/Support/TestExceptionSerialization.cs deleted file mode 100644 index 153a69a..0000000 --- a/src/Lucene.Net.Tests.Replicator/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Replicator.IReplicator).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Sandbox/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Sandbox/Support/TestExceptionSerialization.cs deleted file mode 100644 index ba0c622..0000000 --- a/src/Lucene.Net.Tests.Sandbox/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Sandbox.Queries.DuplicateFilter).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Spatial/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Spatial/Support/TestExceptionSerialization.cs deleted file mode 100644 index 88b2710..0000000 --- a/src/Lucene.Net.Tests.Spatial/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Spatial.DisjointSpatialFilter).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Suggest/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Suggest/Support/TestExceptionSerialization.cs deleted file mode 100644 index 3a03526..0000000 --- a/src/Lucene.Net.Tests.Suggest/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Search.Suggest.IInputEnumerator).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests.TestFramework/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.TestFramework/Support/TestExceptionSerialization.cs deleted file mode 100644 index 5ceea6d..0000000 --- a/src/Lucene.Net.Tests.TestFramework/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,58 +0,0 @@ -// LUCENENET TODO: Get this working on all test frameworks -#if TESTFRAMEWORK_NUNIT -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.RandomExtensions).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif -#endif \ No newline at end of file diff --git a/src/Lucene.Net.Tests/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests/Support/TestExceptionSerialization.cs deleted file mode 100644 index e3fadaa..0000000 --- a/src/Lucene.Net.Tests/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Analysis.Analyzer).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file diff --git a/src/dotnet/Lucene.Net.Tests.ICU/Support/TestExceptionSerialization.cs b/src/dotnet/Lucene.Net.Tests.ICU/Support/TestExceptionSerialization.cs deleted file mode 100644 index 229c48a..0000000 --- a/src/dotnet/Lucene.Net.Tests.ICU/Support/TestExceptionSerialization.cs +++ /dev/null @@ -1,55 +0,0 @@ -#if FEATURE_SERIALIZABLE_EXCEPTIONS -using Lucene.Net.Attributes; -using Lucene.Net.Util; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - [TestFixture] - public class TestExceptionSerialization : ExceptionSerializationTestBase - { - public static IEnumerable<object> ExceptionTestData - { - get - { - var exceptionTypes = typeof(Lucene.Net.Search.Highlight.DefaultEncoder).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); - - // If the assembly has no exceptions, just provide Exception so the test will pass - if (!exceptionTypes.Any()) - { - return new Type[] { typeof(Exception) }; - } - - return exceptionTypes; - } - } - - [Test, LuceneNetSpecific] - public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) - { - var instance = TryInstantiate(luceneException); - Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); - } - } -} -#endif \ No newline at end of file
