Hi!
You're right Alex. That's why they dont implement the interfaces. I can only
change MyClassA, MyClassB IClassA and IClassB.
Their properties and methods are not virtual so i cannot mock them directly.
I was able to solve it like this.
I changed the IClassA interface to
public interface IClassA
{
public *I*ClassB classb { get; set;} //This is changed to the interface
IClassB
}
Then i added an property to MyClassA to be consistant with the change of the
interface.
public class MyClassA : ClassA, IClassA
{
public IClassB classb
{
get
{
return (IClassB)base.classb;
}
set
{
base.classb = (ClassB)value;
}
}
Since the object is alvays of type MyClassB that inherits ClassB and
implements IClassB the casts work.
Perhaps there's a better solution but i think this was a good one once
realized it was possible.
Best Regards
Fredrik H
2009/11/13 Alex McMahon <[email protected]>
> I believe it's because he doesn't have access to ClassA and ClassB, he only
> has them in binary form.
>
> 2009/11/13 Stefan Steinegger <[email protected]>
>
>>
>> Why does ClassA not implement IClassA, and ClassB not IClassB??
>>
>> You can't mock IClassB when it is referenced by its concrete type. Why
>> is the reference not of type IClassB?
>>
>>
>> On 12 Nov., 09:45, Fredrik H <[email protected]> wrote:
>> > Hi!
>> > I'm currently struggeling with a mocking problem that perhaps someone
>> > can help me find a solution to.
>> >
>> > I'm not able to describe the problem in word so i need to write a
>> > little code.
>> > I have to classes i need to mock that i cannot change. I only have
>> > them in binary form. ClassA and ClassB
>> >
>> > public ClassA
>> > {
>> > public ClassB classb
>> > {
>> > get
>> > {
>> > return _classb;
>> > }
>> > set
>> > {
>> > _classb = value;
>> > }}
>> >
>> > ClassB's implementation is unimportant.
>> >
>> > Since they're not sealed i can create a new class that inherit the
>> > class and implement an interface that specifies the signature of the
>> > class and then mock that interface.
>> >
>> > public interface IClassA
>> > {
>> > public ClassB { get; set;}
>> >
>> > }
>> >
>> > public class MyClassA : ClassA, IClassA
>> > {
>> >
>> > }
>> >
>> > public interface IClassB
>> > {
>> > //any properties
>> >
>> > }
>> >
>> > public class MyClassB : ClassB, IClassB
>> > {
>> >
>> > }
>> >
>> > the problem is that i need to insert a mock in ClassA's classb
>> > property;
>> > _classa.classb = mock.StrictMock(IClassB);
>> > This won't work since the property is of type ClassB, i cannot insert
>> > a IClassB into it.
>> > I've tried changing the interface to IClassB but this causes other
>> > problems.
>> >
>> > Has anyone solved a similar problem?
>> >
>> > Best Regards
>> > Fredrik H
>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---