public void ReadOnlyDependencyPropertiesTest()
        {
            ReadOnlyElement element = new ReadOnlyElement();

            Assert.AreEqual(0, element.Value1);

            element.SetValue(ReadOnlyElement._private_Value1Key, 1);
            Assert.AreEqual(1, element.Value1);

            try
            {
                element.SetValue(ReadOnlyElement.Value1Property, 2);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is Exception);
            }

            try
            {
                IDependencyPropertyValueEntry entry = element.GetValueEntry(ReadOnlyElement.Value1Property);
                entry.SetBaseValue((int)BaseValueSource.Local, 3);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is Exception);
            }

            try
            {
                DependencyPropertyKey fakeKey = new DependencyPropertyKey(ReadOnlyElement.Value1Property);
                element.SetValue(fakeKey, 4);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is Exception);
            }

            try
            {
                DependencyPropertyKey fakeKey = DependencyProperty.RegisterReadOnly("Value1", typeof(int), typeof(ReadOnlyElement), new PropertyMetadata());
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is Exception);
            }
        }
Example #2
0
        public void ReadOnlyElementWrite()
        {
            var body = new ReadOnlyElement("Body", new ReadOnlyAttr("xmlns", "http://tempuri.org/"))
            {
                ["Origin"]      = "THR",
                ["Destination"] = "MHD",
            };

            var buffer = new ArrayBufferWriter <byte>();

            body.WriteTo(buffer);

            var xml = Encoding.UTF8.GetString(buffer.WrittenSpan);
        }