How to create a proxy object that redirects method calls in C #?

I am trying to use selenium to run tests; There seems to be no good way to run the same set of unit tests in multiple browsers.

I read this post about running tests in parallel: http://slmoloch.blogspot.com/2009/12/design-of-selenium-tests-for-aspnet_19.html

However, I use the visual studio testing infrastructure.

I can create a proxy class as follows:

public class SeleniumProxy {
    private List<DefaultSelenium> targets;
    public SeleniumProxy() {
        targets = new List<DefaultSelenium>();
        targets.Add(new DefaultSelenium(... "firefox"...));
        targets.Add(new DefaultSelenium(... "iexplore"...));
    }
    public void Open(String url) {
        foreach (var i in targets) {
            i.Open(url);
        }
    }
    ...
}

My question is this? How can I do this without rewriting the entire class as a proxy?

I thought that maybe I passed lamda in to match the arguments or passed a function that takes the name of the method to call, but it all seems like pretty lame ideas.

I really want to add a member, for example:

public class SeleniumProxy {
    public dynamic proxy;
    ....
}

And call it like:

var selenium = getProxy();
selenium.proxy.Open("...");

# ?

- - , - ?

: -, ?

(: ... DefaultSelenium - ..?)

+3
2

, , , DynamicObject, .

class Proxy : System.Dynamic.DynamicObject
{
    public Proxy(object someWrappedObject) { ... }

    public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
    {
      // Do whatever, binder.Name will be the called method name
    }
}

//Do whatever... , pokes (), binder.Name .

TryGetMember TryGetIndex , - , .

Proxy dynamic , , ExpandoObject.

0

factory selenium, , . . NUnit :

public abstract class AbstractTests
{
    protected abstract DefaultSelenium CreateSelenium();

    [Test]
    public void TestSomethingA()
    {
        DefaulSelenium selenium = CreateSelenium();

        //Do some testing with selenium.
    }
}

[TestFixture]
public class IETests : AbstractTests
{
    protected override DefaultSelenium CreateSelenium()
    {
        return new DefaultSelenium("iexplore");
    }
}

[TestFixture]
public class FirefoxTests : AbstractTests
{
    protected override DefaultSelenium CreateSelenium()
    {
        return new DefaultSelenium("firefox");
    }
}
0

All Articles