public void OutputBoth() { var property1Value = "Property1"; var field1Value = "Field1"; var source = new PropertyAndFieldClass() { Property = property1Value }; source.Field = field1Value; var expected = $"{nameof(PropertyAndFieldClass)}{{" + $"{nameof(PropertyAndFieldClass.Property)}={property1Value}," + $"{nameof(PropertyAndFieldClass.Field)}={field1Value}}}"; ; var config = new ToStringConfig <PropertyAndFieldClass>() { OutputTarget = TargetType.Both }; var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void ExpandIEnumerable() { var e1p1 = "Property11"; var e1p2 = "Property12"; var e2p1 = "Property21"; var e2p2 = "Property22"; var e1 = new DualPropertyClass2() { Property1 = e1p1, Property2 = e1p2 }; var e2 = new DualPropertyClass2() { Property1 = e2p1, Property2 = e2p2 }; var source = new IncludingIEnumerable() { Property1 = new DualPropertyClass2[] { e1, e2 } }; var expected = $"{nameof(IncludingIEnumerable)}{{" + $"{nameof(IncludingIEnumerable.Property1)}=[" + $"{e1.ToString()},{e2.ToString()}]}}"; var config = new ToStringConfig <IncludingIEnumerable>() { ExpandIEnumerable = true }; var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void IgnoreWhiteSpaceProperty() { var source = new DualPropertyClass() { Property1 = " ", Property2 = null }; var config = new ToStringConfig<DualPropertyClass>() { IgnoreMode = IgnoreMemberMode.NullOrWhiteSpace }; var expected = $"{nameof(DualPropertyClass)}{{}}"; var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void IgnoreNullProperty() { var property1Value = " "; var source = new DualPropertyClass() { Property1 = property1Value, Property2 = null }; var config = new ToStringConfig<DualPropertyClass>() { IgnoreMode = IgnoreMemberMode.Null }; var expected = $"{nameof(DualPropertyClass)}{{{nameof(DualPropertyClass.Property1)}={property1Value}}}"; var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void ProcessOneFieldClass() { var field1Value = "Field1"; var source = new SingleFieldClass(); source.Field1 = field1Value; var expected = $"{nameof(SingleFieldClass)}{{{nameof(SingleFieldClass.Field1)}={field1Value}}}"; var config = new ToStringConfig <SingleFieldClass>(); config.OutputTarget = TargetType.Both; var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void IgnoreSpecifiedProperty() { var property1Value = "Property1"; var property2Value = "Property2"; var source = new DualPropertyClass() { Property1 = property1Value, Property2 = property2Value }; var expected = $"{nameof(DualPropertyClass)}{{" + $"{nameof(DualPropertyClass.Property1)}={property1Value}}}"; var config = new ToStringConfig<DualPropertyClass>(); config.SetIgnoreMember(it => it.Property2); var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void IgnoreWhiteSpaceProperty() { var source = new DualPropertyClass() { Property1 = " ", Property2 = null }; var config = new ToStringConfig <DualPropertyClass>() { IgnoreMode = IgnoreMemberMode.NullOrWhiteSpace }; var expected = $"{nameof(DualPropertyClass)}{{}}"; var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void IgnoreNullProperty() { var property1Value = " "; var source = new DualPropertyClass() { Property1 = property1Value, Property2 = null }; var config = new ToStringConfig <DualPropertyClass>() { IgnoreMode = IgnoreMemberMode.Null }; var expected = $"{nameof(DualPropertyClass)}{{{nameof(DualPropertyClass.Property1)}={property1Value}}}"; var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void OutputField() { var property1Value = "Property1"; var field1Value = "Field1"; var source = new PropertyAndFieldClass() { Property = property1Value }; source.Field = field1Value; var expected = $"{nameof(PropertyAndFieldClass)}{{" + $"{nameof(PropertyAndFieldClass.Field)}={field1Value}}}"; var config = new ToStringConfig<PropertyAndFieldClass>() { OutputTarget = TargetType.Field }; var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void IgnoreSpecifiedProperty() { var property1Value = "Property1"; var property2Value = "Property2"; var source = new DualPropertyClass() { Property1 = property1Value, Property2 = property2Value }; var expected = $"{nameof(DualPropertyClass)}{{" + $"{nameof(DualPropertyClass.Property1)}={property1Value}}}"; var config = new ToStringConfig <DualPropertyClass>(); config.SetIgnoreMember(it => it.Property2); var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void ExpandIEnumerable() { var e1p1 = "Property11"; var e1p2 = "Property12"; var e2p1 = "Property21"; var e2p2 = "Property22"; var e1 = new DualPropertyClass2() { Property1 = e1p1, Property2 = e1p2 }; var e2 = new DualPropertyClass2() { Property1 = e2p1, Property2 = e2p2 }; var source = new IncludingIEnumerable() { Property1 = new DualPropertyClass2[] { e1, e2 } }; var expected = $"{nameof(IncludingIEnumerable)}{{" + $"{nameof(IncludingIEnumerable.Property1)}=[" + $"{e1.ToString()},{e2.ToString()}]}}"; var config = new ToStringConfig<IncludingIEnumerable>() { ExpandIEnumerable = true }; var actual = ToStringBuilder.ToString(source, config); Console.WriteLine(actual); Assert.AreEqual(expected, actual); }