Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

Commented Feature: Allow for custom IValueFormatters [12364]

$
0
0
I have some cases where I override ToString on my class under test but I'd prefer to use the DefaultValueFormatter as it display nicer formatted results for me (though there are a few properties I would like to omit). There a number ways to fix this but in the end I think allowing the user to setup their own IValueFormatter(s) would be great.
Comments: ** Comment from web user: AB_dreeve **

A general example case is when I have a class which I override ToString() to return only 1 or 2 properties on my class, but my class might have many more properties. Losing the default formatting and the ability to display the additional properties is unfortunate because the additional property values is often important in why a test might fail.

For example:

public class ExcelSchemaDefinition {
public int Index { get; set; }
public string DataField { get; set; }
public string ColumnLabel { get; set; }
public int ColumnIndex { get; set; }
public string CellFormat { get; set; }
public string PropertyName { get; set; }
public Type PropertyType { get; set; }

/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>
/// A string that represents the current object.
/// </returns>
/// <filterpriority>2</filterpriority>
public override string ToString() {
return string.Format("Index: {0}, ColumnLabel: {1}, DataField: {2}", this.Index, this.ColumnLabel, this.DataField);
}
}

My app wants nice short ToStrings() for various reasons, but the DefaultValueFormatter or a CustomValueFormatter helps me see whats wrong with my tests quickly.


Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>