public void Should_Convert_To_PascalCase_Json_With_Altered_Serialization_Settings() { var transcoder = new JsonTranscoder( new DefaultSerializer( new JsonSerializerSettings(), new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() })); var data = new Transcoders.Pascal { SomeProperty = "SOME", SomeIntProperty = 12345, HasPascalCase = true }; var expectedJsonBytes = Encoding.UTF8.GetBytes("{\"SomeProperty\":\"SOME\",\"SomeIntProperty\":12345,\"HasPascalCase\":true}"); using var jsonBytes = new MemoryStream(); using var jsonEncoded = new MemoryStream(); transcoder.SerializeAsJson(jsonBytes, data); transcoder.Encode(jsonEncoded, data, new Flags { DataFormat = DataFormat.Json }, OpCode.Get); Assert.Equal(expectedJsonBytes, jsonBytes.ToArray()); Assert.Equal(expectedJsonBytes, jsonEncoded.ToArray()); }
public void Test_Json_Deserialize_Int() { var transcoder = new JsonTranscoder(); int value = 42; using var stream = new MemoryStream(); transcoder.SerializeAsJson(stream, value); var actual = transcoder.DeserializeAsJson <int>(stream.ToArray()); Assert.Equal(value, actual); }
public void Test_Deserialize_Null() { var transcoder = new JsonTranscoder(); object value = null; var flags = new Flags { Compression = Couchbase.Core.IO.Operations.Compression.None, DataFormat = DataFormat.Json, TypeCode = TypeCode.Empty }; using var stream = new MemoryStream(); // ReSharper disable once ExpressionIsAlwaysNull transcoder.SerializeAsJson(stream, value); var actual = transcoder.Decode <object>(stream.ToArray(), flags, OpCode.Get); Assert.Equal(value, actual); }