20 May 2010

Rhinomocks stub mulitple return values

Rhinomocks stubbing is great, but sometimes we need a stubbed instance to return different values.

[Test]
public void gggg()
{
var myobject = MockRepository.GenerateStub<IMyInterface>();
myobject.Stub(x => myobject.MyMethod()).Return("woof");
myobject.Stub(x => x.MyMethod()).Return("croak");

In this case MyMethod will always return “woof”. The “croak” will only be return if we use the .Repeat statements to tell Rhinomocks to limit the usage of the values.

[Test]
public void gggg()
{
var myobject = MockRepository.GenerateStub<IMyInterface>();
myobject.Stub(x => myobject.MyMethod()).Return("woof").Repeat.Once();
myobject.Stub(x => x.MyMethod()).Return("croak");
}
Here the first call to MyMethod will return “woof”, all subsequent calls will return “croak”.

04 May 2010

GeckoFx: Accessing the Document Elements

When using the GeckoFx version 1.9.1.0 browser control. it is important to use the correct version of the XULRunner.
When I tried to access the Document Elements with the 1.9.1.0 version of the XULRunner with this code:
geckoBrowser.Document.GetElementById("_mainTableDiv");
this is the error I encountered:
“Unable to cast COM object of type 'System.__ComObject' to interface type 
'Skybound.Gecko.nsIDOMNSElement'. This operation failed because the 
QueryInterface call on the COM component for the interface with 
IID '{F0AEF489-18C5-4DE6-99D5-58B3758B098C}' failed due to the following 
error: No such interface supported (Exception from HRESULT: 0x80004002 
(E_NOINTERFACE)).”

It was fixed by using the 1.9.1.4 version of the XULRunner.
Hope this helps someone.