示例#1
0
        public void UnifyingSerializationHelpers_Roundtrip_WithEnums()
        {
            var metadata = new MetadataMock();
            var uri1     = new Uri("test://id/1");
            var uri2     = new Uri("test://id/2");

            metadata.Observables.Add(uri1, new MockObservable <EntityEnum>(uri1));
            metadata.Observables.Add(uri2, new MockObservable <TypeWithEnum>(uri2));

            Expression <Func <IAsyncReactiveQbservable <EntityEnum>, IAsyncReactiveQbservable <TypeWithEnum>, IAsyncReactiveQbservable <TypeWithEnum> > > f = (io1, io2) => Concat(Select(io1, x => new TypeWithEnum {
                Enum = x
            }), io2);
            var invoked = BetaReducer.Reduce(
                Expression.Invoke(
                    f,
                    Expression.Parameter(typeof(IAsyncReactiveQbservable <EntityEnum>), uri1.ToCanonicalString()),
                    Expression.Parameter(typeof(IAsyncReactiveQbservable <TypeWithEnum>), uri2.ToCanonicalString())));
            var normalized = new ReactiveExpressionServices(typeof(object)).Normalize(invoked);

            var clientSerializer  = new ClientSerializationHelpers();
            var serviceSerializer = new UnifyingSerializationHelpers(metadata);
            var bonsai            = clientSerializer.Serialize(normalized);
            var roundtrip         = serviceSerializer.Deserialize <Expression>(bonsai);

            Assert.AreEqual(typeof(IAsyncReactiveQbservable <TypeWithEnum>), roundtrip.Type);
        }
示例#2
0
        public void UnifyingSerializationHelpers_FindAndUnify_Subscription()
        {
            var metadata = new MetadataMock();
            var uri      = new Uri("test://id");

            metadata.Subscriptions.Add(uri, new MockSubscription(uri));

            var parameter = ExpressionSlim.Parameter(typeof(IAsyncReactiveQubscription).ToTypeSlim(), uri.ToCanonicalString());
            var mappings  = UnifyingSerializationHelpers.FindAndUnify(parameter, metadata);

            Assert.AreEqual(0, mappings.Count());
        }
示例#3
0
        public void UnifyingSerializationHelpers_FindAndUnify_Parameterized()
        {
            var metadata = new MetadataMock();
            var uri      = new Uri("test://id");

            metadata.Observables.Add(uri, new MockParameterizedObservable <int, int>(uri));

            var parameter = ExpressionSlim.Parameter(typeof(Func <int, IAsyncReactiveQbservable <int> >).ToTypeSlim(), uri.ToCanonicalString());
            var mappings  = UnifyingSerializationHelpers.FindAndUnify(parameter, metadata);

            Assert.AreEqual(0, mappings.Count());
        }
示例#4
0
        public void UnifyingSerializationHelpers_FindAndUnify_MismatchProperty()
        {
            var metadata = new MetadataMock();
            var uri      = new Uri("test://id");

            metadata.Observables.Add(uri, new MockObservable <TypeWithEnum>(uri));

            var structuralType = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);

            structuralType.AddProperty(structuralType.GetProperty("eg://enum", typeof(int).ToTypeSlim(), EmptyReadOnlyCollection <TypeSlim> .Instance, canWrite: true));
            var observerableType = TypeSlim.Generic(((GenericDefinitionTypeSlim)typeof(IAsyncReactiveQbservable <>).ToTypeSlim()), new TypeSlim[] { structuralType }.ToReadOnly());
            var parameter        = ExpressionSlim.Parameter(observerableType, uri.ToCanonicalString());

            Assert.ThrowsException <InvalidOperationException>(() => UnifyingSerializationHelpers.FindAndUnify(parameter, metadata));
        }