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); }
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); }
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(); }
public void GetFormatAsAfterDisposeThrowsException() { StringFormatTest format = new StringFormatTest("3"); Node node = new Node("NodeTest", format); node.Dispose(); Assert.That( node.GetFormatAs <StringFormatTest>, Throws.TypeOf <ObjectDisposedException>()); }
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); }
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); }
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); }
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); }
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); }
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)); }
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); }
public void TransformWithTypeThrowsIfNull() { var dummyFormat = new StringFormatTest("3"); Node node = new Node("mytest", dummyFormat); Type myType = null; Assert.That( () => node.TransformWith(myType), Throws.ArgumentNullException); }
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); }
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); }
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>()); }
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); }
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); }
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); }
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); }
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); }
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)); }