Listing 1

public class User
{
	ArrayList roles;
	Authorizer auth;

	public User(Authorizer auth)
	{
		this.auth = auth;
	}

	public void Authorize()
	{
		ArrayList roles = new ArrayList();
		roles = auth.Authorize();
	}

	public ArrayList Roles
	{
		get
		{
			return roles;
		}
	}
}

public interface Authorizer
{
	ArrayList Authorize();
}

Listing 2

[TestFixture]
	public class UserTest
	{
		[Test]
		public void VerifyRoleRetrieval()
		{
			Mock mock = new DynamicMock(typeof(Authorizer));
			User user = new User((Authorizer)mock.MockInstance);

			mock.Expect("Authorize", new IsEqual("derek"));

			user.Authorize("derek");
			Assert.AreEqual(5, user.Roles.Count);

			mock.Verify();
		}
	}

	public class User
	{
		ArrayList roles;
		Authorizer auth;

		public User(Authorizer auth)
		{
			this.auth = auth;
		}

		public void Authorize(string username)
		{
			ArrayList roles = new ArrayList();
			roles = auth.Authorize(username);
		}

		public ArrayList Roles
		{
			get
			{
				return roles;
			}
		}
	}

	public interface Authorizer
	{
		ArrayList Authorize(string user);
	}

Listing 3

[TestFixture]
	public class UserTest
	{
		[Test]
		public void VerifyRoleRetrieval()
		{
			Mock mock = new DynamicMock(typeof(Authorizer));
			ArrayList retval = new ArrayList();
			for (int i = 0; i < 5; i++)
			{
				retval.Add("");
			}

			User user = new User((Authorizer)mock.MockInstance);
mock.ExpectAndReturn("Authorize", retval, new IsEqual("derek"));

			user.Authorize("derek");
			Assert.AreEqual(5, user.Roles.Count);

			mock.Verify();
		}
	}

	public class User
	{
		Authorizer auth;
		ArrayList roles;

		public User(Authorizer auth)
		{
			this.auth = auth;
		}

		public void Authorize(string username)
		{
			this.roles = auth.Authorize(username);
		}

		public ArrayList Roles
		{
			get
			{
				return roles;
			}
		}
	}