public void save_button_click(object sender, EventArgs e) { JToken new_token = jtoken; if (textBox.Text == String.Empty) { parent.Callback(key, null); return; } switch (primitive_type.Name.ToString()) { case "String": new_token = new JValue(Convert.ToString(textBox.Text)); break; case "Int64": new_token = new JValue(Convert.ToInt64(textBox.Text)); break; case "Double": new_token = new JValue(Convert.ToDouble(textBox.Text)); break; case "Boolean": new_token = new JValue(Convert.ToBoolean(textBox.Text)); break; } parent.Callback(key, new_token); Console.WriteLine(new_token.Type); //JTOKEN IS A JVALUE }
public static async void Request(string email, ICallback callback) { string requestUrl = URL + email; try { var getResp = await requestUrl .WithHeaders(new { Accept = "text/plain", User_Agent = "School project sweden" }) .AllowHttpStatus(HttpStatusCode.NotFound).GetAsync(); if (getResp.StatusCode == HttpStatusCode.OK) { List <BreachedSites> result = JsonConvert.DeserializeObject <List <BreachedSites> >(getResp.Content.ReadAsStringAsync().Result); Debug.WriteLine(getResp.Content); Debug.WriteLine(result); callback.Callback(1, result); } else if (getResp.StatusCode == HttpStatusCode.NotFound) { callback.Callback(0, null); } } catch (FlurlHttpException ex) { string message = ex.ToString(); callback.Callback(-1, null); } catch (Exception ex) { Console.WriteLine(ex.ToString()); callback.Callback(-1, null); } }
public void Callback(string k, JToken t) { JArray jarray; /* * if (parent != null) * { * parent.Callback(token_pair.Key, jarray); * }*/ if (t != null) { jTokens[Convert.ToInt32(k)] = t; listBox.Items.Clear(); foreach (JToken ob in jTokens) { listBox.Items.Add(ob); } jarray = new JArray(jTokens); } else { jTokens.RemoveAt(Convert.ToInt32(k)); listBox.Items.Clear(); foreach (JToken ob in jTokens) { listBox.Items.Add(ob); } jarray = new JArray(jTokens); } parent.Callback(token_pair.Key, jarray); }
public void Callback(string child_key, JToken child_token) { /* * jobject_part[child_key].Replace(child_token); * * token = jobject_part;*/ /* * if (parent != null) * { * parent.Callback(key, token); * }*/ if (token != null) { jobject_part[child_key].Replace(child_token); token = jobject_part; } else { jobject_part[child_key].Remove(); token = jobject_part; } parent.Callback(key, token); }
/// <summary> /// Reads and stores the request for assertion later. /// This must be done during Setup, otherwise the HttpClient will dispose the request content after sending the request. /// </summary> /// <param name="mock"></param> /// <param name="processRequest">Contains the delegate to process the request and requestBody.</param> /// <returns></returns> public static IReturnsThrows <TestableHttpMessageHandler, Task <HttpResponseMessage> > CaptureRequest(this ICallback <TestableHttpMessageHandler, Task <HttpResponseMessage> > mock, out Action <Action <HttpRequestMessage, string> > processRequest) { bool captured = false; HttpRequestMessage request = null; string requestBody = null; var result = mock.Callback((HttpRequestMessage r, CancellationToken c) => { captured = true; request = r; if (r.Content != null) { requestBody = r.Content.ReadAsStringAsync().GetAwaiter().GetResult(); } }); processRequest = action => { if (!captured) { throw new InvalidOperationException("Method has not been called."); } action(request, requestBody); }; return(result); }
/// <summary> /// Captures two arguments for the current setup. /// </summary> /// <typeparam name="T1">The type of the first argument to capture.</typeparam> /// <typeparam name="T2">The type of the second argument to capture.</typeparam> /// <param name="callback">The setup to capture arguments for.</param> /// <param name="t1Results">The list to store the captured first arguments in.</param> /// <param name="t2Results">The list to store the captured second arguments in.</param> /// <returns>The continuation of the setup.</returns> public static ICallbackResult Capture <T1, T2>(this ICallback callback, List <T1> t1Results, List <T2> t2Results) { return(callback.Callback <T1, T2>((p1, p2) => { t1Results.Add(p1); t2Results.Add(p2); })); }
/// <summary> /// Specifies a factory method to create an exception to be thrown /// </summary> /// <typeparam name="T1">The type of the first argument of the invoked method.</typeparam> /// <typeparam name="T2">The type of the second argument of the invoked method.</typeparam> /// <param name="mock">The Mock object.</param> /// <param name="func">The factory method that creates an exception to be thrown.</param> /// <returns></returns> public static IThrowsResult Throws <T1, T2>(this ICallback mock, Func <T1, T2, Exception> func) { mock.Callback <T1, T2>( (t1, t2) => { throw func(t1, t2); }); return(mock as IThrowsResult); }
/// <summary> /// Specifies a factory method to create an exception to be thrown /// </summary> /// <typeparam name="T1">The type of the first argument of the invoked method.</typeparam> /// <typeparam name="T2">The type of the second argument of the invoked method.</typeparam> /// <typeparam name="T3">The type of the third argument of the invoked method.</typeparam> /// <typeparam name="T4">The type of the fourth argument of the invoked method.</typeparam> /// <typeparam name="T5">The type of the fifth argument of the invoked method.</typeparam> /// <typeparam name="T6">The type of the sixth argument of the invoked method.</typeparam> /// <typeparam name="T7">The type of the seventh argument of the invoked method.</typeparam> /// <typeparam name="T8">The type of the eighth argument of the invoked method.</typeparam> /// <typeparam name="T9">The type of the ninth argument of the invoked method.</typeparam> /// <param name="mock">The Mock object.</param> /// <param name="func">The factory method that creates an exception to be thrown.</param> /// <returns></returns> public static IThrowsResult Throws <T1, T2, T3, T4, T5, T6, T7, T8, T9>(this ICallback mock, Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, Exception> func) { mock.Callback <T1, T2, T3, T4, T5, T6, T7, T8, T9>( (t1, t2, t3, t4, t5, t6, t7, t8, t9) => { throw func(t1, t2, t3, t4, t5, t6, t7, t8, t9); }); return(mock as IThrowsResult); }
/// <summary> /// Specifies a factory method to create an exception to be thrown /// </summary> /// <typeparam name="T1">The type of the first argument of the invoked method.</typeparam> /// <typeparam name="T2">The type of the second argument of the invoked method.</typeparam> /// <typeparam name="T3">The type of the third argument of the invoked method.</typeparam> /// <typeparam name="T4">The type of the fourth argument of the invoked method.</typeparam> /// <typeparam name="T5">The type of the fifth argument of the invoked method.</typeparam> /// <typeparam name="T6">The type of the sixth argument of the invoked method.</typeparam> /// <typeparam name="T7">The type of the seventh argument of the invoked method.</typeparam> /// <typeparam name="T8">The type of the eighth argument of the invoked method.</typeparam> /// <typeparam name="T9">The type of the ninth argument of the invoked method.</typeparam> /// <typeparam name="T10">The type of the tenth argument of the invoked method.</typeparam> /// <typeparam name="T11">The type of the eleventh argument of the invoked method.</typeparam> /// <typeparam name="T12">The type of the twelfth argument of the invoked method.</typeparam> /// <typeparam name="T13">The type of the thirteenth argument of the invoked method.</typeparam> /// <typeparam name="T14">The type of the fourteenth argument of the invoked method.</typeparam> /// <typeparam name="T15">The type of the fifteenth argument of the invoked method.</typeparam> /// <typeparam name="T16">The type of the sixteenth argument of the invoked method.</typeparam> /// <param name="mock">The Mock object.</param> /// <param name="func">The factory method that creates an exception to be thrown.</param> /// <returns></returns> public static IThrowsResult Throws <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(this ICallback mock, Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, Exception> func) { mock.Callback <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>( (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16) => { throw func(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16); }); return(mock as IThrowsResult); }
/// <summary> /// Specifies a factory method to create an exception to be thrown /// </summary> /// <typeparam name="T1">The type of the first argument of the invoked method.</typeparam> /// <typeparam name="T2">The type of the second argument of the invoked method.</typeparam> /// <typeparam name="T3">The type of the third argument of the invoked method.</typeparam> /// <typeparam name="T4">The type of the fourth argument of the invoked method.</typeparam> /// <typeparam name="T5">The type of the fifth argument of the invoked method.</typeparam> /// <param name="mock">The Mock object.</param> /// <param name="func">The factory method that creates an exception to be thrown.</param> /// <returns></returns> public static IThrowsResult Throws <T1, T2, T3, T4, T5>(this ICallback mock, Func <T1, T2, T3, T4, T5, Exception> func) { mock.Callback <T1, T2, T3, T4, T5>( (t1, t2, t3, t4, t5) => { throw func(t1, t2, t3, t4, t5); }); return(mock as IThrowsResult); }
/// <summary> /// Captures two arguments for the current setup. /// </summary> /// <typeparam name="TMock">The type of the mocked unit.</typeparam> /// <typeparam name="T1">The type of the first argument to capture.</typeparam> /// <typeparam name="T2">The type of the second argument to capture.</typeparam> /// <param name="callback">The setup to capture arguments for.</param> /// <param name="t1Results">The list to store the captured first arguments in.</param> /// <param name="t2Results">The list to store the captured second arguments in.</param> /// <returns>The continuation of the setup.</returns> public static IReturnsThrows <TMock, Task> Capture <TMock, T1, T2>(this ICallback <TMock, Task> callback, List <T1> t1Results, List <T2> t2Results) where TMock : class { return(callback.Callback <T1, T2>((p1, p2) => { t1Results.Add(p1); t2Results.Add(p2); })); }
private void EndSetup(ICallback callback) { callback.Callback(callbackAction); }
/// <summary> /// Captures two arguments for the current setup. /// </summary> /// <typeparam name="TMock">The type of the mocked unit.</typeparam> /// <typeparam name="T1">The type of the first argument to capture.</typeparam> /// <typeparam name="T2">The type of the second argument to capture.</typeparam> /// <param name="callback">The setup to capture arguments for.</param> /// <param name="results">The list to store captured arguments in.</param> /// <returns>The continuation of the setup.</returns> public static IReturnsThrows <TMock, Task> Capture <TMock, T1, T2>(this ICallback <TMock, Task> callback, List <Tuple <T1, T2> > results) where TMock : class { return(callback.Callback <T1, T2>((p1, p2) => results.Add(new Tuple <T1, T2>(p1, p2)))); }
/// <summary> /// Captures a single argument for the current setup. /// </summary> /// <typeparam name="TMock">The type of the mocked unit.</typeparam> /// <typeparam name="T1">The type of argument to capture.</typeparam> /// <param name="callback">The setup to capture arguments for.</param> /// <param name="results">The list to store captured arguments in.</param> /// <returns>The continuation of the setup.</returns> public static IReturnsThrows <TMock, Task> Capture <TMock, T1>(this ICallback <TMock, Task> callback, List <T1> results) where TMock : class { return(callback .Callback <T1>(p1 => results.Add(p1))); }
public static IReturnsThrows <TMock, TReturn> Callback <T1, T2, TMock, TReturn>(this ICallback <TMock, TReturn> mock, ActionOut2 <T1, T2> action) where TMock : class { return(mock.Callback((Delegate)action)); }
private static UIntPtr DoCallback(ICallback pThis, UIntPtr param) { VTable.Assert(Isa.IsRunningOnInterruptStack); return(pThis.Callback(param)); }
private void EndSetup(ICallback <TMock, TResult> callback) { callback.Callback(callbackAction); }
/// <summary> /// Captures two arguments for the current setup. /// </summary> /// <typeparam name="T1">The type of the first argument to capture.</typeparam> /// <typeparam name="T2">The type of the second argument to capture.</typeparam> /// <param name="callback">The setup to capture arguments for.</param> /// <param name="results">The list to store captured arguments in.</param> /// <returns>The continuation of the setup.</returns> public static ICallbackResult Capture <T1, T2>(this ICallback callback, List <Tuple <T1, T2> > results) { return(callback.Callback <T1, T2>((p1, p2) => results.Add(new Tuple <T1, T2>(p1, p2)))); }
private void EndSetup(ICallback callback) { callback.Callback(() => currentStep++); }
/// <summary> /// Captures a single argument for the current setup. /// </summary> /// <typeparam name="T1">The type of argument to capture.</typeparam> /// <param name="callback">The setup to capture arguments for.</param> /// <param name="results">The list to store captured arguments in.</param> /// <returns>The continuation of the setup.</returns> public static ICallbackResult Capture <T1>(this ICallback callback, List <T1> results) { return(callback .Callback <T1>(p1 => results.Add(p1))); }