c# - IInvokeProvider.Invoke in NUnit Test -


i have wpf user control writing unit tests using nunit. 1 of tests displays control on window , clicks button on control. after looks confirm correct result received.

using raisedevents looks , works correctly.

mybutton.raiseevent(buttonargs); assert.areequal(expected, actual); 

i trying same thing using automation framework. like:

buttonautomationpeer peer = new buttonautomationpeer(mybutton); iinvokeprovider invokeprov = (iinvokeprovider)(peer.getpattern(patterninterface.invoke)); invokeprov.invoke(); assert.areequal(expected, actual); 

now in case assert fails (as expected) because invoke called asynchronously , has not yet occurred @ time of assertion.

i hoping resolve calling invoke on separate thread , waiting complete.

thread thread = new thread(invokeprov.invoke); thread.start(); thread.join(); 

however still fails. sleeping:

invokeprov.invoke(); thread.sleep(1000); 

showing dialog , forcing user continue, work.

invokeprov.invoke(); system.windows.messagebox.show(""); 

so think there sort of setup need things behave way like. perhaps setting separate thread dispatcher, or window. i'm sure there examples of out there, seem not searching on right key words. note nunit requiring me run unit tests requiressta attribute.

i think conclusion correct. iinvokeprovider.invoke async same way dispatcher.begininvoke async. puts message queue dispatcher process. not starting thread's dispatcher until show message box. want this process dispatcher operations in test thread.

public static void doevents() {     dispatcherframe frame = new dispatcherframe();     dispatcher.currentdispatcher.begininvoke(dispatcherpriority.background,             new dispatcheroperationcallback(exitframe), frame);     dispatcher.pushframe(frame); }  public static object exitframe(object f) {     ((dispatcherframe)f).continue = false;     return null; } 

which can used so:

buttonautomationpeer peer = new buttonautomationpeer(mybutton); iinvokeprovider invokeprov = (iinvokeprovider)(peer.getpattern(patterninterface.invoke)); invokeprov.invoke(); doevents(); assert.areequal(expected, actual); 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -