public void ApplyTo_NonSerializable_False()
        {
            var nonSerializable = new NonSerializable("s");
            var subject         = new SerializationConstraint <NonSerializable>(new JsonRoundtripSerializer <NonSerializable>(), Is.Not.Null);

            Assert.That(matches(subject, nonSerializable), Is.False);
        }
        public void WriteMessageTo_NonSerializable_ExpectedContainsConstraintExpectations_ActualContainsExpectationsErrorPlusObject()
        {
            var nonSerializable = new NonSerializable("s");
            var subject         = new SerializationConstraint <NonSerializable>(new JsonRoundtripSerializer <NonSerializable>(), Is.Not.Null);

            Assert.That(getMessage(subject, nonSerializable), Does
                        .StartWith(TextMessageWriter.Pfx_Expected + "Deserialized object not null").And
                        .Contains(TextMessageWriter.Pfx_Actual + "Could not serialize/deserialize object"));
        }
Example #3
0
        public void WhenJustCreatedTheClassTheProxyIsInactive()
        {
            var value = new NonSerializable()
            {
                Value = "asd"
            };
            var serializable = new SerializeAsString(value);

            serializable.IsProxyActivated.Should().Be.False();
        }
Example #4
0
        public void WhenTheClassIsNotSerializedTheInstanceIsTheSame()
        {
            var value = new NonSerializable()
            {
                Value = "asd"
            };
            var serializable = new SerializeAsString(value);
            var value2       = serializable.Real;

            Assert.AreSame(value, value2);
        }
Example #5
0
        public void WhenJustDeserializedTheClassTheRealIsInactive()
        {
            var value = new NonSerializable()
            {
                Value = "asd"
            };
            var serializable    = new SerializeAsString(value);
            var newSerializable = SerializeAndDeserialize(serializable);

            newSerializable.IsRealActivated.Should().Be.False();
            serializable.IsProxyActivated.Should().Be.True();
        }
Example #6
0
        public override void Configure(Configuration configuration)
        {
            configuration.AddEventType("TypeS0", typeof(SupportBean_S0));
            configuration.AddEventType("TypeS2", typeof(SupportBean_S2));

            configuration.AddVariable("vars0_A", "TypeS0", new SupportBean_S0(10));
            configuration.AddVariable("vars1_A", typeof(SupportBean_S1).FullName, new SupportBean_S1(20));
            configuration.AddVariable("varsobj1", typeof(object).Name, 123);

            nonSerializable = new NonSerializable("abc");
            configuration.AddVariable("myNonSerializable", typeof(NonSerializable), nonSerializable);
        }
Example #7
0
        public void WhenTheClassIsSerializedTheInstanceIsTheDifferent()
        {
            var value = new NonSerializable()
            {
                Value = "asd"
            };
            var serializable    = new SerializeAsString(value);
            var newSerializable = SerializeAndDeserialize(serializable);
            var value2          = newSerializable.Real;

            Assert.AreNotSame(serializable, newSerializable);
            Assert.AreNotSame(value, value2);
        }
Example #8
0
        public void WhenAccessTheProxyPropertyItBecomesActivated()
        {
            var value = new NonSerializable()
            {
                Value = "asd"
            };
            var serializable = new SerializeAsString(value);
            var proxy        = serializable.Proxy;

            proxy.Should().Not.Be.Null();
            serializable.IsRealActivated.Should().Be.True();
            serializable.IsProxyActivated.Should().Be.True();
        }
Example #9
0
        public void WhenAccessTheRealPropertyAfterDeserializationItBecomesActivated()
        {
            var value = new NonSerializable()
            {
                Value = "asd"
            };
            var serializable    = new SerializeAsString(value);
            var newSerializable = SerializeAndDeserialize(serializable);
            var real            = newSerializable.Real;

            real.Should().Not.Be.Null();
            newSerializable.IsRealActivated.Should().Be.True();
            serializable.IsProxyActivated.Should().Be.True();
        }
Example #10
0
        public override int GetHashCode()
        {
            unchecked
            {
                var hash = 17;

                hash = hash * 23 + Matching.GetHashCode();

                foreach (var type in types)
                {
                    if (type != null)
                    {
                        hash = hash * 23 + type.GetHashCode();
                    }
                }

                hash = hash * 23 + Value.GetHashCode();
                hash = hash * 23 + Reference.GetHashCode();
                hash = hash * 23 + Classes.GetHashCode();
                hash = hash * 23 + Interfaces.GetHashCode();
                hash = hash * 23 + Structs.GetHashCode();
                hash = hash * 23 + Enums.GetHashCode();
                hash = hash * 23 + Delegates.GetHashCode();
                hash = hash * 23 + Public.GetHashCode();
                hash = hash * 23 + NonPublic.GetHashCode();
                hash = hash * 23 + Abstract.GetHashCode();
                hash = hash * 23 + Generic.GetHashCode();
                hash = hash * 23 + OpenConstructedGeneric.GetHashCode();
                hash = hash * 23 + Static.GetHashCode();
                hash = hash * 23 + Sealed.GetHashCode();
                hash = hash * 23 + Nested.GetHashCode();
                hash = hash * 23 + Primitives.GetHashCode();
                hash = hash * 23 + Object.GetHashCode();
                hash = hash * 23 + NonSerializable.GetHashCode();
                hash = hash * 23 + Obsolete.GetHashCode();
                hash = hash * 23 + GenericParameterAttributeFlags.GetHashCode();

                return(hash);
            }
        }
Example #11
0
 public void NonSerializedPropertyTests(NonSerializable obj)
 {
     Assert.Equal(obj.A, obj.B);
 }
Example #12
0
 public void NonSerializedMethodTests(NonSerializable obj)
 {
     Assert.Equal(obj.A, obj.B);
 }
Example #13
0
        private static void AddTypeProperties(Type type)
        {
            if (type_properties.ContainsKey(type))
            {
                return;
            }

            IList <PropertyMetadata> props = new List <PropertyMetadata> ();

            foreach (PropertyInfo p_info in type.GetProperties())
            {
                if (p_info.Name == "Item")
                {
                    continue;
                }

                PropertyMetadata p_data = new PropertyMetadata();
                p_data.Info    = p_info;
                p_data.IsField = false;
                props.Add(p_data);
            }

            //foreach (FieldInfo f_info in type.GetFields ()) {
            //    PropertyMetadata p_data = new PropertyMetadata ();
            //    p_data.Info = f_info;
            //    p_data.IsField = true;

            //    props.Add (p_data);
            //}

            foreach (FieldInfo f_info in type.GetFields(BindingFlags.Instance | BindingFlags.Public))
            {
                NonSerializable s = (NonSerializable)Attribute.GetCustomAttribute(f_info, typeof(NonSerializable));
                if (s == null)
                {
                    PropertyMetadata p_data = new PropertyMetadata();
                    p_data.Info    = f_info;
                    p_data.IsField = true;

                    props.Add(p_data);
                }
            }

            foreach (FieldInfo f_info in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
            {
                Serializable s = (Serializable)Attribute.GetCustomAttribute(f_info, typeof(Serializable));
                if (s != null)
                {
                    PropertyMetadata p_data = new PropertyMetadata();
                    p_data.Info    = f_info;
                    p_data.IsField = true;

                    props.Add(p_data);
                }
            }

            lock (type_properties_lock) {
                try {
                    type_properties.Add(type, props);
                } catch (ArgumentException) {
                    return;
                }
            }
        }
Example #14
0
        private static void AddObjectMetadata(Type type)
        {
            if (object_metadata.ContainsKey(type))
            {
                return;
            }

            ObjectMetadata data = new ObjectMetadata();

            if (type.GetInterface("System.Collections.IDictionary") != null)
            {
                data.IsDictionary = true;
            }

            data.Properties = new Dictionary <string, PropertyMetadata> ();

            foreach (PropertyInfo p_info in type.GetProperties())
            {
                if (p_info.Name == "Item")
                {
                    ParameterInfo[] parameters = p_info.GetIndexParameters();

                    if (parameters.Length != 1)
                    {
                        continue;
                    }

                    if (parameters[0].ParameterType == typeof(string))
                    {
                        data.ElementType = p_info.PropertyType;
                    }

                    continue;
                }

                PropertyMetadata p_data = new PropertyMetadata();
                p_data.Info = p_info;
                p_data.Type = p_info.PropertyType;

                data.Properties.Add(p_info.Name, p_data);
            }



            //foreach (FieldInfo f_info in type.GetFields ()) {
            //    PropertyMetadata p_data = new PropertyMetadata ();
            //    p_data.Info = f_info;
            //    p_data.IsField = true;
            //    p_data.Type = f_info.FieldType;

            //    data.Properties.Add (f_info.Name, p_data);
            //}

            foreach (FieldInfo f_info in type.GetFields(BindingFlags.Instance | BindingFlags.Public))
            {
                NonSerializable s = (NonSerializable)Attribute.GetCustomAttribute(f_info, typeof(NonSerializable));
                if (s == null)
                {
                    PropertyMetadata p_data = new PropertyMetadata();
                    p_data.Info    = f_info;
                    p_data.IsField = true;
                    p_data.Type    = f_info.FieldType;

                    data.Properties.Add(f_info.Name, p_data);
                }
            }

            foreach (FieldInfo f_info in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
            {
                Serializable s = (Serializable)Attribute.GetCustomAttribute(f_info, typeof(Serializable));
                if (s != null)
                {
                    PropertyMetadata p_data = new PropertyMetadata();
                    p_data.Info    = f_info;
                    p_data.IsField = true;
                    p_data.Type    = f_info.FieldType;

                    data.Properties.Add(f_info.Name, p_data);
                }
            }


            lock (object_metadata_lock) {
                try {
                    object_metadata.Add(type, data);
                } catch (ArgumentException) {
                    return;
                }
            }
        }
 public void non_serializable_fails_on_deep_clone()
 {
     var a = new NonSerializable();
     SerializationUtils.DeepClone(a);
 }