/// <summary> /// Deserializes on object of this type from a binary reader. /// </summary> /// <remarks> /// Doesn't handle any exceptions. /// </remarks> public static async Task <Response> DeserializeAsync(Stream stream, CancellationToken token) { var id = await Utils.ReadIntAsync(stream, token); var result = await IpcResult.DeserializeAsync(stream, token); return(new Response(id, result)); }
public async Task TestIpcResultSerializationAsync(IpcResultStatus status, string payload) { var duration = TimeSpan.FromMilliseconds(1234); var ipcResult = new IpcResult(status, payload, duration); // serialize using var stream = new MemoryStream(); await ipcResult.SerializeAsync(stream, CancellationToken.None); // reset stream position and deserialize stream.Position = 0; var ipcResultClone = await IpcResult.DeserializeAsync(stream, CancellationToken.None); // compare var errMessage = $"Cloning failed:\n - original: {ipcResult}\n - clone: {ipcResultClone}"; XAssert.AreEqual(status, ipcResultClone.ExitCode); XAssert.AreEqual(payload, ipcResultClone.Payload, errMessage); XAssert.AreEqual(duration, ipcResultClone.ActionDuration, errMessage); XAssert.AreNotEqual(ipcResult.Succeeded, ipcResult.Failed); }