Example #1
0
        /// <summary>
        /// Raise property changed.
        /// </summary>
        /// <param name="expression">
        /// The expression, which contains property.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="expression"/> is null.
        /// </exception>
        protected void RaisePropertyChanged(Expression <Func <object> > expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            this.RaisePropertyChanged(PropertyNameExtractor.GetPropertyName(expression));
        }
Example #2
0
        public void ShouldCreateIndexWithFullPropertyName()
        {
            PropertyNameExtractor.GetPropertyName <Home, object>(x => x.Kitchen.Knives).Should()
            .Be("Kitchen.Knives");

            PropertyNameExtractor.GetPropertyName <Home, object>(x => x.Kitchen.SomeNumber).Should()
            .Be("Kitchen.SomeNumber");

            PropertyNameExtractor.GetPropertyName <Home, object>(x => x.Kitchen).Should()
            .Be("Kitchen");
        }
        ///<exception cref="ArgumentException"></exception>
        public static DependencyPropertyKey RegisterReadOnly <TOwner, TProperty>(
            Expression <Func <TOwner, TProperty> > propertyExpression,
            PropertyMetadata propertyMetadata           = null,
            ValidateValueCallback validateValueCallback = null)
        {
            var name        = PropertyNameExtractor.Extract(propertyExpression);
            var propertyKey = DependencyProperty.RegisterReadOnly(
                name, typeof(TProperty), typeof(TOwner), propertyMetadata, validateValueCallback);

            return(propertyKey);
        }
Example #4
0
        public static AndConstraint <TTestable> ShouldHaveProperty <TTestable, TProperty>(this TTestable testable, Expression <Func <TTestable, TProperty> > propertySelector, TProperty expectedValue)
        {
            var memberName  = PropertyNameExtractor.GetPropertyName(propertySelector);
            var property    = testable.GetType().GetProperty(memberName);
            var actualValue = property.GetValue(testable);

            Execute.Assertion
            .ForCondition(actualValue.Equals(expectedValue))
            .FailWith($"Expected the property {memberName} to have value {expectedValue} but found {actualValue}");

            return(new AndConstraint <TTestable>(testable));
        }
Example #5
0
        /// <summary>
        /// Unsubscribe for property changed notification for special field.
        /// </summary>
        /// <param name="expression">
        /// The expression.
        /// </param>
        /// <param name="action">
        /// The action.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="expression"/> or <paramref name="action"/> is null.
        /// </exception>
        public void Unsubscribe(
            Expression <Func <object> > expression,
            EventHandler <PropertyChangedEventArgs> action)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            this.Unsubscribe(PropertyNameExtractor.GetPropertyName(expression), action);
        }
Example #6
0
        public void PropertyChanged_SubscribeOnPropertyChange_MethodNotified()
        {
            // Arrange
            this.bindingModel.PropertyChanged += this.subscriber.Object.SubscribeMethod;

            // Act
            this.bindingModel.Property1 = 10;

            // Assert
            this.subscriber.Verify(
                x =>
                x.SubscribeMethod(
                    this.bindingModel,
                    It.Is <PropertyChangedEventArgs>(e => e.PropertyName == PropertyNameExtractor.GetPropertyName(() => this.bindingModel.Property1))),
                Times.Once());
        }
Example #7
0
        public void Unsubscribe_UnsubscribeOnPropertyChange_MethodIsNotNotified()
        {
            // Arrange
            this.bindingModel.Subscribe(() => this.bindingModel.Property1, this.subscriber.Object.SubscribeMethod);
            this.bindingModel.Unsubscribe(() => this.bindingModel.Property1, this.subscriber.Object.SubscribeMethod);

            // Act
            this.bindingModel.Property1 = 10;

            // Assert
            this.subscriber.Verify(
                x =>
                x.SubscribeMethod(
                    this.bindingModel,
                    It.Is <PropertyChangedEventArgs>(e => e.PropertyName == PropertyNameExtractor.GetPropertyName(() => this.bindingModel.Property1))),
                Times.Never());
        }
Example #8
0
        public void ClearPropertyChangedSubscriptions_SubscriptionByEvent_MethodIsNotNotified()
        {
            // Arrange
            this.bindingModel.PropertyChanged += this.subscriber.Object.SubscribeMethod;
            this.bindingModel.ClearPropertyChangedSubscriptions();

            // Act
            this.bindingModel.Property1 = 10;

            // Assert
            this.subscriber.Verify(
                x =>
                x.SubscribeMethod(
                    this.bindingModel,
                    It.Is <PropertyChangedEventArgs>(e => e.PropertyName == PropertyNameExtractor.GetPropertyName(() => this.bindingModel.Property1))),
                Times.Never());
        }
Example #9
0
        private void SetContentRegion(object content)
        {
            if (this.currentView != null)
            {
                this.currentView.GetPresenter <BindingModelBase>().Unsubscribe("IsDataLoading", this.OnIsDataLoadingChanged);

                try
                {
                    this.currentView.GetPresenter <BindingModelBase>().DisposeIfDisposable();
                }
                catch (Exception exp)
                {
                    this.logger.Error(exp, "Exception while tried to dispose presenter for curren view.");
                }

                try
                {
                    this.currentView.DisposeIfDisposable();
                }
                catch (Exception exp)
                {
                    this.logger.Error(exp, "Exception while tried to dispose current view.");
                }

                this.currentView = null;
            }

            this.ClearViewCommands();
            this.ClearContextCommands();

            this.ContentControl.Content = null;
            this.TitleTextBox.ClearValue(TextBlock.TextProperty);
            this.SubtitleTextBox.ClearValue(TextBlock.TextProperty);
            this.TitleGrid.ClearValue(UIElement.VisibilityProperty);
            this.StoreLogoImage.ClearValue(UIElement.VisibilityProperty);

            this.currentView = content as IView;

            var pageView = this.currentView as IPageView;

            if (pageView != null)
            {
                this.TitleTextBox.SetBinding(
                    TextBlock.TextProperty,
                    new Binding()
                {
                    Source = this.currentView,
                    Mode   = BindingMode.OneWay,
                    Path   = new PropertyPath(PropertyNameExtractor.GetPropertyName(() => pageView.Title))
                });

                this.SubtitleTextBox.SetBinding(
                    TextBlock.TextProperty,
                    new Binding()
                {
                    Source = this.currentView,
                    Mode   = BindingMode.OneWay,
                    Path   = new PropertyPath(PropertyNameExtractor.GetPropertyName(() => pageView.Subtitle))
                });

                this.TitleGrid.SetBinding(
                    UIElement.VisibilityProperty,
                    new Binding()
                {
                    Source    = this.currentView,
                    Mode      = BindingMode.OneWay,
                    Path      = new PropertyPath(PropertyNameExtractor.GetPropertyName(() => pageView.IsTitleVisible)),
                    Converter = (IValueConverter)Application.Current.Resources["BooleanToVisibilityConverter"]
                });

                this.StoreLogoImage.SetBinding(
                    UIElement.VisibilityProperty,
                    new Binding()
                {
                    Source    = this.currentView,
                    Mode      = BindingMode.OneWay,
                    Path      = new PropertyPath(PropertyNameExtractor.GetPropertyName(() => pageView.IsStoreLogoVisible)),
                    Converter = (IValueConverter)Application.Current.Resources["BooleanToVisibilityConverter"]
                });
            }

            var dataPageView = this.currentView as IPageView;

            if (dataPageView != null)
            {
                this.ProgressRing.IsActive  = true;
                this.ContentControl.Opacity = 0;
                this.currentView.GetPresenter <BindingModelBase>().Subscribe("IsDataLoading", this.OnIsDataLoadingChanged);
            }

            this.ContentControl.Content = this.currentView;
        }
 public MyClass()
 {
     this.nameOf_MyProperty = PropertyNameExtractor.ExposeProperty(() => this.MyProperty);
 }