You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by mh...@apache.org on 2014/11/09 23:07:47 UTC
[3/7] lucenenet git commit: creating new projects in order to
separate out logic create to suppliment .NET with JAVA standard library
functionality.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4b4d4d93/test/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/test/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/test/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
index f3428c6..c9a1803 100644
--- a/test/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
+++ b/test/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
@@ -19,6 +19,7 @@ using System.Runtime.Serialization;
namespace Lucene.Net.Util
{
+ using Lucene.Net.Random;
#if PORTABLE || K10
using Lucene.Net.Support;
#endif
@@ -28,7 +29,7 @@ namespace Lucene.Net.Util
using System.Threading;
using Xunit;
- public class LuceneTestCase
+ public class LuceneTestCase : TestClass
{
/// <summary>
/// A random multiplier which you should use when writing random tests:
@@ -41,226 +42,14 @@ namespace Lucene.Net.Util
/// </summary>
public static bool TEST_NIGHTLY = SystemProps.Get<Boolean>("tests:nightly", false);
- private static ThreadLocal<System.Random> random;
- static LuceneTestCase()
+ public static int AtLeast(int minimumValue)
{
- random = new ThreadLocal<System.Random>(() => {
-
-
- return new System.Random((int) DateTime.Now.Ticks & 0x0000FFFF);
- });
- }
-
- public LuceneTestCase()
- {
-
- }
-
- /// <summary>
- /// Placeholder for random values.
- /// </summary>
- public System.Random Random
- {
- get { return random.Value; }
- }
-
-#if XUNIT
-
- [Serializable]
- public class LuceneAssertionException : Exception
- {
- //
- // For guidelines regarding the creation of new exception types, see
- // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
- // and
- // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
- //
-
- public LuceneAssertionException()
- {
- }
-
- public LuceneAssertionException(string message) : base(message)
- {
- }
-
- public LuceneAssertionException(string message, Exception inner) : base(message, inner)
- {
- }
-
-#if NET45
- protected LuceneAssertionException(
- System.Runtime.Serialization.SerializationInfo info,
- StreamingContext context) : base(info, context)
- {
- }
-#endif
- }
-
- [DebuggerHidden]
- public static void Null(object value, string message = null, params object[] args)
- {
- try
- {
- Assert.Null(value);
- }
- catch (Exception ex)
- {
- var msg = message ?? "The value must be null.";
- if (args != null && args.Length > 0)
- msg = string.Format(msg, args);
-
- throw new LuceneAssertionException(msg, ex);
- }
- }
-
- public static void NotNull(object value, string message = null, params object[] args)
- {
- try
- {
- Assert.NotNull(value);
- }
- catch (Exception ex)
- {
- var msg = message ?? "The value must not be null.";
- if (args != null && args.Length > 0)
- msg = string.Format(msg, args);
-
- throw new LuceneAssertionException(msg, ex);
- }
- }
-
- /// <summary>
- /// Asserts that two object are the same.
- /// </summary>
- /// <param name="expected">The expected value.</param>
- /// <param name="actual">The actual value.</param>
- [DebuggerHidden]
- public static void Same(object expected, object actual)
- {
- Assert.Same(expected, actual);
- }
-
- /// <summary>
- /// Assert that two objects are not the same.
- /// </summary>
- /// <param name="expected">The expected value.</param>
- /// <param name="actual">The actual value.</param>
- [DebuggerHidden]
- public static void NotSame(object expected, object actual)
- {
- Assert.NotSame(expected, actual);
- }
-
- [DebuggerHidden]
- public static void Equal(string expected, string actual, string message = null, params object[] args)
- {
- try
- {
- Assert.Equal(expected, actual);
- }
- catch (Exception ex)
- {
- if (message == null)
- throw;
-
- var msg = message;
- if (args != null && args.Length > 0)
- msg = string.Format(msg, args);
-
- throw new LuceneAssertionException(msg, ex);
- }
- }
-
- [DebuggerHidden]
- public static void Equal<T>(T expected, T actual, string message = null, params object[] args)
- {
- try
- {
- Assert.Equal(expected, actual);
- }
- catch (Exception ex)
- {
- if (message == null)
- throw;
-
- var msg = message;
- if (args != null && args.Length > 0)
- msg = string.Format(msg, args);
-
- throw new LuceneAssertionException(msg, ex);
- }
- }
-
- [DebuggerHidden]
- public static void Equal<T>(IEnumerable<T> expected, IEnumerable<T> actual, string message= null, params object[] args)
- {
- try
- {
- Assert.Equal(expected, actual);
- }
- catch (Exception ex)
- {
- if (message == null)
- throw;
-
- var msg = message;
- if (args != null && args.Length > 0)
- msg = string.Format(msg, args);
-
- throw new LuceneAssertionException(msg, ex);
- }
- }
-
- [DebuggerHidden]
- public static void NotEqual<T>(T expected, T actual, string message = null, params object[] args)
- {
- try
- {
- Assert.NotEqual(expected, actual);
- }
- catch (Exception ex)
- {
- if (message == null)
- throw;
-
- var msg = message;
- if (args != null && args.Length > 0)
- msg = string.Format(msg, args);
-
- throw new LuceneAssertionException(msg, ex);
- }
-
+ int min = (LuceneTestCase.TEST_NIGHTLY ? 2 * minimumValue : minimumValue) * LuceneTestCase.RANDOM_MULTIPLIER;
+ int max = min + (min / 2);
+ return Random.NextBetween(min, max);
}
-
- [DebuggerHidden]
- public static void Ok(bool condition, string message = null, params object[] values)
- {
- if (!string.IsNullOrWhiteSpace(message))
- {
- var exceptionMessage = message;
-
- if(values != null && values.Length > 0)
- {
- exceptionMessage = String.Format(exceptionMessage, values);
- }
-
- Assert.True(condition, exceptionMessage);
- }
- else
- {
- Assert.True(condition);
- }
- }
-
- [DebuggerHidden]
- public static T Throws<T>(Action code) where T : Exception
- {
- return Assert.Throws<T>(code);
- }
-
- #endif
+
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4b4d4d93/test/Lucene.Net.TestFramework/Util/TestAttribute.cs
----------------------------------------------------------------------
diff --git a/test/Lucene.Net.TestFramework/Util/TestAttribute.cs b/test/Lucene.Net.TestFramework/Util/TestAttribute.cs
deleted file mode 100644
index 158afa6..0000000
--- a/test/Lucene.Net.TestFramework/Util/TestAttribute.cs
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * 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.
- */
-
-namespace Lucene.Net.Util
-{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Xunit.Abstractions;
- using Xunit.Sdk;
-
- /// <summary>
- /// Summary description for TestAttribute
- /// </summary>
- public class TestAttribute : Xunit.FactAttribute
- {
-
- public string JavaMethodName { get; set; }
-
- public TestAttribute(string displayName, string javaMethodName = null, string skip = null)
- {
- this.DisplayName = displayName;
- this.Skip = skip;
- this.JavaMethodName = javaMethodName;
- }
-
- public TestAttribute()
- {
- }
- }
-
- [TraitDiscoverer("TicketDiscoverer", "TraitExtensibility")]
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
- public class TicketAttribute : System.Attribute, Xunit.Sdk.ITraitAttribute
- {
- public string Ticket { get; private set; }
-
- public string Description { get; private set; }
-
- public TicketAttribute(string ticket, string description)
- {
- this.Ticket = ticket;
- this.Description = description;
- }
- }
-
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
- public class PerfAttribute : CategoryAttribute
- {
-
- public PerfAttribute()
- : base("Performance")
- {
-
- }
- }
-
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
- public class NightlyAttribute : CategoryAttribute
- {
-
- public NightlyAttribute()
- : base("Nightly")
- {
-
- }
- }
-
- [TraitDiscoverer("CategoryDiscoverer", "TraitExtensibility")]
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
- public class CategoryAttribute : System.Attribute, Xunit.Sdk.ITraitAttribute
- {
- public string Name { get; private set; }
-
- public CategoryAttribute(string category)
- {
- this.Name = category;
- }
- }
-
- /// <summary>
- /// This class discovers all of the tests and test classes that have
- /// applied the Category attribute
- /// </summary>
- public class TicketDiscoverer : ITraitDiscoverer
- {
- /// <summary>
- /// Gets the trait values from the Category attribute.
- /// </summary>
- /// <param name="traitAttribute">The trait attribute containing the trait values.</param>
- /// <returns>The trait values.</returns>
- public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
- {
- var ctorArgs = traitAttribute.GetConstructorArguments().ToList();
- var message = "";
-
- if(ctorArgs.Count > 0)
- message = ctorArgs[1].ToString();
-
-
- yield return new KeyValuePair<string, string>("Ticket", ctorArgs[0].ToString());
- yield return new KeyValuePair<string, string>("Ticket Description", message);
- }
- }
-
- /// <summary>
- /// This class discovers all of the tests and test classes that have
- /// applied the Category attribute
- /// </summary>
- public class CategoryDiscoverer : ITraitDiscoverer
- {
- /// <summary>
- /// Gets the trait values from the Category attribute.
- /// </summary>
- /// <param name="traitAttribute">The trait attribute containing the trait values.</param>
- /// <returns>The trait values.</returns>
- public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
- {
- var ctorArgs = traitAttribute.GetConstructorArguments().ToList();
- yield return new KeyValuePair<string, string>("Category", ctorArgs[0].ToString());
- }
- }
-}
\ No newline at end of file