You can't mock static methods with Rhino Mocks.  It depends on Dynamic
Proxy to intercept method calls via an interface or virtual methods on
your class.  Since static methods are not overiddable, you can't mock
them.

Your choices are to refactor the code to not use statics or consider a
mocking framework like TypeMock that can mock static methods.  But I
don't think TypeMock is free...

---
Patrick Steele
http://weblogs.asp.net/psteele



On Sat, Jan 23, 2010 at 10:20 AM, Asif <[email protected]> wrote:
> Hello all,
> Here is an example of a piece of code and I want to check this
> method's functionality . Please look on this method carefully. This
> class contains a static method SaveBonus .I want to test this method
> with RhinoMock. Here CRUDBuilder is another class of my application.
> Database class is from dll of Microsoft.Practices. ....
> Please show me the Test Method for this case
> public class BonusDC
>    {
>
> public static void SaveBonus(Bonus objBonus)
>        {
>            int vResult = 0;
>            Database vDB = DatabaseFactory.CreateDatabase();
>            try
>            {
>                if (objBonus.IsNew)
>                    vResult = vDB.ExecuteNonQuery(CommandType.Text,
> CRUDBuilder.CREATEQuery(objBonus));
>                else
>                    vResult = vDB.ExecuteNonQuery(CommandType.Text,
> CRUDBuilder.UPDATEQuery(objBonus));
>            }
>            catch (DbException ex)
>            {
>                bool rethrow = ExceptionPolicy.HandleException(ex,
> "Data Context Exception Policy");
>                if (rethrow)
>                    throw;
>
>            }
>        }
>
> }

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en.

Reply via email to