On the first issue (logging), you need to refactor your logging into
an interface. Rhino.Mocks doesn't support intercepting static
methods, so you can't set expectations or anything on
Log.Instance.WriteEntry().
On the second issue, you should be able to do something like:
var user1 = new TopUser { Name = "abc" };
var user2 = new TopUser { Name = "def" };
var user3 = new TopUser [ Name = "xyz" };
var myStub = MockRepository.GenerateStub<ISomeObject>();
myStub.Stub(s => s.DoMyBest(user1)).Returns(...);
myStub.Stub(s => s.DoMyBest(user2)).Returns(...);
myStub.Stub(s => s.DoMyBest(user3)).Returns(...);
Rhino mocks will return a specific value based on which TopUser you send to it.
---
Patrick Steele
http://weblogs.asp.net/psteele
On Thu, Oct 21, 2010 at 12:13 PM, Lonli-Lokli <[email protected]> wrote:
> Hello.
>
> there is a scenario.
> I have an app I want to test - I create parameters for the class,
> initialize it and trying to test some method like
> TryToKnowEveryting().
> this is a huge method with several private methods, each of them
> trying to validate input params and writing to the static Log.Instance
> instance, method WriteEntry(string error, Exception ex, int
> errorCategory) for example.
>
> Now the problem - I want to test different input values and check
> expecting exceptions. I can do it via
> Log.Instance.GetArgumentsForCallsMadeOn(log => log.WriteEntry(null,
> null, 0)); and then trying to get internal objects. But this behaviour
> is not very good - I want to replace default method with the test one.
>
> I tried this code, but this doesn't work
>
> private List<Exception> _exceptions = new List<Exception>(); - class
> field
>
> ILog log = MockRepository.GenerateStub<ILog>();
> log.Stub(log2 => (Action<string, Exception, int>)
> ((error, ex, category) =>
> _exceptions.Add(ex))); -
> initializing.
>
>
> Connected question is how can I tell RhinoMock, that in case when
> param for method IList<TopActions> DoMyBest(TopUser user) is one
> TopUser, it should return one set of values, if another - another. If
> it's not one of these two users, it should return third set.
>
> --
> 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.
>
>
--
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.