I tried to set up unit test for a private inner class, but had very little success:
namespace Stats.Model
{
public class DailyStat
{
private class DailyStatKey
{
private DateTime date;
public DateTime Date
{
get { return date; }
set { date = value.Date; }
}
public StatType Type { get; set; }
public override int GetHashCode()
{
return Date.Year * 1000000 +
Date.Month * 10000 +
Date.Day * 100 +
(int)Type;
}
public override bool Equals(object obj)
{
DailyStatKey otherKey = obj as DailyStatKey;
if (otherKey == null)
return false;
return (this.Date == otherKey.Date && this.StatType == otherKey.StatType);
}
}
}
}
I tried this code:
PrivateType statKeyType = new PrivateType("Stats.Model", "Stats.Model.DailyStat.DailyStatKey");
and
PrivateType statKeyType = new PrivateType("Stats.Model", "DailyStat.DailyStatKey");
To no avail.
The assembly name is "Stats.Model" and for me the type name looks correct, but I just get an exception: "System.TypeLoadException: failed to load type"
So what am I doing wrong?
PrivateType, as far as I know, is based on reflection, and I would suggest that it is largely intended for this scenario, since you cannot have a private class directly below the namespace.
EDIT:
Added full implementation of DailyStatKey. What I want to check out is the uniqueness of the GetHashCode method. As you can see, I'm trying to set date + type to one int.