public void Serialize_WithPrimitivesAndDateTime_Successful() { var payload = new PrimitivesAndDateTime { alpha = 707070, beta = true, gamma = 1230, delta = new DateTime(2018, 03, 01, 07, 00, 00, DateTimeKind.Utc), epsilon = "epsilon should not be serialized", zeta = "I myself confused I still need to have this string", eta = "So insecure, I also write something into this field" }; var writer = new StringWriter(); AwesomeFormat.WriteHeader(writer, MessageType.unknown); AwesomeFormat.WritePayload(writer, payload); Assert.That(writer.ToString(), Is.EqualTo( "type: unknown\n" + "alpha: 707070\n" + "beta: True\n" + "gamma: 1230\n" + "delta: 2018-03-01T07:00:00.0000000Z")); }
public void Serialize_WithPrimitivesAndDoubleArrays_Successful() { var payload = new PrimitivesAndDoubleArrays { alpha = 707070, beta = true, gamma = 1230, delta = new[] { 16.125, 2.25, 7.375, 8.00 }, epsilon = "epsilon should not be serialized", zeta = "I myself confused I still need to have this string", eta = "So insecure, I also write something into this field" }; var writer = new StringWriter(); AwesomeFormat.WriteHeader(writer, MessageType.unknown); AwesomeFormat.WritePayload(writer, payload); Assert.That(writer.ToString(), Is.EqualTo( "type: unknown\n" + "alpha: 707070\n" + "beta: True\n" + "gamma: 1230\n" + "delta: [16.125,2.25,7.375,8]")); }
public void Serialize_WithPrimitives_ForAllDataMemberAttributes_Successful() { var payload = new AllPrimitives { alpha = 707070, beta = true, gamma = 1230, delta = "this should be string, still", epsilon = "epsilon should not be serialized", zeta = "I myself confused I still need to have this string", eta = "So insecure, I also write something into this field" }; var writer = new StringWriter(); AwesomeFormat.WriteHeader(writer, MessageType.unknown); AwesomeFormat.WritePayload(writer, payload); Assert.That(writer.ToString(), Is.EqualTo( "type: unknown\n" + "alpha: 707070\n" + "beta: True\n" + "gamma: 1230\n" + "delta: this should be string, still")); }
public void Serialize_WithAllStringMembers_ForAllDataMemberAttributes_Successful() { var payload = new AllString { alpha = "the content of alpha", beta = "beta content should be something too", gamma = "gamma also needs placeholder string", delta = "I've run out of idea for delta content", epsilon = "epsilon should not be serialized", zeta = "I myself confused I still need to have this string", eta = "So insecure, I also write something into this field" }; StringWriter writer = new StringWriter(); AwesomeFormat.WriteHeader(writer, MessageType.unknown); AwesomeFormat.WritePayload(writer, payload); Assert.That(writer.ToString(), Is.EqualTo( "type: unknown\n" + "alpha: the content of alpha\n" + "beta: beta content should be something too\n" + "gamma: gamma also needs placeholder string\n" + "delta: I've run out of idea for delta content")); }
private void SendRequest <T, U>(MessageType requestType, T requestPayload, ResultCallback <U> callback) where T : class, new() where U : class, new() { long messageId = GenerateId(); var writer = new StringWriter(); AwesomeFormat.WriteHeader(writer, requestType, messageId); AwesomeFormat.WritePayload(writer, requestPayload); this.responseCallbacks[messageId] = (errorCode, response) => { Result <U> result; if (errorCode != ErrorCode.None) { result = Result <U> .CreateError(errorCode); } else { U responsePayload; errorCode = AwesomeFormat.ReadPayload(response, out responsePayload); result = errorCode != ErrorCode.None ? Result <U> .CreateError(errorCode) : Result <U> .CreateOk(responsePayload); } this.coroutineRunner.Run(() => callback.Try(result)); }; this.webSocket.Send(writer.ToString()); }
private void SendRequest <T>(MessageType requestType, T requestPayload, ResultCallback callback) where T : class, new() { long messageId = this.GenerateId(); var writer = new StringWriter(); AwesomeFormat.WriteHeader(writer, requestType, messageId); AwesomeFormat.WritePayload(writer, requestPayload); this.responseCallbacks[messageId] = (errorCode, response) => { var result = errorCode != ErrorCode.None ? Result.CreateError(errorCode) : Result.CreateOk(); this.coroutineRunner.Run(() => callback(result)); }; this.webSocket.SendAsync(writer.ToString(), null); }