Ejemplo n.º 1
0
        public void Culture()
        {
            var    serializer = SerializerFactory.Create <MessageWithDouble>();
            double val        = 65.36;
            var    msg        = new MessageWithDouble {
                Double = val
            };

            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");

            var stream = new MemoryStream();

            serializer.Serialize(new[] { msg }, stream);

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            stream.Position = 0;
            var msgArray = serializer.Deserialize(stream);
            var m        = msgArray[0] as MessageWithDouble;

            Assert.AreEqual(val, m.Double);

            stream.Dispose();
        }
Ejemplo n.º 2
0
        public void TestInterfaces()
        {
            IMessageMapper mapper     = new MessageMapper();
            var            serializer = SerializerFactory.Create <IM2>();


            var o = mapper.CreateInstance <IM2>();

            o.Id      = Guid.NewGuid();
            o.Age     = 10;
            o.Address = Guid.NewGuid().ToString();
            o.Int     = 7;
            o.Name    = "udi";
            o.Uri     = new Uri("http://www.UdiDahan.com/");
            o.Risk    = new Risk {
                Percent = 0.15D, Annum = true, Accuracy = 0.314M
            };
            o.Some         = SomeEnum.B;
            o.Start        = DateTime.Now;
            o.Duration     = TimeSpan.Parse("-01:15:27.123");
            o.Offset       = DateTimeOffset.Now;
            o.Lookup       = new MyDic();
            o.Lookup["1"]  = "1";
            o.Foos         = new Dictionary <string, List <Foo> >();
            o.Foos["foo1"] = new List <Foo>(new[] { new Foo {
                                                        Name = "1", Title = "1"
                                                    }, new Foo {
                                                        Name = "2", Title = "2"
                                                    } });
            o.Data        = new byte[] { 1, 2, 3, 4, 5, 4, 3, 2, 1 };
            o.SomeStrings = new List <string> {
                "a", "b", "c"
            };

            o.ArrayFoos = new Foo[] { new Foo {
                                          Name = "FooArray1", Title = "Mr."
                                      }, new Foo {
                                          Name = "FooAray2", Title = "Mrs"
                                      } };
            o.Bars = new Bar[] { new Bar {
                                     Name = "Bar1", Length = 1
                                 }, new Bar {
                                     Name = "BAr2", Length = 5
                                 } };
            o.NaturalNumbers = new HashSet <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            o.Developers     = new HashSet <string>(new string[] { "Udi Dahan", "Andreas Ohlund", "Matt Burton", "Jonathan Oliver et al" });

            o.Parent         = mapper.CreateInstance <IM1>();
            o.Parent.Name    = "udi";
            o.Parent.Age     = 10;
            o.Parent.Address = Guid.NewGuid().ToString();
            o.Parent.Int     = 7;
            o.Parent.Name    = "-1";
            o.Parent.Risk    = new Risk {
                Percent = 0.15D, Annum = true, Accuracy = 0.314M
            };

            o.Names = new List <IM1>();
            for (int i = 0; i < number; i++)
            {
                var m1 = mapper.CreateInstance <IM1>();
                o.Names.Add(m1);
                m1.Age     = 10;
                m1.Address = Guid.NewGuid().ToString();
                m1.Int     = 7;
                m1.Name    = i.ToString();
                m1.Risk    = new Risk {
                    Percent = 0.15D, Annum = true, Accuracy = 0.314M
                };
            }

            o.MoreNames = o.Names.ToArray();

            IMessage[] messages = new IMessage[] { o };

            Time(messages, serializer);
        }
Ejemplo n.º 3
0
 public void When_Using_A_Dictionary_With_An_Object_As_Value_should_throw()
 {
     Assert.Throws <NotSupportedException>(() => SerializerFactory.Create <MessageWithDictionaryWithAnObjectAsValue>());
 }