I have the class below--UserInfo. I can insert the following code into main method:to test my class
however I need to use the NUnit Framework to test it (the web-site
www.nunit.org). I have attached the NUnit_UserInfo.txt file - I'm using the NUnit Framework to test.
My question is:
1) Am I using NUnit Framework correctly?? What would be the best approach??
2) How can I test to ensure the UserInfo can be safely serialized and de-serialized??
b1 = new UserInfo("Bill Smith", "BSMITH");
b2 = new UserInfo("Bill Smith", "BSMITH");
System.Console.WriteLine( b1.Equals(b1) ); // prints true
System.Console.WriteLine( b1.Equals(b2) ); // prints true
**************************
**
namespace abc
{
[Serializable()]
public class UserInfo
{
private String _name; //
private String _userId; //
public String Name
{
get { return _name; }
set { _name = value; }
}
public String UserId
{
get { return _userId; }
set { _userId = value; }
}
/// <summary>
/// Default constructor necessary for
/// XML serialization
/// </summary>
public UserInfo()
{
_name = String.Empty;
_userId = String.Empty;
}
public UserInfo(String name, String userId)
{
this._name = name;
this._userId = userId;
}
public override bool Equals(object obj)
{
if ((object)obj == null)
return false;
if(!(obj is UserInfo))
return false;
return (this._name == (obj as UserInfo)._name) && (_userId == (obj as UserInfo)._userId);
}
public override string ToString()
{
return String.Format("{0}: {1}", _userId, _name);
}
public override int GetHashCode()
{
return this.ToString().GetHashCod
e();
}
}
}
Start Free Trial