UnitTest برای کلاس های Abstract با استفاده از Rhino Mocks
نویسنده: مسعود پاکدل
تاریخ: ۱۳۹۱/۱۱/۲۳ ۱۲:۴۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
public abstract class myabstractclass
{
public abstract string dosomething( string input );
public double round( double number , int decimals )
{
return math.round( number , decimals );
}
} public class mynewclass : myabstractclass
{
public override string dosomething( string input )
{
return input;
}
} [testclass]
public class mytest
{
[testmethod]
public void testround()
{
mynewclass mynewclass = new mynewclass();
var result = mynewclass.round( 5.55 , 1 );
assert.areequal( 5.6 , result );
}
}
[testmethod]
public void testwithmockrepository()
{
var mockrepository = new rhino.mocks.mockrepository();
var mock = mockrepository.partialmock<myabstractclass>();
using ( mockrepository.record() )
{
expect.call( mock.dosomething( arg<string>.is.anything ) ).return( "hi..." ).repeat.once();
}
using ( mockrepository.playback() )
{
assert.areequal( "hi..." , mock.dosomething( "salam" ) );
}
} [testmethod]
public void testwithaaa()
{
var mock = mockrepository.generatepartialmock<myabstractclass>();
mock.expect( x => x.dosomething( arg<string>.is.anything ) ).return( "hi..." ).repeat.once();//arange
var result = mock.dosomething( "salam" );//act
assert.areequal( "hi..." , result );//assert
} [testmethod]
public void testwithaaa()
{
var mock = mockrepository.generatepartialmock<myabstractclass>();
mock.expect( x => x.dosomething( arg<string>.is.anything ) ).return( "hi..." ).repeat.once();//arange
var result = mock.dosomething( "salam" );//act
var result2 = mock.dosomething( "bye" );//act
assert.areequal( "hi..." , result );//assert
}