public void EntityReaderWriter_Roundtrip_V3_Templatized_WithConstants() { var registry = new QueryEngineRegistry(new MockQueryEngineRegistry()); var templatizer = new QueryEngineRegistryTemplatizer(registry); var templatized = templatizer.Templatize(Expression.Constant(42)); var io = new ObservableDefinitionEntity(new Uri("io:/1"), templatized, null); var stream = new MemoryStream(); Write(); stream.Position = 0; Read(); void Write() { using var writer = new EntityWriter(stream, new SerializationPolicy(DefaultExpressionPolicy.Instance, Versioning.v3)); writer.WriteHeader(); writer.Save(io); } void Read() { using var reader = new EntityReader(stream, registry, new SerializationPolicy(DefaultExpressionPolicy.Instance, Versioning.v3)); reader.ReadHeader(); _ = reader.Load(ReactiveEntityKind.Observable); reader.ReadFooter(); } }
public void EntityReaderWriter_Roundtrip_Stream() { var registry = new QueryEngineRegistry(new MockQueryEngineRegistry()); var sub = new SubjectEntity(new Uri("io:/1"), Expression.Default(typeof(object)), null); var stream = new MemoryStream(); Write(); stream.Position = 0; var rt = Read(); Assert.AreEqual(ReactiveEntityKind.Stream, rt.Kind); Assert.AreEqual(sub.Uri, rt.Uri); AssertEqual(sub.Expression, rt.Expression); Assert.AreEqual(sub.State, rt.State); void Write() { using var writer = new EntityWriter(stream, new SerializationPolicy(DefaultExpressionPolicy.Instance, Versioning.v1)); writer.WriteHeader(); writer.Save(sub); } ReactiveEntity Read() { using var reader = new EntityReader(stream, registry, new SerializationPolicy(DefaultExpressionPolicy.Instance, Versioning.v1)); reader.ReadHeader(); var rt = reader.Load(ReactiveEntityKind.Stream); reader.ReadFooter(); return(rt); } }
public void EntityReaderWriter_Roundtrip_Definitions() { var registry = new QueryEngineRegistry(new MockQueryEngineRegistry()); var def = new OtherDefinitionEntity(new Uri("io:/1"), Expression.Default(typeof(object)), null); var stream = new MemoryStream(); using (var writer = new EntityWriter(stream, new SerializationPolicy(DefaultExpressionPolicy.Instance, Versioning.v1))) { writer.WriteHeader(); writer.Save(def); writer.Dispose(); } foreach (var kind in new[] { ReactiveEntityKind.Observable, ReactiveEntityKind.Observer, ReactiveEntityKind.StreamFactory, ReactiveEntityKind.Other, }) { stream.Position = 0; var rt = default(ReactiveEntity); using (var reader = new EntityReader(stream, registry, new SerializationPolicy(DefaultExpressionPolicy.Instance, Versioning.v1))) { reader.ReadHeader(); rt = reader.Load(kind); reader.ReadFooter(); } Assert.AreEqual(kind, rt.Kind); Assert.AreEqual(def.Uri, rt.Uri); AssertEqual(def.Expression, rt.Expression); Assert.AreEqual(def.State, rt.State); } }