Exemplo n.º 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));
            }
        }
Exemplo n.º 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();
            }
        }