public void StructuralTypeSlimReference_AddPropertyAfterFreeze_Fail()
        {
            var t = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);

            t.Freeze();
            var p = t.GetProperty("Foo", propertyType: null, EmptyReadOnlyCollection <TypeSlim> .Instance, canWrite: true);

            Assert.ThrowsException <InvalidOperationException>(() => t.AddProperty(p));
        }
Exemple #2
0
        public void TypeSlimVisitor_VisitStructural_Recursive_ResultIsSame()
        {
            var visitor      = new TypeSlimVisitor();
            var empty        = EmptyReadOnlyCollection <TypeSlim> .Instance;
            var structural   = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);
            var recursiveRef = structural.GetProperty("Foo", structural, empty, canWrite: true);

            structural.AddProperty(recursiveRef);
            structural.Freeze();
            Assert.AreSame(structural, visitor.Visit(structural));
        }
Exemple #3
0
        public void TypeSlimVisitor_VisitStructural_IndexParameterChange_ResultIsNotSame()
        {
            var visitor = new B();
            var structural = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);
            var index = new List <TypeSlim> {
                SlimType
            }.AsReadOnly();
            var prop = structural.GetProperty("Foo", structural, index, canWrite: true);

            structural.AddProperty(prop);
            structural.Freeze();
            Assert.AreNotSame(structural, visitor.Visit(structural));
        }
Exemple #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));
        }
Exemple #5
0
        public void TypeSlimVisitor_VisitStructural_DeepRecursive_ResultIsSame()
        {
            var visitor = new TypeSlimVisitor();
            var empty   = EmptyReadOnlyCollection <TypeSlim> .Instance;
            var s1      = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);
            var s2      = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);
            var s1Prop  = s2.GetProperty("Foo", s1, empty, canWrite: true);
            var s2Prop  = s1.GetProperty("Bar", s2, empty, canWrite: true);

            s1.AddProperty(s2Prop);
            s2.AddProperty(s1Prop);
            s1.Freeze();
            s2.Freeze();
            Assert.AreSame(s1, visitor.Visit(s1));
        }
        public void TypeSlimEqualityComparer_EqualsStructural_RecursiveReference()
        {
            var s1 = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);

            s1.AddProperty(s1.GetProperty("Foo", s1, EmptyReadOnlyCollection <TypeSlim> .Instance, canWrite: true));
            var s2 = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);

            s2.AddProperty(s2.GetProperty("Foo", s2, EmptyReadOnlyCollection <TypeSlim> .Instance, canWrite: true));

            var equal = new Dictionary <TypeSlim, TypeSlim>
            {
                { s1, s2 }
            };

            AssertAllEqual(equal.AsEnumerable());
        }
Exemple #7
0
        public override TypeSlim ToType(DeserializationDomain domain, params TypeSlim[] genericArguments)
        {
            if (_type == null)
            {
                var refType = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, Kind, _members.Length);
                _type = refType;
                foreach (var member in _members)
                {
                    var newPropertyType = domain.GetType(member.Type).ToType(domain, genericArguments);
                    var newProperty     = _type.GetProperty(member.Name, newPropertyType, s_emptyTypeList, member.CanWrite);
                    refType.AddProperty(newProperty);
                }
                refType.Freeze();
            }

            return(_type);
        }
Exemple #8
0
 protected override TypeSlim VisitStructural(StructuralTypeSlim type)
 {
     if (!type.HasValueEqualitySemantics)
     {
         var newType = StructuralTypeSlimReference.Create(type.HasValueEqualitySemantics, type.StructuralKind);
         foreach (var property in type.Properties)
         {
             newType.AddProperty(property);
         }
         newType.Freeze();
         return(newType);
     }
     else
     {
         return(base.VisitStructural(type));
     }
 }
Exemple #9
0
        public void TypeSlimVisitor_VisitStructural_DeepRecursive_ManOrBoy()
        {
            var visitor     = new B();
            var empty       = EmptyReadOnlyCollection <TypeSlim> .Instance;
            var s1          = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);
            var s2          = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);
            var s1Prop      = s2.GetProperty("Foo", s1, empty, canWrite: true);
            var changedProp = s2.GetProperty("Baz", SlimType, empty, canWrite: true);
            var s2Prop      = s1.GetProperty("Bar", s2, empty, canWrite: true);

            s1.AddProperty(s2Prop);
            s2.AddProperty(s1Prop);
            s2.AddProperty(changedProp);
            s1.Freeze();
            s2.Freeze();
            Assert.AreSame(s1, s2.Properties.SingleOrDefault(p => p.Name == "Foo").PropertyType);

            var rs2 = (StructuralTypeSlim)visitor.Visit(s2);
            var rs1 = (StructuralTypeSlim)rs2.Properties.SingleOrDefault(p => p.Name == "Foo").PropertyType;

            Assert.AreSame(rs2, rs1.Properties.SingleOrDefault(p => p.Name == "Bar").PropertyType);
        }
        public void StructuralTypeSlimReference_AddProperty_NullArgument()
        {
            var t = StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);

            AssertEx.ThrowsException <ArgumentNullException>(() => t.AddProperty(property: null), ex => Assert.AreEqual("property", ex.ParamName));
        }
 protected override StructuralTypeSlimReference GetTypeSlimBuilder() => StructuralTypeSlimReference.Create(hasValueEqualitySemantics: true, StructuralTypeSlimKind.Record);