public void ConvertsToBrush() { var falseBrush = new SolidColorBrush(Colors.Black); var trueBrush = new SolidColorBrush(Colors.White); var converter = new BoolToBrushConverter() { FalseBrush = falseBrush, TrueBrush = trueBrush }; using var source = new BehaviorSubject <bool?>(null); var convertedBrush = (Brush?)converter.Convert(false, typeof(Brush), null, CultureInfo.InvariantCulture); Assert.AreEqual(falseBrush, convertedBrush); convertedBrush = (Brush?)converter.Convert(true, typeof(Brush), null, CultureInfo.InvariantCulture); Assert.AreEqual(trueBrush, convertedBrush); }
public void Cannot_Get_Brush_From_Null_Value() { //Arrange BoolToBrushConverter converter = new BoolToBrushConverter(); //Act ActualValueDelegate <object> testDelegate = () => converter.Convert(null, typeof(Brush), null, CultureInfo.CurrentCulture); //Assert Assert.That(testDelegate, Throws.TypeOf <NullReferenceException>()); }
public void Cannot_Get_Brush_From_Invalid_Type_Value() { //Arrange var convertFrom = "string"; BoolToBrushConverter converter = new BoolToBrushConverter(); //Act ActualValueDelegate <object> testDelegate = () => converter.Convert(convertFrom, typeof(Brush), null, CultureInfo.CurrentCulture); //Assert Assert.That(testDelegate, Throws.TypeOf <InvalidCastException>()); }
public void Can_Get_White_Brush_From_True_Value() { //Arrange var convertFrom = false; BoolToBrushConverter converter = new BoolToBrushConverter(); //Act var result = converter.Convert(convertFrom, typeof(Brush), null, CultureInfo.CurrentCulture); //Assert Assert.AreEqual(result, Brushes.White); }