public Promise ReplayTestSession(string sessionId, bool setupAndTeardown = true) { return(new Promise((resolve, reject) => { #if DEBUG Console.WriteLine("\n\n============================================"); Console.WriteLine(">> Replaying session {0}", sessionId); #endif var(request, canceller) = this.socket.SendRequest("ReplayTestSession", new JToken[] { sessionId }); request.ContinueWith(prev => resolve(prev.Result), TaskContinuationOptions.OnlyOnRanToCompletion); request.ContinueWith(prev => reject(prev.Exception), TaskContinuationOptions.OnlyOnFaulted); }).Then(payload => { // WARN: From here we don't have static typing. // The code below can throw arbitrary exceptions // if the JSON payload format changes JObject data = (JObject)payload; SessionInfo info = SessionInfo.FromJson(data); #if DEBUG Console.WriteLine(" Seed : {0}", info.schedulingSeed); Console.WriteLine(" [{2} .{1}] in {0}", info.assemblyName, info.methodName, info.methodDeclaringClass); #else Console.WriteLine(" Replaying session '{0}'\tseed = {1}", info.id, info.schedulingSeed); #endif var assembly = Assembly.LoadFrom(info.assemblyPath); var testMethod = GetMethodToBeTested(assembly, info.methodDeclaringClass, info.methodName); var testDefinition = GetTestDefinition(testMethod); if (testDefinition.Setup != null && setupAndTeardown) { testDefinition.Setup.Invoke(null, null); } var session = this.StartSession(info.id, testMethod, info.schedulingSeed); session.Wait(); if (testDefinition.Teardown != null && setupAndTeardown) { testDefinition.Teardown.Invoke(null, null); } return session.Result; })); }