public async Task CanSerializeAnObjectAsync() { using var memoryStream = new MemoryStream(); var o = new ExtendedModel(readOnlyD: 4) { A = "1", B = 2, C = 3, IgnoredE = 5, F = 6, }; await _jsonObjectSerializer.SerializeAsync(memoryStream, o, o.GetType(), default); Assert.AreEqual($"{{\"d\":4,\"{SerializedName("A")}\":\"1\",\"{SerializedName("B")}\":2}}", Encoding.UTF8.GetString(memoryStream.ToArray())); }
public async Task CanSerializeAnObjectAsync() { using var memoryStream = new MemoryStream(); var o = new ExtendedModel(4, 8) { A = "1", ActuallyB = 2, C = 3, Type = ModelType.One, IgnoredE = 5, F = 6, G = 7, }; await _jsonObjectSerializer.SerializeAsync(memoryStream, o, o.GetType(), default); Assert.AreEqual($"{{\"{SerializedName("A")}\":\"1\",\"b\":2,\"d\":4,\"{SerializedName("F")}\":6,\"h\":8,\"{SerializedName("Type")}\":\"one\"}}", Encoding.UTF8.GetString(memoryStream.ToArray())); }
public async Task UpdateAsync(ExtendedModel model) { var client = GetGenesisClient(); var cancellationTokenSource = new CancellationTokenSource(); var request = new RestRequest($"/v3.0/type/APPOINTMENT/{model.GGUID}", Method.PUT, DataFormat.Json); request.AddHeader("If-Match", model.Etag); var body = _mapper.Map <ExtendedModel, TerminRequest>(model); var data = new { fields = body }; var serialized = JsonConvert.SerializeObject(data); request.AddJsonBody(serialized); await client.ExecuteAsync(request, cancellationTokenSource.Token); }
public async Task CanCreateBinaryDataFromCustomTypePassingBaseType() { var payload = new ExtendedModel() { A = "value", B = 5, C = 3, F = 5 }; var serializer = new JsonObjectSerializer(); await AssertData(await serializer.SerializeAsync(payload, typeof(Model))); await AssertData(serializer.Serialize(payload, typeof(Model))); async Task AssertData(BinaryData data) { Assert.AreEqual(payload.A, data.ToObject <Model>(serializer).A); Assert.AreEqual(payload.B, data.ToObject <Model>(serializer).B); Assert.AreEqual(0, data.ToObject <Model>(serializer).C); Assert.AreEqual(payload.A, (await data.ToObjectAsync <Model>(serializer)).A); Assert.AreEqual(payload.B, (await data.ToObjectAsync <Model>(serializer)).B); Assert.AreEqual(0, (await data.ToObjectAsync <Model>(serializer)).C); Assert.AreEqual(0, (await data.ToObjectAsync <ExtendedModel>(serializer)).F); } }