Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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>());
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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>());
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }