This project is read-only.

UnitTest Test Funktionen

Wie Eingangs erwähnt sind die Test Funktionen mittels .Net-Extensions implementiert.
Für folgende Typen gibt es typisierte Test Funktionen:
  • Int (Int32)
  • UInt (UInt32)
  • Decimal
  • Double
  • Float
  • String
  • Object
  • Enum
  • IList / ICollection
  • Delegate

Int / UInt / Decimal / Double / Float

Die verfügbaren Test Funktionen für die Typen Int, UInt, Decimal, Double, Float find identisch:
Unit_IsEqual(this int pActualValue, int pDesiredValue)
Unit_IsEqual(this int pActualValue, int pDesiredValue, string pErrorMessage)
Unit_IsNotEqual(this int pActualValue, int pDesiredValue)
Unit_IsNotEqual(this int pActualValue, int pDesiredValue, string pErrorMessage)
Unit_IsGreater(this int pActualValue, int pDesiredValue)
Unit_IsGreater(this int pActualValue, int pDesiredValue, string pErrorMessage)
Unit_IsGreaterOrEqual(this int pActualValue, int pDesiredValue)
Unit_IsGreaterOrEqual(this int pActualValue, int pDesiredValue, string pErrorMessage)
Unit_IsLessOrEqual(this int pActualValue, int pDesiredValue)
Unit_IsLessOrEqual(this int pActualValue, int pDesiredValue, string pErrorMessage)
Unit_IsLess(this int pActualValue, int pDesiredValue)
Unit_IsLess(this int pActualValue, int pDesiredValue, string pErrorMessage)
Beispiele:
10.Unit_IsEqual(10);
11.Unit_IsNotEqual(10);

double Value = 33.5;
Value.Unit_IsGreater(20);
Value.Unit_IsGreaterOrEqual(33.5);

10.Unit_IsLessOrEqual(10);
10.Unit_IsLess(20);

String

Für den Typ String gibt es folgende Test Funktionen:
Unit_IsEqual(this string pActualValue, string pDesiredValue)
Unit_IsEqual(this string pActualValue, string pDesiredValue, string pErrorMessage)
Unit_IsNotEqual(this string pActualValue, string pDesiredValue)
Unit_IsNotEqual(this string pActualValue, string pDesiredValue, string pErrorMessage)
Unit_IsEmpty(this string pActualValue)
Unit_IsEmpty(this string pActualValue, string pErrorMessage)
Unit_IsNotEmpty(this string pActualValue)
Unit_IsNotEmpty(this string pActualValue, string pErrorMessage)
Beispiele:
"Hallo".Unit_IsEqual("Hallo");
"Hallo".Unit_IsNotEqual("Bye");
"".Unit_IsEmpty();
"123".Unit_IsNotEmpty();

Object

Für den Typ Object gibt es folgende Test Funktionen:
Unit_IsEqual(this object pActualValue, object pDesiredValue)
Unit_IsEqual(this object pActualValue, object pDesiredValue, string pErrorMessage)
Unit_IsNotEqual(this object pActualValue, object pDesiredValue)
Unit_IsNotEqual(this object pActualValue, object pDesiredValue, string pErrorMessage)
Unit_IsNull(this object pObj)
Unit_IsNull(this object pObj, string pErrorMessage)
Unit_IsNotNull(this object pObj)
Unit_IsNotNull(this object pObj, string pErrorMessage)
Beispiele:
DemoClass_Equals ObjEO1 = new DemoClass_Equals() { Name = "Demo", Date = new DateTime(2010, 06, 18) };
DemoClass_Equals ObjEO2 = new DemoClass_Equals() { Name = "Demo", Date = new DateTime(2010, 06, 18) };

DemoClass Obj1 = new DemoClass() { Name = "Demo", Date = new DateTime(2010, 06, 18) };
DemoClass Obj2 = new DemoClass() { Name = "Demo", Date = new DateTime(2010, 06, 18) };

ObjEO1.Unit_IsEqual<DemoClass_Equals>(ObjEO2); //Use Overrided Equals-Methode
Obj1.Unit_IsNotEqual<DemoClass>(Obj2); //Use Object Equals-Methode, is check the references and they are different

object Obj = null;
Obj.Unit_IsNull();

Obj = new object();
Obj.Unit_IsNotNull();
Benutze Demoklassen:
public class DemoClass_Equals
{
    public String Name { get; set; }
    public DateTime Date { get; set; }

    public DemoClass_Equals() { }

    public override bool Equals(object obj)
    {
        if (obj as DemoClass_Equals != null)
        {
            var Value2 = (DemoClass_Equals)obj;
            return (this.Name == Value2.Name && this.Date == Value2.Date);
        }
        else return this == obj;
    }
}

public class DemoClass
{
    public String Name { get; set; }
    public DateTime Date { get; set; }

    public DemoClass() { }
}

Enum

Für den Typ Enum gibt es folgende Test Funktionen:
Unit_IsEqual(this Enum pActualValue, Enum pDesiredValue)
Unit_IsEqual(this Enum pActualValue, Enum pDesiredValue, string pErrorMessage)
Unit_IsNotEqual(this Enum pActualValue, Enum pDesiredValue)
Unit_IsNotEqual(this Enum pActualValue, Enum pDesiredValue, string pErrorMessage)
Unit_FlagContains(this Enum pActualValue, Enum pContainsValue)
Unit_FlagContains(this Enum pActualValue, Enum pContainsValue, string pErrorMessage)
Beispiele:
var Enum1 = TestValues.Value1;
var Enum2 = TestValues.Value1;

Enum1.Unit_IsEqual(Enum2);
Enum2.Unit_IsNotEqual(TestValues.value3);

(TestValues.Value1 | TestValues.value2).Unit_FlagContains(TestValues.value2);
Demo Enum:
[Flags]
 public enum TestValues
{
    Value1,
    value2,
    value3
}

Bool

Für den Typ Enum gibt es folgende Test Funktionen:
Unit_IsTrue(this bool pActualValue)
Unit_IsTrue(this bool pActualValue, string pErrorMessage)
Unit_IsFalse(this bool pActualValue)
Unit_IsFalse(this bool pActualValue, string pErrorMessage)
Beispiele:
true.Unit_IsEqual<bool>(true);
true.Unit_IsNotEqual<bool>(false);

(10 == 10).Unit_IsTrue();
(10 == 11).Unit_IsFalse();

IList / ICollection

Für Typen die IList / ICollection implementieren gibt es folgende Test Funktionen:
Unit_Contains(this IList pList, object pContains)
Unit_Contains(this IList pList, object pContains, string pErrorMessage)
Unit_IsItemCount(this ICollection pCollection, int pDesiredValue)
Unit_IsItemCount(this ICollection pCollection, int pDesiredValue, string pErrorMessage)
Beispiele:
System.Collections.Generic.List<DemoClass> ObjList = new System.Collections.Generic.List<DemoClass>();
ObjList.Add(Obj1);
ObjList.Add(Obj2);

ObjList.Unit_IsItemCount(2);
ObjList.Unit_Contains(Obj2);

Delegate

Für Delegates gibt es folgende Test Funktionen:
Unit_ThrowException<RaisedException>(this Delegate pDel, object[] args) where RaisedException : Exception
Unit_ThrowException<RaisedException>(this Delegate pDel, string pErrorMessage, object[] args) where RaisedException : Exception
object Unit_ThrowNoException<RaisedException>(this Delegate pDel, object[] args) where RaisedException : Exception
object Unit_ThrowNoException<RaisedException>(this Delegate pDel, string pErrorMessage, object[] args) where RaisedException : Exception
Beispiele:
Action A_Throw = new Action(delegate() { throw new ArgumentException("Don't be null", "Parameter"); });
A_Throw.Unit_ThrowException<ArgumentException>(null);

Action A_NoThrow = new Action(delegate() { bool DoSomething = true; DoSomething = false; });
A_NoThrow.Unit_ThrowNoException<ArgumentException>(null);






This WikiPage was created with Codeplex WikiEditor

Last edited Jun 23, 2010 at 10:01 PM by SoftHai, version 4

Comments

No comments yet.