1

I am using Teststack.White to launch and interact with a GUI. The Model is hidden behind a facade, that allows a testing mock to be injected into the GUI. The GUI successfully loads the testing mock and Teststack.White can launch the application.

How can I access my singleton using the Teststack.White.Application or means of this sort.

enter image description here

    /*Singleton in Mock.DLL that will allow test configurations*/
    class Hook
    {
        public Hook SingleHook { get; private set; } = new Hook();
        private Hook() { }
    }

    /*Loader in Nunit so far*/

    private Application apploader()
    {
        ProcessStartInfo info = new ProcessStartInfo(@"C:\MyGUI\MYWPFGUI.exe");
        info.WorkingDirectory = (@"C:\MyGUI\");
        TestStack.White.Application app = Application.Launch(info);
        return app;
    }

I am currently investigating using AppDomains but since this Application is running in its won process i can not see how I would do that. I need to get a hold of Singleton in order to setup and evaluate my tests.

Johannes
  • 6,490
  • 10
  • 59
  • 108
  • 1
    I'm not familiar with white but from what I understand you need access to objects of another process.I guess you need to search for inter process communication – George Vovos Jan 27 '17 at 15:31
  • @GeorgeVovos Can you make your comment into an answer? I would reward my bounty to it. – Johannes Feb 02 '17 at 13:52
  • I can,but it wasn't much of an answer...Also,wait in case someone else post anything better – George Vovos Feb 02 '17 at 13:55
  • @GeorgeVovos I think IPC using WCF Naming Pipes is exactly what I need since i can edit the Mock.dll. I have 23 hours on my bounty left and I am on German time, so I will be awake when I can set the bounty in 23 hours. – Johannes Feb 02 '17 at 13:58

2 Answers2

0

You need to use reflection, first step is to Load the assembly that holds the Hook class by using Assembly.Load or Assembly.LoadFrom , then you use Assembly.CreateInstance or Activator.CreateInstance or AppDomain.CreateInstanceAndUnwrap methods and pass the Hook class type, now you cannot create the singleton from outside and then call CreateInstance to create it since it has private ctor, otherwise you need to use other means like GetMethod and Invoke from the Hook Singleton type to access its methods which is too much hassle.

However, i would suggest you create the class as normal class and hold a singleton instance in Test application, so make sure to mark your Hook class as public class with public constructor and in the Test project create a public static property/variable to hold the created class with reflection and then you can access the Singleton Hook class anywhere in the Test application by just calling the static property.

YazX
  • 444
  • 4
  • 12
  • Realoding the dll would not do anything for me. You see, the other Process has the dll loaded, If the testing process also loads the assembly both end up talking to different assebmlies that are not connected. – Johannes Jan 30 '17 at 08:11
  • 1
    ah now i understand, well if you want to use the same class and not an new instance from it, then you need to expose functionalities from that class either via COM+, services (WCF net.tcp is an option) or file system where you drop commands to a file and the class has FileSystemWatcher (easiest way) to monitor the changes, then read the changes and execute the necessary procedure. – YazX Feb 02 '17 at 15:32
0

I think the only way to do that is using some sort of inter process communication.

There are many example on google on here on SO here or here

Community
  • 1
  • 1
George Vovos
  • 7,563
  • 2
  • 22
  • 45