public void Convert_WrongDataType_ExceptionThrown() { var sut = new InverseBooleanConverter(); sut.Invoking(x => x.Convert(true, typeof(int), 0, CultureInfo.InvariantCulture)).Should() .Throw <ArgumentException>(); }
public void Convert_AllPossibleInputs_Converted(bool input, bool expected) { var sut = new InverseBooleanConverter(); var result = sut.Convert(input, typeof(bool), 0, CultureInfo.InvariantCulture); result.Should().Be(expected); }
public void ConvertTest() { InverseBooleanConverter converter = new InverseBooleanConverter(); bool b = false; var value = (bool)converter.Convert(b, typeof(bool), null, CultureInfo.CurrentCulture); Assert.IsTrue(value); }
public void WhenConvertingFalseThenResultIsTrue() { var inverseBooleanConverter = new InverseBooleanConverter(); object result = inverseBooleanConverter.Convert(false, typeof(bool), null, new CultureInfo("en-us")); Assert.IsInstanceOfType(result, typeof(bool)); Assert.AreEqual(result, true); }
public void ShouldThrowIfTargetIsNotABool() { var ibc = new InverseBooleanConverter(); Assert.Throws <InvalidOperationException>(() => ibc.Convert(false, null, null, null)); Assert.Throws <InvalidOperationException>(() => ibc.ConvertBack(false, null, null, null)); Assert.Throws <InvalidOperationException>(() => ibc.Convert(false, typeof(string), null, null)); Assert.Throws <InvalidOperationException>(() => ibc.ConvertBack(false, typeof(string), null, null)); }
public void FalseConvertersToTrue() { var converter = new InverseBooleanConverter(); object output = null; var exception = Record.Exception(() => { output = converter.Convert(false, typeof(bool), null, CurrentCulture); }); Assert.Null(exception); Assert.NotNull(output); Assert.IsType <bool>(output); Assert.True((bool)output); }
private void CheckConvertBack(object value, bool target, InverseBooleanConverter converter) { var result = converter.ConvertBack(value, null, null, CultureInfo.CurrentCulture); if (result is bool boolean) { Assert.AreEqual(target, boolean); } else { Assert.Fail($"The result should be a boolean but actually is '{result?.GetType().Name ?? "[UNKNOWN]"}'."); } }
public void VerifyConverterConverts() { var converter = new InverseBooleanConverter(); Assert.Throws <InvalidOperationException>(() => converter.Convert(null, typeof(string), null, null)); var value = converter.Convert(true, typeof(bool), null, null); Assert.IsFalse(value is bool b && b); value = converter.Convert(false, typeof(bool), null, null); Assert.IsTrue(value is bool c && c); }
public void ShouldInverseABool() { var ibc = new InverseBooleanConverter(); var result = ibc.Convert(false, typeof(bool), null, null); Assert.IsType <bool>(result); Assert.True((bool)result); result = ibc.ConvertBack(result, typeof(bool), null, null); Assert.IsType <bool>(result); Assert.False((bool)result); }
public void WhenConvertingWithChainedConvertersThenResultWasConvertedByEachConverterInTheExpectedOrder() { var emptyStringToBooleanConverter = new EmptyStringToBooleanConverter(); var inverseBooleanConverter = new InverseBooleanConverter(); var convertersChain = new ConverterChain(new Collection <IValueConverter>() { emptyStringToBooleanConverter, inverseBooleanConverter }); object result = convertersChain.Convert("just a string", typeof(bool), null, new CultureInfo("en-us")); Assert.IsInstanceOfType(result, typeof(bool)); Assert.AreEqual(result, true); }
public void InverseBooleanConverterConstructorTestMethod() { InverseBooleanConverter target = new InverseBooleanConverter(); object value = null; object actual = (target as IValueConverter).Convert(value, typeof(bool), null, null); Assert.IsNull(value); target.NullSource = true; actual = (target as IValueConverter).Convert(value, typeof(bool), null, null); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(bool)); Assert.IsTrue((bool)actual); value = false; actual = (target as IValueConverter).Convert(value, typeof(bool), null, null); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(bool)); Assert.IsTrue((bool)actual); target.NullSource = false; actual = (target as IValueConverter).Convert(value, typeof(bool), null, null); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(bool)); Assert.IsTrue((bool)actual); value = false; actual = (target as IValueConverter).Convert(value, typeof(bool), null, null); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(bool)); Assert.IsTrue((bool)actual); value = true; target.NullSource = true; actual = (target as IValueConverter).Convert(value, typeof(bool), null, null); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(bool)); Assert.IsFalse((bool)actual); }
static InverseBooleanConverter() { Instance = new InverseBooleanConverter(); }
private void CheckConvertBack(bool value, bool target, InverseBooleanConverter converter) => this.CheckConvertBack((object)value, target, converter);
public void Setup() { _target = new InverseBooleanConverter(); }
public void SetUp() { _inverseBooleanConverter = new InverseBooleanConverter(); }
public void Setup() { _converter = new InverseBooleanConverter(); }
public void VerifyConverterConvertsBackThrows() { var converter = new InverseBooleanConverter(); Assert.Throws <NotSupportedException>(() => converter.ConvertBack(null, null, null, null)); }