public ExistingUpdatableObservableViewModelBuilderOptions(IObservableViewModel viewModel)
 {
     if (viewModel == null)
     {
         throw new ArgumentNullException("viewModel");
     }
     ViewModel = viewModel;
 }
Exemplo n.º 2
0
        public void ToViewModel_ShouldSaveViewModel(
            Task <object> source,
            TestSchedulers scheduler)
        {
            //arrange
            IObservableViewModel viewModel = null;
            var sut = new ObservableViewModelBuilderOptions <object>(model => viewModel = model, ct => source, scheduler);

            //act
            var actual = sut.ToViewModel();

            //assert
            actual.Should().Be(viewModel.As <ObservableViewModel <object> >());
        }
        public static IObservable <TProperty> Changed <TProperty>(this IObservableViewModel vm,
                                                                  Expression <Func <TProperty> > propertyExpression)
        {
            if (!(propertyExpression.Body is MemberExpression member))
            {
                throw new ArgumentException(string.Format(
                                                "Expression '{0}' refers to a method, not a property.",
                                                propertyExpression.ToString()));
            }

            var propInfo = member.Member as PropertyInfo;

            if (propInfo == null)
            {
                throw new ArgumentException(string.Format(
                                                "Expression '{0}' refers to a field, not a property.",
                                                propertyExpression.ToString()));
            }

            return(vm.Changed.Where(c => c.PropertyName == propInfo.Name)
                   .Select(c => propertyExpression.Compile().Invoke()));
        }