Click here to Skip to main content
15,880,608 members
Articles / Programming Languages / C#

Writing NHibernate Level 2 Cache Usage Tests

Rate me:
Please Sign up or sign in to vote.
4.69/5 (7 votes)
15 Jan 2009CPOL8 min read 52.6K   121   22  
Writing NHibernate Level 2 caching related tests by utilizing a custom log4net appender.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Domain
{
  public class CompositeId
  {
    public int Id1 { get; internal set; }
    public int Id2 { get; internal set; }
    public CompositeId(int id1, int id2)
    {
      Id1 = id1;
      Id2 = id2;
    }
    
    internal CompositeId(){}

    public override bool Equals(object obj)
    {
      if (obj == null || !(obj is CompositeId))
        return false;

      CompositeId inObj = obj as CompositeId;
      return CompositeId.AreEqual(this, inObj);
    }

    public override int GetHashCode()
    {
      int hash = 7;
      hash = 3 * hash + Id1;
      hash = 3 * hash + Id2;
      return hash;
    }

    public static bool operator ==(CompositeId t1, CompositeId t2)
    {
      return CompositeId.AreEqual(t1, t2);
    }

    public static bool operator !=(CompositeId t1, CompositeId t2)
    {
      return !CompositeId.AreEqual(t1, t2);
    }

    private static bool AreEqual(CompositeId t1, CompositeId t2)
    {
      object objt1 = t1;
      object objt2 = t2;

      return (objt1 == null && objt2 == null) || (objt1 != null && objt2 != null && (t1.Id1 == t2.Id1 && t1.Id2 == t2.Id2));
    }
  }

  public class CompositeEntity
  {
    public virtual CompositeId Id { get; internal set; }
    public virtual string Data { get; set; }
    
    public CompositeEntity(int id1, int id2)
    {
      Id = new CompositeId(id1, id2);
    }

    public CompositeEntity(CompositeId id)
    {
      Id = id;
    }

    internal CompositeEntity()
    {
    
    }

  }


}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader PragmaTouch
Turkey Turkey
- Software developer
- Has BS degree in Computer Engineering
- Has MBA degree
- Programmed with C, C++, Delphi, T-SQL and recently C#
- Little educational experience with Prolog
- Feel enthusiasm about NHibernate and LINQ
- Love to develop on Cuyahoga Web Framework
- Developer of PragmaSQL Editor
(Code Project Members Choice Winner for 2009 and 2010)
- Developed JiraTouch and MoodleTouch for iPhone
- PragmaTouch Lead (www.pragmatouch.com)

Comments and Discussions