トップ «前の日記(2006/10/15 [日]) 最新 次の日記(2006/10/19 [木])» 編集

その他雑多なこと(tDiary版)

2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|12|
2012|01|02|03|04|05|06|07|

2006/10/18 [水] [長年日記]

_ [PC] NUnitとNMock

メモ

NUit.Mock @IT記事

NMock2 NMock2.pdf

@IT記事NUnitサンプル NMock2書き換え

using namespace NMock2;
using namespace NUnit::Framework;
namespace SimpleMock
{
	public interface class  ISystemWriter 
	{
	public:
		bool	IsReady();
		void	Write(String^	name, String^	val);
		void	Close();
	};
	public ref class SimpleMock : public MarshalByRefObject
	{
	private:
		ISystemWriter^	writer;
	public:
		SimpleMock(void);
		void Write(ISystemWriter^	writer, int	count);
	};
};
namespace SimpleMock
{
	SimpleMock::SimpleMock(void) {};
	void SimpleMock::Write(ISystemWriter^	writer, int count){
		if (! writer->IsReady()) {
			return;
		}
		for(int i=0; iWrite("count", i.ToString());
		}
		writer->Close();
	};
};
namespace SimpleMockTest {
	[TestFixture]
	public ref class SimpleMockTest
	{
	private:
		Mockery^	mock;
	public:
		SimpleMockTest(void)
		{
		};
		[Test]
		[Category("SipleMockTest")]
		void MockTest()
		{
			mock = gcnew Mockery();
			SimpleMock::ISystemWriter^ aMock = mock->NewMock();
			Expect::Once->On(aMock)->Method("IsReady")->WithNoArguments()->Will(Return::Value(true));
			Expect::Once->On(aMock)->Method("Write")->With("count", "0");
			Expect::Once->On(aMock)->Method("Write")->With("count", "1");
			Expect::Once->On(aMock)->Method("Write")->With("count", "2");
			Expect::Once->On(aMock)->Method("Close");
			SimpleMock::SimpleMock^ Test = gcnew SimpleMock::SimpleMock;
			Test->Write(aMock, 3);
			mock->VerifyAllExpectationsHaveBeenMet();
		};
	};
};
本日のリンク元
その他のリンク元
検索

辞書