public void ShouldDispatchOnDispatcherThreadForDispatcherObjects() { using (var dt = new DispatcherThread()) { var root = dt.Invoke(() => new DispatcherRoot()); var dispatcher = DispatcherFactory.CreateDispatcher(root, _endpoint.Object, false); dispatcher.Execute("GetIntValue", new Dictionary <string, string>()).Result.ShouldBe("1"); dispatcher.Execute("GetIntValueAsync", new Dictionary <string, string>()).Result.ShouldBe("1"); dispatcher.Execute("Invoke", new Dictionary <string, string>()).Result.ShouldBe(""); dispatcher.Execute("InvokeAsync", new Dictionary <string, string>()).Result.ShouldBe(""); _endpoint.Setup(x => x.RegisterInstance(It.IsAny <object>())).Returns("i1"); dispatcher.Execute("Clone", new Dictionary <string, string>()).Result.ShouldBe("i1"); dispatcher.Execute("CloneAsync", new Dictionary <string, string>()).Result.ShouldBe("i1"); } }
static NuGetLockServiceTests() { // ThreadHelper in VS requires a persistent dispatcher thread. Because // each unit test executes on a new thread, we create our own // persistent thread that acts like a UI thread. This will be invoked just // once for the module. DispatcherThread = new DispatcherThread(); DispatcherThread.Invoke(() => { // Internally this calls ThreadHelper.SetUIThread(), which // causes ThreadHelper to remember this thread for the // lifetime of the process as the dispatcher thread. var serviceProvider = ServiceProvider.GlobalProvider; }); JoinableTaskContext = new JoinableTaskContextNode( new JoinableTaskContext(DispatcherThread.Thread, DispatcherThread.SyncContext)); }