public void AddT_DefaultConstructor_Success() { // Arrange var registry = new TypeSerializerRegistry(); // Act registry.Add <DefaultConstructorSerializer>(new[] { "text/plain" }); // Assert registry.Get("text/plain").Should().BeOfType <DefaultConstructorSerializer>(); }
public void AddT_RegistryConstructor_Success() { // Arrange var registry = new TypeSerializerRegistry(); // Act registry.Add <RegistryConstructorSerializer>(new[] { "text/plain" }); // Assert registry.Get("text/plain").Should().BeOfType <RegistryConstructorSerializer>() .Subject.Registry.Should().BeSameAs(registry); }
public async Task TestCustomSerializationWithPerson() { var expected = new SamplePerson("Olivia", new DateTimeOffset(2010, 4, 29, 5, 30, 3, TimeSpan.FromHours(1))); var registry = TypeSerializerRegistry.Build() .AddCustomType(typeof(SamplePerson), new SamplePersonSerializer()).Create(); var writer = CreateGraphBinaryWriter(registry); var reader = CreateGraphBinaryReader(registry); var serializationStream = new MemoryStream(); await writer.WriteAsync(expected, serializationStream); serializationStream.Position = 0; var actual = (SamplePerson)await reader.ReadAsync(serializationStream); Assert.Equal(expected, actual); }
public async Task ReadValueAndWriteValueShouldBeSymmetric(bool nullable) { var expected = new SamplePerson("Olivia", new DateTimeOffset(2010, 4, 29, 5, 30, 3, TimeSpan.FromHours(1))); var registry = TypeSerializerRegistry.Build() .AddCustomType(typeof(SamplePerson), new SamplePersonSerializer()).Create(); var writer = CreateGraphBinaryWriter(registry); var reader = CreateGraphBinaryReader(registry); var serializationStream = new MemoryStream(); await writer.WriteValueAsync(expected, serializationStream, nullable).ConfigureAwait(false); serializationStream.Position = 0; var actual = (SamplePerson)await reader.ReadValueAsync <SamplePerson>(serializationStream, nullable) .ConfigureAwait(false); Assert.Equal(expected, actual); }
public ValueTask <T> GetBodyAsync <T>(CancellationToken cancellationToken = default) => Message.Content != null ? TypeSerializerRegistry.DeserializeAsync <T>(Message.Content) : new ValueTask <T>(default(T) !);
private static GraphBinaryReader CreateGraphBinaryReader(TypeSerializerRegistry registry) => new GraphBinaryReader(registry);