public void SerializeDictionaryWithComplexAttachedProperty()
        {
            var ap = new ComplexAttachedProperty()
            {
                Bar = "WE", Foo = 890
            };

            Dictionary <string, int> priorities = new Dictionary <string, int>();

            priorities.Add("red", 10);

            SetComplex(priorities, ap);

            Assert.IsTrue(GetComplex(priorities).Equals(ap));
            Assert.IsTrue(AttachablePropertyServices.GetAttachedPropertyCount(priorities) == 1);

            var expected =
                @"<Dictionary x:TypeArguments=""x:String, x:Int32"" xmlns=""clr-namespace:System.Collections.Generic;assembly={0}"" xmlns:dt=""clr-namespace:DrtXaml.Tests;assembly=DrtXaml"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
  <dt:AttachablePropertyServicesTests.Complex>
    <dt:ComplexAttachedProperty Bar=""WE"" Foo=""890"" />
  </dt:AttachablePropertyServicesTests.Complex>
  <x:Int32 x:Key=""red"">10</x:Int32>
</Dictionary>";

            expected = string.Format(expected, typeof(Dictionary <string, int>).GetAssemblyName());

            Dictionary <string, int> result = (Dictionary <string, int>)RoundTrip(priorities, expected);

            Assert.IsTrue(GetComplex(result).Equals(ap));
        }
        public void SerializeArrayWithComplexAttachedProperty()
        {
            var ap = new ComplexAttachedProperty()
            {
                Bar = "AP", Foo = 34
            };

            string[] strings = new string[3];
            strings[0] = "all";
            strings[1] = "strings";
            strings[2] = "rule!";

            SetComplex(strings, ap);

            Assert.IsTrue(GetComplex(strings).Equals(ap));
            Assert.IsTrue(AttachablePropertyServices.GetAttachedPropertyCount(strings) == 1);

            var    expected  = @"<x:Array Type=""x:String"" xmlns=""clr-namespace:DrtXaml.Tests;assembly=DrtXaml"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
  <AttachablePropertyServicesTests.Complex>
    <ComplexAttachedProperty Bar=""AP"" Foo=""34"" />
  </AttachablePropertyServicesTests.Complex>
  <x:String>all</x:String>
  <x:String>strings</x:String>
  <x:String>rule!</x:String>
</x:Array>";
            string generated = XamlServices.Save(strings);

            Assert.AreEqual(expected, generated);

            //string[] result = (string[])RoundTrip(strings, expected);

            //Assert.IsTrue(GetComplex(result).Equals(ap));
        }
        public void SerializeWithAPSComplexProperty()
        {
            var ap = new ComplexAttachedProperty()
            {
                Bar = "something", Foo = 65
            };
            FooWithBar f = new FooWithBar()
            {
                Bar = 12,
            };

            SetComplex(f, ap);

            Assert.IsTrue(GetComplex(f).Equals(ap));
            Assert.IsTrue(AttachablePropertyServices.GetAttachedPropertyCount(f) == 1);

            var        expected = @"<FooWithBar Bar=""12"" xmlns=""clr-namespace:DrtXaml.Tests;assembly=DrtXaml"">
  <AttachablePropertyServicesTests.Complex>
    <ComplexAttachedProperty Bar=""something"" Foo=""65"" />
  </AttachablePropertyServicesTests.Complex>
</FooWithBar>";
            FooWithBar result   = (FooWithBar)RoundTrip(f, expected);

            Assert.IsTrue(result.Bar == 12);
            Assert.IsTrue(GetComplex(result).Equals(ap));
        }
        public void SerializeStringWithComplexAttachedProperty()
        {
            var ap = new ComplexAttachedProperty()
            {
                Bar = "something", Foo = 124
            };
            string s = "SomeComplexThing";

            SetComplex(s, ap);

            Assert.IsTrue(GetComplex(s).Equals(ap));
            Assert.IsTrue(AttachablePropertyServices.GetAttachedPropertyCount(s) == 1);

            var expected = @"<x:String xmlns=""clr-namespace:DrtXaml.Tests;assembly=DrtXaml"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">SomeComplexThing<AttachablePropertyServicesTests.Complex><ComplexAttachedProperty Bar=""something"" Foo=""124"" /></AttachablePropertyServicesTests.Complex></x:String>";

            string generated = XamlServices.Save(s);

            Assert.AreEqual(expected, generated);

            //TODO, 549050
            //string result = (string)RoundTrip(s, expected);

            //Assert.IsTrue(result != null);
            //Assert.IsTrue(GetComplex(result).Equals(ap));
        }
        public override bool Equals(object obj)
        {
            ComplexAttachedProperty other = obj as ComplexAttachedProperty;

            if (other == null)
            {
                return(false);
            }
            return(this.Foo.Equals(other.Foo) && this.Bar.Equals(other.Bar));
        }
        public void SerializeCollectionWithComplexAttachedProperty()
        {
            var ap = new ComplexAttachedProperty()
            {
                Bar = "AP", Foo = 52
            };

            List <string> strings = new List <string>();

            strings.Add("Things");
            strings.Add("that");
            strings.Add("make");
            strings.Add("me go hmm...");

            SetComplex(strings, ap);

            Assert.IsTrue(GetComplex(strings).Equals(ap));
            Assert.IsTrue(AttachablePropertyServices.GetAttachedPropertyCount(strings) == 1);

            Type type         = typeof(List <string>);
            var  assemblyName = type.GetAssemblyName();

            var expected =
                @"<List x:TypeArguments=""x:String"" Capacity=""4"" xmlns=""clr-namespace:System.Collections.Generic;assembly={0}"" xmlns:dt=""clr-namespace:DrtXaml.Tests;assembly=DrtXaml"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
  <dt:AttachablePropertyServicesTests.Complex>
    <dt:ComplexAttachedProperty Bar=""AP"" Foo=""52"" />
  </dt:AttachablePropertyServicesTests.Complex>
  <x:String>Things</x:String>
  <x:String>that</x:String>
  <x:String>make</x:String>
  <x:String>me go hmm...</x:String>
</List>";

            expected = string.Format(expected, assemblyName);

            List <string> result = (List <string>)RoundTrip(strings, expected);

            Assert.IsTrue(GetComplex(result).Equals(ap));
        }
 public static void SetComplex(object target, ComplexAttachedProperty value)
 {
     AttachablePropertyServices.SetProperty(target, complexPropertyName, value);
 }