示例#1
0
        public void TransformWithGeneric()
        {
            var  dummyFormat = new StringFormatTest("3");
            Node node        = new Node("mytest", dummyFormat);

            node.TransformWith <PrivateConverter>();
            Assert.IsInstanceOf <IntFormatTest>(node.Format);
            Assert.AreNotSame(dummyFormat, node.Format);
            Assert.AreEqual(4, node.GetFormatAs <IntFormatTest>().Value);
        }
示例#2
0
        public void ChangeFormatWithoutDisposingPreviousFormat()
        {
            var  dummyFormat1 = new StringFormatTest("3");
            var  dummyFormat2 = new IntFormatTest(4);
            Node node         = new Node("mytest", dummyFormat1);

            node.ChangeFormat(dummyFormat2, false);
            Assert.IsFalse(dummyFormat1.Disposed);
            Assert.IsFalse(dummyFormat2.Disposed);
        }
示例#3
0
        public void TransformToWithTypeDisposeFormat()
        {
            var  dummyFormat = new StringFormatTest("3");
            Node node        = new Node("mytest", dummyFormat);

            node.TransformTo(typeof(IntFormatTest));
            Assert.IsTrue(dummyFormat.Disposed);
            Assert.IsFalse(node.GetFormatAs <IntFormatTest>().Disposed);
            node.Dispose();
        }
示例#4
0
        public void GetFormatAsAfterDisposeThrowsException()
        {
            StringFormatTest format = new StringFormatTest("3");
            Node             node   = new Node("NodeTest", format);

            node.Dispose();
            Assert.That(
                node.GetFormatAs <StringFormatTest>,
                Throws.TypeOf <ObjectDisposedException>());
        }
示例#5
0
        public void ChangeFormat()
        {
            var  dummyFormat1 = new StringFormatTest("3");
            var  dummyFormat2 = new IntFormatTest(4);
            Node node         = new Node("mytest", dummyFormat1);

            node.ChangeFormat(dummyFormat2);
            Assert.AreNotSame(node.Format, dummyFormat1);
            Assert.AreSame(node.Format, dummyFormat2);
        }
示例#6
0
        public void TransformTypedChangeFormat()
        {
            Format dummyFormat = new StringFormatTest("3");
            Node   node        = new Node("mytest", dummyFormat);

            node.Transform(typeof(IntFormatTest));
            Assert.IsInstanceOf <IntFormatTest>(node.Format);
            Assert.AreNotSame(dummyFormat, node.Format);
            Assert.AreEqual(3, (node.Format as IntFormatTest).Value);
        }
示例#7
0
        public void SetFormatDoesNotDisposePreviousFormat()
        {
            Format dummyFormat1 = new StringFormatTest("3");
            Format dummyFormat2 = new IntFormatTest(4);
            Node   node         = new Node("mytest", dummyFormat1);

            node.Format = dummyFormat2;
            Assert.IsFalse(dummyFormat1.Disposed);
            Assert.IsFalse(dummyFormat2.Disposed);
        }
示例#8
0
        public void SetFormat()
        {
            Format dummyFormat1 = new StringFormatTest("3");
            Format dummyFormat2 = new IntFormatTest(4);
            Node   node         = new Node("mytest", dummyFormat1);

            node.Format = dummyFormat2;
            Assert.AreNotSame(node.Format, dummyFormat1);
            Assert.AreSame(node.Format, dummyFormat2);
        }
示例#9
0
        public void TransformConcatenating()
        {
            Format dummyFormat = new StringFormatTest("3");
            Node   node        = new Node("mytest", dummyFormat);

            node.Transform <IntFormatTest>().Transform <StringFormatTest>();
            Assert.IsInstanceOf <StringFormatTest>(node.Format);
            Assert.AreNotSame(dummyFormat, node.Format);
            Assert.AreEqual("3", (node.Format as StringFormatTest).Value);
        }
示例#10
0
        public void TransformWithPrivateTypeThrowsException()
        {
            var  dummyFormat = new StringFormatTest("3");
            Node node        = new Node("mytest", dummyFormat);

            Assert.That(
                () => node.TransformWith(typeof(PrivateConverter)),
                Throws.InvalidOperationException.With.Message.EqualTo(
                    "Cannot find converter " +
                    typeof(PrivateConverter).FullName));
        }
示例#11
0
        public void TransformWithAndTypeConverterChangeFormat()
        {
            PrivateConverter converter   = new PrivateConverter();
            Format           dummyFormat = new StringFormatTest("3");
            Node             node        = new Node("mytest", dummyFormat);

            node.Transform(typeof(IntFormatTest), converter: converter);
            Assert.IsInstanceOf <IntFormatTest>(node.Format);
            Assert.AreNotSame(dummyFormat, node.Format);
            Assert.AreEqual(4, (node.Format as IntFormatTest).Value);
        }
示例#12
0
        public void TransformWithTypeThrowsIfNull()
        {
            var  dummyFormat = new StringFormatTest("3");
            Node node        = new Node("mytest", dummyFormat);

            Type myType = null;

            Assert.That(
                () => node.TransformWith(myType),
                Throws.ArgumentNullException);
        }
示例#13
0
        public void DisposeDoesDisposeFormat()
        {
            using var dummyFormat = new StringFormatTest("3");
            Node node = new Node("mytest", dummyFormat);

            Assert.IsFalse(node.Disposed);
            Assert.IsFalse(dummyFormat.Disposed);
            node.Dispose();
            Assert.IsTrue(node.Disposed);
            Assert.IsTrue(dummyFormat.Disposed);
        }
示例#14
0
        public void TransformWithType()
        {
            var dummyFormat = new StringFormatTest("3");

            using Node node = new Node("mytest", dummyFormat);

            node.TransformWith(typeof(StringFormatTest2IntFormatTestConverter));
            Assert.IsInstanceOf <IntFormatTest>(node.Format);
            Assert.AreNotSame(dummyFormat, node.Format);
            Assert.AreEqual(3, node.GetFormatAs <IntFormatTest>().Value);
        }
示例#15
0
        public void TransformWithInstanceThrowsExceptionIfSelectWrongConverter()
        {
            PrivateConverter converter = new PrivateConverter();
            var dummyFormat            = new StringFormatTest("3");

            using Node node = new Node("mytest", dummyFormat);

            Assert.That(
                () => node.TransformWith <IntFormatTest, StringFormatTest>(converter),
                Throws.InstanceOf <InvalidCastException>());
        }
示例#16
0
        public void TransformToGeneric()
        {
            var dummyFormat = new StringFormatTest("3");

            using Node node = new Node("mytest", dummyFormat);

            node.TransformTo <IntFormatTest>();
            Assert.IsInstanceOf <IntFormatTest>(node.Format);
            Assert.AreNotSame(dummyFormat, node.Format);
            Assert.AreEqual(3, node.GetFormatAs <IntFormatTest>().Value);
        }
示例#17
0
        public void ChangeFormatDoesNothingForSameFormat()
        {
            var dummyFormat1 = new StringFormatTest("3");
            var dummyFormat2 = dummyFormat1;

            using Node node = new Node("mytest", dummyFormat1);
            node.ChangeFormat(dummyFormat2);
            Assert.AreEqual(dummyFormat2, node.Format);
            Assert.IsFalse(dummyFormat1.Disposed);
            Assert.IsFalse(dummyFormat2.Disposed);
        }
示例#18
0
        public void TransformToWithType()
        {
            var  dummyFormat = new StringFormatTest("3");
            Node node        = new Node("mytest", dummyFormat);

            var result = node.TransformTo(typeof(IntFormatTest));

            Assert.IsInstanceOf <IntFormatTest>(node.Format);
            Assert.AreNotSame(dummyFormat, node.Format);
            Assert.AreEqual(3, node.GetFormatAs <IntFormatTest>().Value);
            Assert.AreSame(node, result);
        }
示例#19
0
        public void TransformWithInstance()
        {
            PrivateConverter converter = new PrivateConverter();
            var dummyFormat            = new StringFormatTest("3");

            using Node node = new Node("mytest", dummyFormat);

            node.TransformWith <StringFormatTest, IntFormatTest>(converter);
            Assert.IsInstanceOf <IntFormatTest>(node.Format);
            Assert.AreNotSame(dummyFormat, node.Format);
            Assert.AreEqual(4, node.GetFormatAs <IntFormatTest>().Value);
        }
示例#20
0
        public void SetFromContainerToDifferentCleanChildren()
        {
            using Node node = new Node("mytest");
            NodeContainerFormat format = new NodeContainerFormat();

            format.Root.Add(new Node("Child"));
            node.ChangeFormat(format);
            Assert.IsNotEmpty(node.Children);

            StringFormatTest newFormat = new StringFormatTest("3");

            node.ChangeFormat(newFormat);
            Assert.IsEmpty(node.Children);
        }
示例#21
0
        public void TransformWithThrowsIfNoConverterImplementation()
        {
            var  dummyFormat = new StringFormatTest("3");
            Node node        = new Node("mytest", dummyFormat);

            var msg = "Converter doesn't implement IConverter<,>";

            Assert.That(
                () => node.TransformWith <ConverterWithoutGenericInterface>(),
                Throws.InvalidOperationException.With.Message.EqualTo(msg));
            Assert.That(
                () => node.TransformWith <ConverterWithoutGenericInterface, int>(0),
                Throws.InvalidOperationException.With.Message.EqualTo(msg));

            // It won't be discovered
            Assert.That(
                () => node.TransformWith(typeof(ConverterWithoutGenericInterface)),
                Throws.InvalidOperationException.With.Message.EqualTo(
                    "Cannot find converter " +
                    typeof(ConverterWithoutGenericInterface).FullName));
        }