I have an application where I need to have text with multiple attributes displayed in the same label or text field, and the proper answer appears to be to use the FormattedString class and add a new Span to it for each change I need to make. The changes I need to support include text color, bold, and underline. Since I want to be able to test my conversions, I created a class to do the conversions separately from the UI. This class looks at the definitions of the text segments and applies the TextDecoration for underline, the TextColor, or the FontAttribute for bold as necessary. All was fine with TextDecoration and TextColor, however when I tried the following code:
if (itemSegment.IsBold)
{
segmentSpan.FontAttributes = FontAttributes.Bold;
}
my unit tests throw an exception "System.InvalidOperationException: You MUST call Xamarin.Forms.Init(); prior to using it."
I can only assume from research that the FontAttributes is calling something like the DependencyService or DeviceInfo in the background.
Is anyone aware of a way I can mock the initialization in an MS test so that I can unit test this code?
TIA
Ron L.