using System;
using System.Collections.Generic;
using <<|=BOPROJECTNAME|>>;
using Habanero.Base;
using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.DB;
using Habanero.Util;
using Habanero.Testability;

namespace <<|=BOTestProjectName|>>
{
	/// <summary>
	/// Provides a standard set of utilities to be used by tests for BusinessObjects in this
	/// application.  In addition, each tested BO has a TestUtils class used to create
	/// random test packs.
	///
	/// You can safely add additional utilities to this particular file since it is
	/// only written once.  If you are adding utilities for a specific BO only, rather
	/// add them to the TestUtils class for that BO (usually title TestUtilsCar if Car is the BO).
	/// </summary>
	public class TestUtilsShared
	{

		public static int GetRandomInt()
		{
		  return RandomValueGen.GetRandomInt(0,100000); 
		}

		public static int GetRandomInt(int max)
		{
			 return RandomValueGen.GetRandomInt(0, max); 
		}

		public static int GetRandomInt(int min,int max)
		{
			return RandomValueGen.GetRandomInt(min, max); 
		}

		public static string GetRandomString()
		{
			 return RandomValueGen.GetRandomString();
		}

		public static string GetRandomString(int maxLength)
		{            
			 return RandomValueGen.GetRandomString(maxLength);
		}
		
		public static string GetRandomString(int minLength, int maxLength)
		{ 
		return RandomValueGen.GetRandomString(minLength, maxLength);
		}
		
		public static bool GetRandomBoolean()
		{
		  return RandomValueGen.GetRandomBoolean(); 
		}
		
		public static DateTime GetRandomDate()
		{
			 return RandomValueGen.GetRandomDate();
		}

		public static DateTime GetRandomDate(string max)
		{
			return RandomValueGen.GetRandomDate(max);
		}
		
	    public static DateTime GetRandomDate(string min, string max)
		{
			 return RandomValueGen.GetRandomDate(min,max);
		}

		/// <summary>
		/// Takes a lookup list generated by Habanero and randomly selects a value
		/// from the list
		/// </summary>
		public static object GetRandomLookupListValue(Dictionary<string, string> lookupList)
		{
			 return RandomValueGen.GetRandomLookupListValue(lookupList);
		}


		public static TEnum GetRandomEnum<TEnum>()
			where TEnum : struct
		{
			 return (TEnum) RandomValueGen.GetRandomEnum(null);
		}

		public static TEnum GetRandomEnum<TEnum>(TEnum? excluded)
               where TEnum : struct
        {
            Array values = Enum.GetValues(typeof(TEnum));
            int randomIndex = GetRandomInt(0, values.Length);
            TEnum value = (TEnum)values.GetValue(randomIndex);
            if (excluded.HasValue && excluded.Value.Equals(value))
            {
                  return RandomValueGen.GetRandomEnum(excluded);
            }
               return value;
            }
		
		/// <summary>
		/// Waits for the garbage collector to clear dereferenced objects in order
		/// to ensure accurate testing
		/// </summary>
		public static void WaitForGC()
		{
			GC.Collect();
			GC.WaitForPendingFinalizers();
		}
	}
}