Beispiel #1
0
        public void NegativeAddValueTwice()
        {
            var si = new SerializationInfo(typeof(Serializable), FormatterConverter.Default);
            Assert.Throws<SerializationException>(() =>
            {
                si.AddValue("bool", true);
                si.AddValue("bool", true);
            });

            try
            {
                si.AddValue("bool", false);
            }
            catch (Exception e)
            {
                Assert.Equal("Cannot add the same member twice to a SerializationInfo object.", e.Message);
            }
        }
 public void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.AddValue("string", "hello");
     info.AddValue("bool", true);
     info.AddValue("char", 'a');
     info.AddValue("byte", byte.MaxValue);
     info.AddValue("decimal", decimal.MaxValue);
     info.AddValue("double", double.MaxValue);
     info.AddValue("short", short.MaxValue);
     info.AddValue("int", int.MaxValue);
     info.AddValue("long", long.MaxValue);
     info.AddValue("sbyte", sbyte.MaxValue);
     info.AddValue("float", float.MaxValue);
     info.AddValue("ushort", ushort.MaxValue);
     info.AddValue("uint", uint.MaxValue);
     info.AddValue("ulong", ulong.MaxValue);
     info.AddValue("datetime", DateTime.MaxValue);
 }
 public void NegativeValueNotFound()
 {
     var si = new SerializationInfo(typeof(Serializable), new FormatterConverter());
     si.AddValue("a", 1);
     Assert.Throws<SerializationException>(() => si.GetInt32("b"));
 }
 public void NegativeAddValueTwice()
 {
     var si = new SerializationInfo(typeof(Serializable), new FormatterConverter());
     si.AddValue("bool", true);
     Assert.Throws<SerializationException>(() => si.AddValue("bool", true));
 }
Beispiel #5
0
        public void NegativeValueNotFound()
        {
            var si = new SerializationInfo(typeof(Serializable), FormatterConverter.Default);
            Assert.Throws<SerializationException>(() =>
            {
                si.AddValue("a", 1);
                si.GetInt32("b");
            });

            si = new SerializationInfo(typeof(Serializable), FormatterConverter.Default);
            try
            {
                si.AddValue("a", 1);
                si.GetInt32("b");
            }
            catch (Exception e)
            {
                Assert.Equal("Member 'b' was not found.", e.Message);
            }
        }