我有这样的代码
[ DataContract ]
public sealed class ProductName
{
[ DataMember( Order = 1 ) ]
public string Name { get; private set; }
public static readonly ProductName Undefined = Create( "Unknown" );
private ProductName()
{
}
private ProductName( string Name )
{
this.Name = Name.Trim();
}
public static ProductName Create( string Name )
{
Condition.Requires( Name, "Name" ).IsNotNullOrEmpty();
return new ProductName( Name );
}
public static ProductName TryCreate( string Name )
{
return Name.IsValidName() ? new ProductName( Name ) : null;
}
public override string ToString()
{
return this.Name;
}
public override int GetHashCode()
{
var stableHashCodeIgnoringCase = this.Name.GetStableHashCodeIgnoringCase();
return stableHashCodeIgnoringCase;
}
#region Equality members
public bool Equals( ProductName other )
{
if( ReferenceEquals( null, other ) )
return false;
if( ReferenceEquals( this, other ) )
return true;
return string.Equals( this.Name, other.Name, StringComparison.InvariantCultureIgnoreCase );
}
public override bool Equals( object obj )
{
if( ReferenceEquals( null, obj ) )
return false;
if( ReferenceEquals( this, obj ) )
return true;
if( obj.GetType() != this.GetType() )
return false;
return this.Equals( ( ProductName )obj );
}
#endregion
}
[ DataContract ]
public class ProductNameIndex
{
[ DataMember( Order = 1 ) ]
public IDictionary< ProductName, ProductId > Products{ get; private set; }
public ProductNameIndex()
{
this.Products = new Dictionary< ProductName, ProductId >();
}
}
我想对Foo进行单元测试,我要测试的一件事是在Process方法中调用某些对象(我有权访问)。问题是在单元测试中进行检查后调用Process方法。如何测试它以使其更加同步?