Beispiel #1
0
        public void EntityReaderWriter_Roundtrip_V3_Templatized_MissingTemplate()
        {
            var registry    = new QueryEngineRegistry(new MockQueryEngineRegistry());
            var templatizer = new QueryEngineRegistryTemplatizer(registry);
            var templatized = templatizer.Templatize(Expression.Default(typeof(object)));

            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()
            {
                var emptyRegistry = new QueryEngineRegistry(new MockQueryEngineRegistry());

                using var reader = new EntityReader(stream, emptyRegistry, new SerializationPolicy(DefaultExpressionPolicy.Instance, Versioning.v3));

                reader.ReadHeader();

                Assert.ThrowsException <InvalidOperationException>(() => reader.Load(ReactiveEntityKind.Observable));
            }
        }
Beispiel #2
0
        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();
            }
        }
Beispiel #3
0
        public void EntityReaderWriter_Roundtrip_None_ThrowsArgumentException()
        {
            var registry = new QueryEngineRegistry(new MockQueryEngineRegistry());

            var def    = new OtherDefinitionEntity(new Uri("io:/1"), Expression.Default(typeof(object)), null);
            var stream = new MemoryStream();

            Write();

            stream.Position = 0;

            Read();

            void Write()
            {
                using var writer = new EntityWriter(stream, new SerializationPolicy(DefaultExpressionPolicy.Instance, Versioning.v1));

                writer.WriteHeader();
                writer.Save(def);
            }

            void Read()
            {
                using var reader = new EntityReader(stream, registry, new SerializationPolicy(DefaultExpressionPolicy.Instance, Versioning.v1));

                reader.ReadHeader();

                AssertEx.ThrowsException <ArgumentException>(() => reader.Load(ReactiveEntityKind.None), ex => Assert.AreEqual("kind", ex.ParamName));
            }
        }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
        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);
            }
        }