Thanks Mauro,
I don't think that's quite what I want. I want to mock what is
returned from GetData so that when it is called within the constructor
for Duck ( new Duck(1, GetData(ID), "Black") ) the mocked return
value for GetData(ID) is passed in as a parameter. I hope that made
sense. I don't want to just mock what is returned from GetObject, but
an internal call. Is that possible? Can you give an example as well?
public object GetObject(string Type, string ID)
{
Duck d = new Duck(1, GetData(ID), "Black");
return d;
}
public virtual string GetData(string ID)
{
return "K";
}
Thanks again,
Laura
On Mon, Feb 16, 2009 at 4:20 AM, Mauro Talevi
<[email protected]> wrote:
> Hi Laura,
>
> I'm not familiar with C#, but it seems to me that you're trying to mock
> classes and mock their behaviour by what you call "injections".
>
> In Java-land, the more natural approach would be to have a clean
> interface/impl separation and mock the interface rather than the class.
>
> So, for example, if you have an
>
> interface Repository {
>
> Object getObject(String type, String id);
>
> }
>
> you'd simply use Mockito, or any other mocking framework, to return the
> expected Object to satisfy the behaviour under consideration.
>
> Cheers
>
> Laura Vendramini wrote:
>>
>> Hey!
>>
>> Mockito is the "official" mocking framework for I haven't seen any
>> samples of using Mockito in a practical example using injections.
>> In C#.net you could use moq to inject mocks into methods (not as a
>> parameter).
>>
>> For example:
>> In the class Repository.cs
>> namespace ObjectFactory
>> {
>> public class Repository
>> {
>>
>> public object GetObject(string Type, string ID)
>> {
>> Duck d = new Duck(1, GetData(ID), "Black");
>> return d;
>> }
>>
>> public virtual string GetData(string ID)
>> {
>> return "K";
>> }
>> }
>> }
>>
>> In the class RepositoryTest.cs
>> using NUnit.Framework;
>> using Moq;
>>
>> namespace ObjectFactory
>> {
>> [TestFixture]
>> public class RepositoryTest
>> {
>> [Test]
>> public void TestGetObject()
>> {
>> Duck d = new Duck(1, "Ducky", "Black");
>> var mock = new Mock<Repository>();
>> mock.Expect(x =>
>> x.GetData(It.IsAny<string>())).Returns("Ducky");
>> Duck getValue = (Duck)mock.Object.GetObject("Duck", "1");
>> Assert.AreEqual(getValue, d);
>> mock.Verify();
>> }
>> }
>> }
>>
>> Instead of GetData returning "K" like it should, it returns "Ducky"
>>
>>
>> Is this possible using Mockito? If so, does anyone have an example?
>>
>>
>> Thanks,
>>
>> Laura
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email