Пример #1
0
        public void GetEncodersByType()
        {
            var encoder1 = new ObjectToEncoderInstanceEncoder <Uri>();
            var encoder2 = new ObjectToEncoderInstanceEncoder <Uri>();
            var group    = new EncoderGroup {
                new ObjectToEncoderInstanceEncoder <Tuple <int> >(),
                encoder1,
                encoder2,
            };

            var got = group.GetEncoders(typeof(Uri)).ToArray();

            CollectionAssert.AreEqual(new[] { encoder1, encoder2 }, got);
        }
Пример #2
0
        public void Encodes()
        {
            var encoder0 = new ObjectToEncoderInstanceEncoder <Tuple <int> >();
            var encoder1 = new ObjectToEncoderInstanceEncoder <Uri>();
            var encoder2 = new ObjectToEncoderInstanceEncoder <Uri>();
            var group    = new EncoderGroup {
                encoder0,
                encoder1,
                encoder2,
            };

            var uri       = group.TryEncode(new Uri("data:"));
            var clrObject = (CLRObject)ManagedType.GetManagedObject(uri.Handle);

            Assert.AreSame(encoder1, clrObject.inst);
            Assert.AreNotSame(encoder2, clrObject.inst);

            var tuple = group.TryEncode(Tuple.Create(1));

            clrObject = (CLRObject)ManagedType.GetManagedObject(tuple.Handle);
            Assert.AreSame(encoder0, clrObject.inst);
        }