示例#1
0
        public void MixinGet_FindsMixinWithGenericMatch()
        {
            BaseType3 bt3   = ObjectFactory.Create <BaseType3> (ParamList.Empty);
            object    mixin = Mixin.Get(typeof(BT3Mixin3 <,>), bt3);

            Assert.That(mixin, Is.Not.Null);
        }
示例#2
0
        public void InstantiatedSubclassProxyHasNextCallProxy()
        {
            BaseType3 bt3        = CreateMixedObject <BaseType3> (typeof(BT3Mixin3 <,>));
            FieldInfo firstField = bt3.GetType().GetField("__first", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.That(firstField.GetValue(bt3), Is.Not.Null);
        }
        public void SerializationOfMixinBaseWorks()
        {
            BaseType3 bt3   = CreateMixedObject <BaseType3> (typeof(BT3Mixin1), typeof(BT3Mixin1B));
            var       mixin = Mixin.Get <BT3Mixin1> (bt3);

            Assert.That(mixin.Next, Is.Not.Null);
            Assert.That(mixin.Next.GetType(), Is.SameAs(bt3.GetType().GetField("__first", BindingFlags.NonPublic | BindingFlags.Instance).FieldType));

            var mixin2 = Mixin.Get <BT3Mixin1B> (bt3);

            Assert.That(mixin2.Next, Is.Not.Null);
            Assert.That(mixin2.Next.GetType(), Is.SameAs(bt3.GetType().GetField("__first", BindingFlags.NonPublic | BindingFlags.Instance).FieldType));

            BaseType3 bt3A   = Serializer.SerializeAndDeserialize(bt3);
            var       mixinA = Mixin.Get <BT3Mixin1> (bt3A);

            Assert.That(mixinA, Is.Not.SameAs(mixin));
            Assert.That(mixinA.Next, Is.Not.Null);
            Assert.That(mixinA.Next.GetType(), Is.SameAs(bt3A.GetType().GetField("__first", BindingFlags.NonPublic | BindingFlags.Instance).FieldType));

            var mixin2A = Mixin.Get <BT3Mixin1B> (bt3A);

            Assert.That(mixin2A, Is.Not.SameAs(mixin2));
            Assert.That(mixin2A.Next, Is.Not.Null);
            Assert.That(mixin2A.Next.GetType(), Is.SameAs(bt3A.GetType().GetField("__first", BindingFlags.NonPublic | BindingFlags.Instance).FieldType));
        }
        public void MuchGenericityWithoutOverriding()
        {
            BaseType3 bt3 = CreateMixedObject <BaseType3> (typeof(VeryGenericMixin <,>), typeof(BT3Mixin4));
            var       m   = bt3 as IVeryGenericMixin;

            Assert.That(m, Is.Not.Null);
            Assert.That(m.GetMessage("5"), Is.EqualTo("IVeryGenericMixin.GenericIfcMethod-5"));
        }
 public void OverriddenMemberCalls()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <BaseType3> ().Clear().AddMixins(typeof(BT3Mixin7Base), typeof(BT3Mixin4)).EnterScope())
     {
         BaseType3 bt3 = ObjectFactory.Create <BaseType3> (ParamList.Empty);
         Assert.That(bt3.IfcMethod(), Is.EqualTo("BT3Mixin7Base.IfcMethod-BT3Mixin4.Foo-BaseType3.IfcMethod-BaseType3.IfcMethod2"));
     }
 }
        public void SerializationOfMixinThisWorks()
        {
            BaseType3 bt3   = CreateMixedObject <BaseType3> (typeof(BT3Mixin2), typeof(BT3Mixin2B));
            var       mixin = Mixin.Get <BT3Mixin2> (bt3);

            Assert.That(mixin.Target, Is.SameAs(bt3));

            var mixin2 = Mixin.Get <BT3Mixin2B> (bt3);

            Assert.That(mixin2.Target, Is.SameAs(bt3));

            BaseType3 bt3A   = Serializer.SerializeAndDeserialize(bt3);
            var       mixinA = Mixin.Get <BT3Mixin2> (bt3A);

            Assert.That(mixinA, Is.Not.SameAs(mixin));
            Assert.That(mixinA.Target, Is.SameAs(bt3A));

            var mixin2A = Mixin.Get <BT3Mixin2B> (bt3A);

            Assert.That(mixin2A, Is.Not.SameAs(mixin2));
            Assert.That(mixin2A.Target, Is.SameAs(bt3A));
        }
        public void GenericMixinsAreSpecialized()
        {
            BaseType3 bt3   = CreateMixedObject <BaseType3> (typeof(BT3Mixin3 <,>));
            object    mixin = Mixin.Get(typeof(BT3Mixin3 <,>), bt3);

            Assert.That(mixin, Is.Not.Null);

            PropertyInfo targetProperty = MixinReflector.GetTargetProperty(mixin.GetType());

            Assert.That(targetProperty, Is.Not.Null);

            Assert.That(targetProperty.GetValue(mixin, null), Is.Not.Null);
            Assert.That(targetProperty.GetValue(mixin, null), Is.SameAs(bt3));
            Assert.That(targetProperty.PropertyType, Is.EqualTo(typeof(BaseType3)));

            PropertyInfo nextProperty = MixinReflector.GetNextProperty(mixin.GetType());

            Assert.That(nextProperty, Is.Not.Null);

            Assert.That(nextProperty.GetValue(mixin, null), Is.Not.Null);
            Assert.That(nextProperty.GetValue(mixin, null).GetType(), Is.SameAs(bt3.GetType().GetField("__first", BindingFlags.NonPublic | BindingFlags.Instance).FieldType));
            Assert.That(nextProperty.PropertyType, Is.EqualTo(typeof(IBaseType33)));
        }
        public void NextCallMethodToThis()
        {
            BaseType3 bt3 = CreateMixedObject <BaseType3> (typeof(MixinWithThisAsBase));

            Assert.That(bt3.IfcMethod(), Is.EqualTo("MixinWithThisAsBase.IfcMethod-BaseType3.IfcMethod"));
        }
        public void OverrideWithComposedBaseInterface()
        {
            BaseType3 bt3 = CreateMixedObject <BaseType3> (typeof(BT3Mixin7Base), typeof(BT3Mixin4));

            Assert.That(bt3.IfcMethod(), Is.EqualTo("BT3Mixin7Base.IfcMethod-BT3Mixin4.Foo-BaseType3.IfcMethod-BaseType3.IfcMethod2"));
        }