Ejemplo n.º 1
0
        public void EnumToBoolConvert_ValueNotEnum_ThrowsArgumentException(object value)
        {
            var enumToBoolConverter = new EnumToBoolConverter();

            Assert.Throws <ArgumentException>(() =>
                                              enumToBoolConverter.Convert(value, typeof(bool), TestEnumForEnumToBoolConverter.Five, CultureInfo.InvariantCulture));
        }
Ejemplo n.º 2
0
        public void EnumToBoolConvert_ParameterNotSameEnum_ReturnsFalse(object parameter)
        {
            var enumToBoolConverter = new EnumToBoolConverter();

            var result = enumToBoolConverter.Convert(TestEnumForEnumToBoolConverter.Five, typeof(bool), parameter, CultureInfo.InvariantCulture);

            Assert.False(result as bool?);
        }
        public void EnumToBoolConvert_Validation(object?[]?trueValues, object?value, object parameter, bool expectedResult)
        {
            var enumToBoolConverter = new EnumToBoolConverter();

            trueValues?.OfType <Enum>().ToList().ForEach(fe => enumToBoolConverter.TrueValues.Add(fe));

            var result = enumToBoolConverter.Convert(value, typeof(bool), parameter, CultureInfo.InvariantCulture);

            Assert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 4
0
        public void EnumToBoolConvert_Validation(object?[]?trueValues, object?value, object parameter, bool expectedResult)
        {
            var enumToBoolConverter = new EnumToBoolConverter();

            foreach (var enumType in trueValues?.OfType <Enum>() ?? Enumerable.Empty <Enum>())
            {
                enumToBoolConverter.TrueValues.Add(enumType);
            }

            var result = enumToBoolConverter.Convert(value, typeof(bool), parameter, CultureInfo.InvariantCulture);

            Assert.AreEqual(expectedResult, result);
        }
        public void ShouldConvertToFalseValue()
        {
            // Arrange
            IValueConverter converter = new EnumToBoolConverter();
            const TestEnum Input = TestEnum.Lorem;
            string inputParameter = TestEnum.Ipsum.ToString();
            const bool ExpectedValue = false;

            // Act
            var convertedOutput = converter.Convert(Input, null, inputParameter, null);

            // Assert
            Assert.Equal(ExpectedValue, convertedOutput);
        }