public void ConversionOfTrue()
        {
            var actual   = _sut.Convert("True", null, null, null);
            var expected = Visibility.Visible;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 2
0
 public void BooleanToVisibilityConverterShouldWork()
 {
     var converter = new BooleanToVisibilityConverter();
     Assert.AreEqual(Visibility.Visible, (Visibility)converter.Convert(true, typeof(bool), null, CultureInfo.CurrentCulture));
     Assert.AreEqual(Visibility.Collapsed, (Visibility)converter.Convert(false, typeof(bool), null, CultureInfo.CurrentCulture));
     Assert.AreEqual(Visibility.Collapsed, (Visibility)converter.Convert(null, typeof(bool), null, CultureInfo.CurrentCulture));
 }
Esempio n. 3
0
        public void Test_Convert_NotExpectType()
        {
            var target = new BooleanToVisibilityConverter();

            target.InvisibleToHidden = true;
            target.Convert(1, null, null, null).Should().Be(DependencyProperty.UnsetValue);
            target.Convert("0", null, null, null).Should().Be(DependencyProperty.UnsetValue);
        }
Esempio n. 4
0
        public void Test_Convert_ReverseLogic_InvisibleHidden()
        {
            var target = new BooleanToVisibilityConverter();

            target.ReverseLogic      = true;
            target.InvisibleToHidden = true;
            target.Convert(true, null, null, null).Should().Be(Visibility.Hidden);
            target.Convert(false, null, null, null).Should().Be(Visibility.Visible);
        }
Esempio n. 5
0
        public void Test_Convert_NormalLogic_InvisibleCollapse()
        {
            var target = new BooleanToVisibilityConverter();

            target.ReverseLogic      = false;
            target.InvisibleToHidden = false;
            target.Convert(true, null, null, null).Should().Be(Visibility.Visible);
            target.Convert(false, null, null, null).Should().Be(Visibility.Collapsed);
        }
Esempio n. 6
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (null != parameter && !System.Convert.ToBoolean(parameter, CultureInfo.InvariantCulture))
            {
                return(converter.Convert(!((bool)value), targetType, parameter, culture));
            }

            return(converter.Convert(value, targetType, parameter, culture));
        }
Esempio n. 7
0
        public void ConvertTest()
        {
            const Visibility trueValue  = Visibility.Collapsed;
            const Visibility falseValue = Visibility.Visible;
            var converter = new BooleanToVisibilityConverter(trueValue, falseValue, Visibility.Visible);

            converter.Convert(true, typeof(Visibility), null, null).ShouldEqual(trueValue);
            converter.Convert(false, typeof(Visibility), null, null).ShouldEqual(falseValue);
        }
Esempio n. 8
0
        public void Wpf_Converters_BooleanToVisibility()
        {
            var converter = new BooleanToVisibilityConverter();

            MakeSure.That(converter.Convert(true, null)).Is(Visibility.Visible);
            MakeSure.That(converter.Convert(false, null)).Is(Visibility.Collapsed);
            MakeSure.That(converter.Convert(false, "i")).Is(Visibility.Visible);
            MakeSure.That(converter.Convert(true, "i")).Is(Visibility.Collapsed);
        }
Esempio n. 9
0
        public void BooleanToVisibilityConverter()
        {
            var converter = new BooleanToVisibilityConverter();

            Assert.AreEqual(Visibility.Visible, converter.Convert(true, typeof(ConvertersTests), null, CultureInfo.CurrentCulture));
            Assert.AreEqual(Visibility.Collapsed, converter.Convert(false, typeof(ConvertersTests), null, CultureInfo.CurrentCulture));
            converter.IsInverted = true;
            Assert.AreEqual(Visibility.Collapsed, converter.Convert(true, typeof(ConvertersTests), null, CultureInfo.CurrentCulture));
            Assert.AreEqual(Visibility.Visible, converter.Convert(false, typeof(ConvertersTests), null, CultureInfo.CurrentCulture));
        }
        public void TestBooleanToVisibilityConverter()
        {
            var converter = new BooleanToVisibilityConverter();

            Assert.AreEqual(Visibility.Visible, converter.Convert(true, null, null, null));
            Assert.AreEqual(Visibility.Collapsed, converter.Convert(false, null, null, null));

            Assert.AreEqual(true, converter.ConvertBack(Visibility.Visible, null, null, null));
            Assert.AreEqual(false, converter.ConvertBack(Visibility.Collapsed, null, null, null));
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(_innerConverter.Convert(true, targetType, parameter, culture));
            }

            var boolValue = (bool)value;

            return(_innerConverter.Convert(!boolValue, targetType, parameter, culture));
        }
Esempio n. 12
0
        public void Convert_Null_Collapsed()
        {
            //arrange
            Visibility expected = Visibility.Collapsed;

            //action
            Visibility actual = (Visibility)Target.Convert((bool?)null, typeof(Visibility), null, null);

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void BooleanToVisibilityConverter_Convert_Get_Visible_If_Value_True()
        {
            // Arrange

            // Act

            var result = (Visibility)_converter.Convert(true, typeof(Visibility), null, CultureInfo.CurrentCulture);

            // Assert

            Assert.AreEqual(result, Visibility.Visible);
        }
        public void Invalid_value()
        {
            var converter = new BooleanToVisibilityConverter();

            Assert.ThrowsException <InvalidOperationException>(() =>
                                                               converter.Convert(1, typeof(Visibility), null, null));

            Assert.ThrowsException <InvalidOperationException>(() =>
                                                               converter.Convert("hello", typeof(Visibility), null, null));

            Assert.ThrowsException <InvalidOperationException>(() =>
                                                               converter.Convert(Visibility.Visible, typeof(Visibility), null, null));
        }
        public void Invalid_target_type()
        {
            var converter = new BooleanToVisibilityConverter();

            Assert.ThrowsException <InvalidOperationException>(() =>
                                                               converter.Convert(true, typeof(string), null, null));

            Assert.ThrowsException <InvalidOperationException>(() =>
                                                               converter.Convert(true, typeof(int), null, null));

            Assert.ThrowsException <InvalidOperationException>(() =>
                                                               converter.Convert(true, typeof(bool), null, null));
        }
        public void ConvertsBoolToVisibility()
        {
            var converter = new BooleanToVisibilityConverter();

            Assert.Equal(
                converter.TrueVisibility,
                converter.Convert(true, null, CultureInfo.CurrentCulture));
            Assert.Equal(
                converter.FalseVisibility,
                converter.Convert(false, null, CultureInfo.CurrentCulture));

            Assert.True(converter.ConvertBack(converter.TrueVisibility, null, CultureInfo.CurrentCulture));
            Assert.False(converter.ConvertBack(converter.FalseVisibility, null, CultureInfo.CurrentCulture));
        }
Esempio n. 17
0
        public void BooleanToVisibilityConverterTest()
        {
            var converter = new BooleanToVisibilityConverter();

            converter.IsInverted = false;

            Assert.AreEqual(Visibility.Visible, converter.Convert(true, typeof(Visibility), null, null));
            Assert.AreEqual(Visibility.Collapsed, converter.Convert(false, typeof(Visibility), null, null));

            converter.IsInverted = true;

            Assert.AreEqual(Visibility.Collapsed, converter.Convert(true, typeof(Visibility), null, null));
            Assert.AreEqual(Visibility.Visible, converter.Convert(false, typeof(Visibility), null, null));
        }
Esempio n. 18
0
        public SearchView()
        {
            InitializeComponent();

            this.WhenActivated((CompositeDisposable disposables) =>
            {
                var visibilityConverter = new BooleanToVisibilityConverter();

                this.OneWayBind(ViewModel, vm => vm.Devices, v => v.DeviceList.ItemsSource)
                .DisposeWith(disposables);

                this.WhenAnyValue(v => v.DeviceList.SelectedItem)
                .Select(x => x as DeviceViewModel)
                .Where(x => x != null)
                .InvokeCommand(this, v => v.ViewModel.OpenDeviceCommand)
                .DisposeWith(disposables);

                this.Bind(ViewModel, vm => vm.SearchUrl, v => v.SearchUrl.Text)
                .DisposeWith(disposables);

                this.OneWayBind(ViewModel,
                                vm => vm.IsSearching,
                                v => v.GoButton.Visibility,
                                x => visibilityConverter.Convert(!x, typeof(Visibility), null, CultureInfo.CurrentCulture))
                .DisposeWith(disposables);

                this.BindCommand(ViewModel, vm => vm.SearchCommand, v => v.GoButton)
                .DisposeWith(disposables);


                this.OneWayBind(ViewModel,
                                vm => vm.IsSearching,
                                v => v.StopButton.Visibility,
                                x => visibilityConverter.Convert(x, typeof(Visibility), null, CultureInfo.CurrentCulture))
                .DisposeWith(disposables);

                this.BindCommand(ViewModel, vm => vm.StopCommand, v => v.StopButton)
                .DisposeWith(disposables);

                this.OneWayBind(ViewModel,
                                vm => vm.IsSearching,
                                v => v.SearchProgress.Visibility,
                                x => visibilityConverter.Convert(x, typeof(Visibility), null, CultureInfo.CurrentCulture))
                .DisposeWith(disposables);

                this.OneWayBind(ViewModel, vm => vm.IsSearching, v => v.FilterPanel.IsEnabled, x => !x)
                .DisposeWith(disposables);
            });
        }
Esempio n. 19
0
        public void verify_method_Convert_returns_correct_value()
        {
            var btvConverter = new BooleanToVisibilityConverter();

            Assert.That(btvConverter.Convert(
                            true, // boolean to convert
                            typeof(Visibility),
                            null, // no parameters
                            System.Globalization.CultureInfo.CurrentCulture).Equals(Visibility.Visible));
            Assert.That(btvConverter.Convert(
                            false, // boolean to convert
                            typeof(Visibility),
                            null,  // no parameters
                            System.Globalization.CultureInfo.CurrentCulture).Equals(Visibility.Collapsed));
        }
        public void ShouldConvertTrueToVisible()
        {
            var converter  = new BooleanToVisibilityConverter();
            var visibility = (Visibility)converter.Convert(true, null, null, null);

            Assert.AreEqual(Visibility.Visible, visibility);
        }
Esempio n. 21
0
        public void ConvertShouldThrowExceptionInvalidValue()
        {
            var    converter = new BooleanToVisibilityConverter(Visibility.Collapsed, Visibility.Visible, Visibility.Visible);
            Action action    = () => converter.Convert(new object(), typeof(object), null, null);

            action.ShouldThrow();
        }
        public void ShouldConvertFalseToCollapsed()
        {
            var converter  = new BooleanToVisibilityConverter();
            var visibility = (Visibility)converter.Convert(false, null, null, null);

            Assert.AreEqual(Visibility.Collapsed, visibility);
        }
        public void convert_automatically_converts_relevant_values_to_booleans()
        {
            var converter = new BooleanToVisibilityConverter();

            Assert.Equal(Visibility.Collapsed, converter.Convert("false", null, null, null));
            Assert.Equal(Visibility.Collapsed, converter.Convert("False", null, null, null));
            Assert.Equal(Visibility.Collapsed, converter.Convert("FALSE", null, null, null));
            Assert.Equal(Visibility.Collapsed, converter.Convert(0, null, null, null));
            Assert.Equal(Visibility.Collapsed, converter.Convert(0d, null, null, null));

            Assert.Equal(Visibility.Visible, converter.Convert("true", null, null, null));
            Assert.Equal(Visibility.Visible, converter.Convert("True", null, null, null));
            Assert.Equal(Visibility.Visible, converter.Convert("TRUE", null, null, null));
            Assert.Equal(Visibility.Visible, converter.Convert(1, null, null, null));
            Assert.Equal(Visibility.Visible, converter.Convert(1d, null, null, null));
        }
        public void when_true_is_passed_then_Visible_is_returned()
        {
            var converter = new BooleanToVisibilityConverter();
            var result = converter.Convert(true, null, null, null);

            Assert.That(result, Is.EqualTo(Visibility.Visible));
        }
Esempio n. 25
0
        public void when_false_is_passed_then_Collapsed_is_returned()
        {
            var converter = new BooleanToVisibilityConverter();
            var result    = converter.Convert(false, null, null, null);

            Assert.That(result, Is.EqualTo(Visibility.Collapsed));
        }
Esempio n. 26
0
        public AIView()
        {
            InitializeComponent();

            this.WhenActivated(d =>
            {
                this.OneWayBind(ViewModel, vm => vm.PlayerState.FirstCard, v => v.xFirstCard.Content).DisposeWith(d);
                this.OneWayBind(ViewModel, vm => vm.PlayerState.SecondCard, v => v.xSecondCard.Content).DisposeWith(d);
                this.OneWayBind(ViewModel, vm => vm.PlayerState.Cash, v => v.xCash.Text, cash => cash.ToString()).DisposeWith(d);
                this.OneWayBind(ViewModel, vm => vm.PlayerState.Name, v => v.xPlayerName.Text);

                this.OneWayBind(ViewModel, vm => vm.PlayerState.IsDealer, v => v.xIsDealer.Visibility, x =>
                {
                    var conv = new BooleanToVisibilityConverter();
                    return((Visibility)conv.Convert(x, typeof(Visibility), null, System.Globalization.CultureInfo.CurrentCulture));
                }).DisposeWith(d);

                this.OneWayBind(ViewModel, vm => vm.PlayerState.IsSmallBlind, v => v.xIsSmallBlind.Visibility, x =>
                {
                    var conv = new BooleanToVisibilityConverter();
                    return((Visibility)conv.Convert(x, typeof(Visibility), null, System.Globalization.CultureInfo.CurrentCulture));
                }).DisposeWith(d);

                this.OneWayBind(ViewModel, vm => vm.PlayerState.IsBigBlind, v => v.xIsBigBlind.Visibility, x =>
                {
                    var conv = new BooleanToVisibilityConverter();
                    return((Visibility)conv.Convert(x, typeof(Visibility), null, System.Globalization.CultureInfo.CurrentCulture));
                }).DisposeWith(d);
            });
        }
        public void when_false_is_passed_then_Collapsed_is_returned()
        {
            var converter = new BooleanToVisibilityConverter();
            var result = converter.Convert(false, null, null, null);

            Assert.That(result, Is.EqualTo(Visibility.Collapsed));
        }
Esempio n. 28
0
        public void when_true_is_passed_then_Visible_is_returned()
        {
            var converter = new BooleanToVisibilityConverter();
            var result    = converter.Convert(true, null, null, null);

            Assert.That(result, Is.EqualTo(Visibility.Visible));
        }
        public void ShouldConvertNullValue()
        {
            var converter = new BooleanToVisibilityConverter();

            var result = converter.Convert(null, null, null, null);

            Assert.IsNull(result);
        }
Esempio n. 30
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var converter = new BooleanToVisibilityConverter();

            return((Visibility)converter.Convert(value, targetType, null, culture) == Visibility.Visible
                ? "tak"
                : "nie");
        }
        public void BooleanToVisibilityConverter_EnsureDefaultForFalseIsCollapsed()
        {
            var converter = new BooleanToVisibilityConverter();

            Visibility visibility = (Visibility)converter.Convert(false, null, null, null);

            Assert.AreEqual(Visibility.Collapsed, visibility);
        }
        public void BooleanToVisibilityConverter_EnsureDefaultForTrueIsVisible()
        {
            var converter = new BooleanToVisibilityConverter();

            Visibility visibility = (Visibility)converter.Convert(true, null, null, null);

            Assert.AreEqual(Visibility.Visible, visibility);
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is bool)
     {
         value = !(bool)value;
     }
     return(BooleanToVisibilityConverter.Convert(value, targetType, parameter, culture));
 }
        public void convert_returns_collapsed_if_value_is_true_and_is_reversed_is_true()
        {
            var converter = new BooleanToVisibilityConverter
            {
                IsReversed = true
            };

            Assert.Equal(Visibility.Collapsed, converter.Convert(true, null, null, null));
        }
        public void convert_returns_visible_if_value_is_false_and_is_reversed_is_true()
        {
            var converter = new BooleanToVisibilityConverter
            {
                IsReversed = true
            };

            Assert.Equal(Visibility.Visible, converter.Convert(false, null, null, null));
        }
        public void convert_returns_hidden_if_value_is_false_and_use_hidden_is_true()
        {
            var converter = new BooleanToVisibilityConverter
            {
                UseHidden = true
            };

            Assert.Equal(Visibility.Hidden, converter.Convert(false, null, null, null));
        }
        public void ConvertsCorrect(
            bool input,
            BooleanToVisibilityConverter.BooleanToVisibilityMapping parameter,
            Visibility expectedResult)
        {
            var converter = new BooleanToVisibilityConverter();
            var result = converter.Convert(input, parameter, CultureInfo.InvariantCulture);

            Assert.Equal(expectedResult, result);
        }
		public void Test ()
		{
			BooleanToVisibilityConverter c = new BooleanToVisibilityConverter ();
			Assert.AreEqual (c.Convert (true, null, null, null), Visibility.Visible, "true");
			Assert.AreEqual (c.Convert (false, null, null, null), Visibility.Collapsed, "false");
			Assert.AreEqual (c.Convert (null, null, null, null), Visibility.Collapsed, "null");
			Assert.AreEqual (c.Convert ((bool?)true, null, null, null), Visibility.Visible, "(bool?)true");
			Assert.AreEqual (c.Convert ((bool?)false, null, null, null), Visibility.Collapsed, "(bool?)false");
			Assert.AreEqual (c.Convert ((bool?)null, null, null, null), Visibility.Collapsed, "(bool?)null");
			Assert.AreEqual (c.Convert (string.Empty, null, null, null), Visibility.Collapsed, "string.Empty");

			Assert.IsTrue ((bool)c.ConvertBack (Visibility.Visible, null, null, null), "Visibility.Visible");
			Assert.IsFalse ((bool)c.ConvertBack (Visibility.Hidden, null, null, null), "Visibility.Hidden");
			Assert.IsFalse ((bool)c.ConvertBack (Visibility.Collapsed, null, null, null), "Visibility.Collapsed");
			Assert.IsFalse ((bool)c.ConvertBack (null, null, null, null), "null");
		}
        public void convert_returns_visible_if_value_is_true()
        {
            var converter = new BooleanToVisibilityConverter();

            Assert.Equal(Visibility.Visible, converter.Convert(true, null, null, null));
        }
        public void convert_returns_collapsed_if_value_is_false_and_use_hidden_is_false()
        {
            var converter = new BooleanToVisibilityConverter();

            Assert.Equal(Visibility.Collapsed, converter.Convert(false, null, null, null));
        }
Esempio n. 41
0
 private static Visibility GetVisibility(bool boolean)
 {
     BooleanToVisibilityConverter converter = new BooleanToVisibilityConverter();
     return (Visibility)converter.Convert(boolean, null, null, null);
 }
        public void convert_automatically_converts_relevant_values_to_booleans()
        {
            var converter = new BooleanToVisibilityConverter();

            Assert.Equal(Visibility.Collapsed, converter.Convert("false", null, null, null));
            Assert.Equal(Visibility.Collapsed, converter.Convert("False", null, null, null));
            Assert.Equal(Visibility.Collapsed, converter.Convert("FALSE", null, null, null));
            Assert.Equal(Visibility.Collapsed, converter.Convert(0, null, null, null));
            Assert.Equal(Visibility.Collapsed, converter.Convert(0d, null, null, null));

            Assert.Equal(Visibility.Visible, converter.Convert("true", null, null, null));
            Assert.Equal(Visibility.Visible, converter.Convert("True", null, null, null));
            Assert.Equal(Visibility.Visible, converter.Convert("TRUE", null, null, null));
            Assert.Equal(Visibility.Visible, converter.Convert(1, null, null, null));
            Assert.Equal(Visibility.Visible, converter.Convert(1d, null, null, null));
        }