コード例 #1
0
        public void OnAttachedTextIsUpdated()
        {
            // Arrange.
            const string Text = "Test Text";

            var numericControl = Mock.Create<RadNumericUpDown>(Behavior.CallOriginal);
            Mock.Arrange(() => numericControl.ContentText).Returns(Text);
            Mock.Arrange(() => numericControl.GetValue(Arg.IsAny<DependencyProperty>())).CallOriginal();
            Mock.Arrange(() => numericControl.SetValue(Arg.IsAny<DependencyProperty>(), Arg.AnyObject)).CallOriginal();

            var behavior = new NumericUpDownTextBehavior();

            // Act.
            behavior.Attach(numericControl);

            // Assert.
            Assert.AreEqual(Text, NumericUpDownTextBehavior.GetText(numericControl));
        }
コード例 #2
0
        public void WhenContentTextChangesTextIsUpdated()
        {
            // Arrange.
            const string Text1 = "Test 1";
            const string Text2 = "Test 2";
            const string Text3 = "Test 3";
            const string Text4 = "Test 4";

            var numericControl = Mock.Create<RadNumericUpDown>(Behavior.CallOriginal);
            var valueListener = Mock.Create<DependencyPropertyChangedListener>(Constructor.Mocked, Behavior.Loose);
            var customUnitListener = Mock.Create<DependencyPropertyChangedListener>(Constructor.Mocked, Behavior.Loose);
            var numberDecimalDigitsListener = Mock.Create<DependencyPropertyChangedListener>(Constructor.Mocked, Behavior.Loose);
            var valueFormatListener = Mock.Create<DependencyPropertyChangedListener>(Constructor.Mocked, Behavior.Loose);
            var eventArgs = Mock.Create<DependencyPropertyValueChangedEventArgs>(Constructor.Mocked, Behavior.Loose);

            Mock.Arrange(() => DependencyPropertyChangedListener.Create(numericControl, "Value")).Returns(valueListener);
            Mock.Arrange(() => DependencyPropertyChangedListener.Create(numericControl, "CustomUnit")).Returns(customUnitListener);
            Mock.Arrange(() => DependencyPropertyChangedListener.Create(numericControl, "NumberDecimalDigits")).Returns(numberDecimalDigitsListener);
            Mock.Arrange(() => DependencyPropertyChangedListener.Create(numericControl, "ValueFormat")).Returns(valueFormatListener);

            var behavior = new NumericUpDownTextBehavior();
            behavior.Attach(numericControl);

            // Act / Assert.
            Mock.Arrange(() => numericControl.ContentText).Returns(Text1);
            Mock.Raise(() => valueListener.ValueChanged += null, eventArgs);
            Assert.AreEqual(Text1, NumericUpDownTextBehavior.GetText(numericControl));

            Mock.Arrange(() => numericControl.ContentText).Returns(Text2);
            Mock.Raise(() => customUnitListener.ValueChanged += null, eventArgs);
            Assert.AreEqual(Text2, NumericUpDownTextBehavior.GetText(numericControl));

            Mock.Arrange(() => numericControl.ContentText).Returns(Text3);
            Mock.Raise(() => numberDecimalDigitsListener.ValueChanged += null, eventArgs);
            Assert.AreEqual(Text3, NumericUpDownTextBehavior.GetText(numericControl));

            Mock.Arrange(() => numericControl.ContentText).Returns(Text4);
            Mock.Raise(() => valueFormatListener.ValueChanged += null, eventArgs);
            Assert.AreEqual(Text4, NumericUpDownTextBehavior.GetText(numericControl));
        }
コード例 #3
0
        public void OnDetachingPropertyListenersAreDetached()
        {
            // Arrange.
            var numericControl = Mock.Create<RadNumericUpDown>(Behavior.CallOriginal);
            var valueListener = Mock.Create<DependencyPropertyChangedListener>(Constructor.Mocked, Behavior.Loose);
            var customUnitListener = Mock.Create<DependencyPropertyChangedListener>(Constructor.Mocked, Behavior.Loose);
            var numberDecimalDigitsListener = Mock.Create<DependencyPropertyChangedListener>(Constructor.Mocked, Behavior.Loose);
            var valueFormatListener = Mock.Create<DependencyPropertyChangedListener>(Constructor.Mocked, Behavior.Loose);

            Mock.Arrange(() => DependencyPropertyChangedListener.Create(numericControl, "Value")).Returns(valueListener);
            Mock.Arrange(() => DependencyPropertyChangedListener.Create(numericControl, "CustomUnit")).Returns(customUnitListener);
            Mock.Arrange(() => DependencyPropertyChangedListener.Create(numericControl, "NumberDecimalDigits")).Returns(numberDecimalDigitsListener);
            Mock.Arrange(() => DependencyPropertyChangedListener.Create(numericControl, "ValueFormat")).Returns(valueFormatListener);

            var behavior = new NumericUpDownTextBehavior();
            behavior.Attach(numericControl);

            Mock.Assert(() => valueListener.Detach(), Occurs.Never());
            Mock.Assert(() => customUnitListener.Detach(), Occurs.Never());
            Mock.Assert(() => numberDecimalDigitsListener.Detach(), Occurs.Never());
            Mock.Assert(() => valueFormatListener.Detach(), Occurs.Never());

            // Act.
            behavior.Detach();

            // Assert.
            Mock.Assert(() => valueListener.Detach(), Occurs.Once());
            Mock.Assert(() => customUnitListener.Detach(), Occurs.Once());
            Mock.Assert(() => numberDecimalDigitsListener.Detach(), Occurs.Once());
            Mock.Assert(() => valueFormatListener.Detach(), Occurs.Once());
        }