public void Subscribe_ShouldCallOnNextWhenSettingProperty( string value, Mock<IObserver<string>> observer, ISchedulers schedulers ) { //arrange var sut = new ObservableProperty<string>(schedulers); sut.Subscribe(observer.Object); //act sut.Value = value; //assert observer.Verify(o => o.OnNext(value)); }
public PropertyProvider(ViewModelBase viewModel, ISchedulers schedulers) { _viewModel = viewModel; _schedulers = schedulers; _viewModel.ShouldDispose(_disposables); }
public void TestValueProperty( WritablePropertyAssertion assertion, ISchedulers schedulers) { var sut = new ObservableProperty<string>(schedulers); assertion.VerifyProperty(() => sut.Value); }
public UpdatableObservableViewModelBuilderOptions(Action <IObservableViewModel> saveViewModel, Func <CancellationToken, Task <TCollection> > source, IScheduler actionSelectionScheduler, IScheduler dispatcherScheduler, ISchedulers schedulers) { if (saveViewModel == null) { throw new ArgumentNullException("saveViewModel"); } if (source == null) { throw new ArgumentNullException("source"); } if (actionSelectionScheduler == null) { throw new ArgumentNullException("actionSelectionScheduler"); } if (dispatcherScheduler == null) { throw new ArgumentNullException("dispatcherScheduler"); } if (schedulers == null) { throw new ArgumentNullException("schedulers"); } _saveViewModel = saveViewModel; _dispatcherScheduler = dispatcherScheduler; _schedulers = schedulers; _actionSelectionScheduler = actionSelectionScheduler; Source = source; }
public CompareOptionsViewModel(ISchedulers schedulers, CompareOptions compareOptions) { ContextLinesInput = new IntegerInputViewModel(schedulers, compareOptions.ContextLines, 0) .DisposeWith(_disposable); InterhunkLinesInput = new IntegerInputViewModel(schedulers, compareOptions.InterhunkLines, 0) .DisposeWith(_disposable); DiffAlgorithm = new EnumViewModel <DiffAlgorithm>(compareOptions.Algorithm) .DisposeWith(_disposable); IndentHeuristic = new ViewSubject <bool>(compareOptions.IndentHeuristic) .DisposeWith(_disposable); SimilarityOptions = new SimilarityOptionsViewModel(schedulers, compareOptions.Similarity) .DisposeWith(_disposable); CompareOptionsObservable = Observable .CombineLatest(ContextLinesInput.Value, InterhunkLinesInput.Value, DiffAlgorithm.Value, IndentHeuristic, SimilarityOptions.SimilarityObservable, (contextLines, interhunkLines, algorithm, indentHeuristic, similarityOptions) => new CompareOptions() { ContextLines = contextLines, InterhunkLines = interhunkLines, Similarity = similarityOptions, IncludeUnmodified = false, Algorithm = algorithm, IndentHeuristic = indentHeuristic, }); }
public void Get_ShouldCallAccept( Mock <IObservableViewModelVisitor> visitor, IBindable parent, ISchedulers schedulers, Mock <IObservableViewModelBuilder> ovmBuilder, Mock <IObservableViewModel> ovm ) { //arrange Action <IObservableViewModel> action = null; var sut = new ObservableViewModelBuilderProvider(() => schedulers, (a, scheduler, arg3) => { action = a; return(ovmBuilder.Object); }); sut.AddVisitor(visitor.Object); //act sut.Get("test"); action(ovm.Object); //assert ovm.Verify(o => o.Accept(visitor.Object)); }
public DiffViewModel( ISchedulers schedulers, IObservable <DiffViewModelInput> input) { TreeDiff = new ViewSubject <Variant <List <TreeEntryChanges>, Unexpected> >(new Unexpected(NoCommitSelectedMessage)) .DisposeWith(_disposables); SelectionInfo = new ViewSubject <TSelectionInfo>( new TSelectionInfo(NoCommitSelectedMessage)) .DisposeWith(_disposables); IndexSelected = new ViewSubject <bool>(false) .DisposeWith(_disposables); var focusChangedCommand = ReactiveCommand .Create <bool, bool>(indexSelected => indexSelected, schedulers.Dispatcher) .DisposeWith(_disposables); FocusChangedCommand = focusChangedCommand; focusChangedCommand .Merge(input .Where(d => d.OldCommit is null) .Where(d => d.NewCommit is null || !d.NewCommit.Is <DiffTargets>()) .Select(_ => false)) .Subscribe(IndexSelected) .DisposeWith(_disposables);
public ObservableMvvmCommand( Func <TCommand, IObservable <TObservable> > factory, ISchedulers schedulers, IScheduler executionScheduler, string name, ICanExecuteStrategy <TCommand> canExecuteStrategy, Func <IObserver <TObservable> > doObserver = null, IScheduler doScheduler = null, Func <CancellationToken, Exception, Task> errorTask = null) : base(schedulers, name, canExecuteStrategy) { if (executionScheduler == null) { throw new ArgumentNullException("executionScheduler"); } Factory = factory; if (errorTask == null) { _hasDefaultErrorTask = true; errorTask = (ct, ex) => Task.FromResult(true); } if (doObserver == null) { doObserver = () => Observer.Create <TObservable>(_ => { }); } DoObserver = doObserver; DoScheduler = doScheduler ?? schedulers.Immediate; ErrorTask = errorTask; _executionScheduler = executionScheduler; _executionDisposable = new SerialDisposable().DisposeWith(Disposables); }
public Bindable(ISchedulers schedulers) { if (schedulers == null) { throw new ArgumentNullException("schedulers"); } _schedulers = schedulers; }
public void TestValueProperty( WritablePropertyAssertion assertion, ISchedulers schedulers) { var sut = new ObservableProperty <string>(schedulers); assertion.VerifyProperty(() => sut.Value); }
public Validable(ISchedulers scheduler) : base(scheduler) { _scheduler = scheduler; var v = new PropertyValidator(); Validator = CreateRuleDefiner(v); }
public Command(Action <T> action, ISchedulers schedulers, string name, ICanExecuteStrategy <T> canExecuteStrategy) : base(schedulers, name, canExecuteStrategy) { if (action == null) { throw new ArgumentNullException("action"); } Action = action; }
public Validable(IValidator validator, ISchedulers scheduler) : base(scheduler) { if (validator == null) { throw new ArgumentNullException(nameof(validator), $"{nameof(validator)} is null."); } _scheduler = scheduler; Validator = CreateRuleDefiner(validator); }
public void OnNext_ShouldSetValue( string value, ISchedulers schedulers) { var sut = new ObservableProperty <string>(schedulers); //act sut.OnNext(value); //assert sut.Value.Should().Be(value); }
public void Sut_TestDefaultValues( ObservableMvvmCommand<object, object> sut, ISchedulers schedulers) { //arrange //act //assert sut.DoScheduler.Should().NotBeNull(); sut.DoScheduler.Should().NotBeNull(); sut.CanExecuteStrategy.Should().NotBeNull(); }
public void OnError_ShouldSetError( Exception value, ISchedulers schedulers) { var sut = new ObservableProperty <string>(schedulers); //act sut.OnError(value); //assert sut.Error.Should().Be(value); }
public void OnError_ShouldSetError( Exception value, ISchedulers schedulers) { var sut = new ObservableProperty<string>(schedulers); //act sut.OnError(value); //assert sut.Error.Should().Be(value); }
public void OnNext_ShouldSetValue( string value, ISchedulers schedulers) { var sut = new ObservableProperty<string>(schedulers); //act sut.OnNext(value); //assert sut.Value.Should().Be(value); }
public void Sut_TestDefaultValues( ObservableMvvmCommand <object, object> sut, ISchedulers schedulers) { //arrange //act //assert sut.DoScheduler.Should().NotBeNull(); sut.DoScheduler.Should().NotBeNull(); sut.CanExecuteStrategy.Should().NotBeNull(); }
public ObservableViewModel( Func <CancellationToken, Task <T> > sourceFactory, Func <T, bool> emptyPredicate, IObservable <Unit> refreshOn, TimeSpan timeout, CompositeDisposable subscriptions, ISchedulers schedulers) { if (sourceFactory == null) { throw new ArgumentNullException("sourceFactory"); } if (emptyPredicate == null) { throw new ArgumentNullException("emptyPredicate"); } if (refreshOn == null) { throw new ArgumentNullException("refreshOn"); } if (subscriptions == null) { throw new ArgumentNullException("subscriptions"); } if (schedulers == null) { throw new ArgumentNullException("schedulers"); } _subscriptions = subscriptions; _schedulers = schedulers; Source = sourceFactory; EmptyPredicate = emptyPredicate; RefreshOn = refreshOn; TimeoutDelay = timeout; RefreshOn.SelectMany(async _ => { await RefreshAsync(); return(Unit.Default); }) .Subscribe(_ => { }, e => { }, () => { }) .DisposeWith(_subscriptions); //intialization _notificationsObservable = _notificationsSubject.Replay(1, ImmediateScheduler.Instance); _notificationDisposable = _notificationsObservable.Connect(); _notificationsSubject.OnNext(new ObservableViewModelNotification() { Status = ObservableViewModelStatus.Initialized, Value = null }); _currentExecution = new SerialDisposable(); }
public void Get_UsingDefaultBuilderFactory_ShouldReturnCorrectValue( string name, ISchedulers schedulers) { //arrange var sut = new CommandBuilderProvider(schedulers); //act var actual = sut.Get(name); //assert actual.Should().NotBeNull().And.BeOfType <CommandBuilder>(); }
public CommandBuilderProvider( ISchedulers schedulers, Func<Action<ICommand>, ISchedulers, string, ICommandBuilder> builderFactory = null) { if (schedulers == null) throw new ArgumentNullException("schedulers"); if (builderFactory == null) { builderFactory = (action, schedulers1, name) => new CommandBuilder(action, schedulers1, name); } _schedulers = schedulers; _builderFactory = builderFactory; _visitors = new List<IMvvmCommandVisitor>(); }
public void Get_UsingDefaultBuilderFactory_ShouldReturnCorrectValue( string name, ISchedulers schedulers) { //arrange var sut = new CommandBuilderProvider(schedulers); //act var actual = sut.Get(name); //assert actual.Should().NotBeNull().And.BeOfType<CommandBuilder>(); }
public void Subscribe_WithDefaultValue_ShouldNotCallOnNext( string value, Mock <IObserver <string> > observer, ISchedulers schedulers) { //arrange var sut = new ObservableProperty <string>(schedulers); sut.Subscribe(observer.Object); //assert observer.Verify(o => o.OnNext(It.IsAny <string>()), Times.Never()); }
public void Get_UsingBuilderFactory_ShouldReturnCorrectValue( string name, ISchedulers schedulers, ICommandBuilder expected) { //arrange var sut = new CommandBuilderProvider(schedulers, (action, schedulers1, arg3) => expected); //act var actual = sut.Get(name); //assert actual.Should().Be(expected); }
public void ToCommand_ShouldCallAction( IObservable<object> value, ISchedulers schedulers) { //arrange bool actionCalled = false; var sut = new ObservableCommandBuilderOptions<string, object>(s => value, command => actionCalled = true, schedulers, "name"); //act sut.ToCommand(); //assert actionCalled.Should().BeTrue(); }
public void ToCommand_ShouldReturnCorrectValue( IObservable<object> value, ISchedulers schedulers) { //arrange var sut = new ObservableCommandBuilderOptions<string, object>(s => value, command => { }, schedulers, "name"); //act var actual = sut.ToCommand(); //assert actual.Should().BeOfType<ObservableMvvmCommand<string, object>>(); ((ObservableMvvmCommand<string, object>)actual).Factory("").Should().Be(value); }
public void ToCommand_ShouldReturnCorrectValue( IObservable <object> value, ISchedulers schedulers) { //arrange var sut = new ObservableCommandBuilderOptions <string, object>(s => value, command => { }, schedulers, "name"); //act var actual = sut.ToCommand(); //assert actual.Should().BeOfType <ObservableMvvmCommand <string, object> >(); ((ObservableMvvmCommand <string, object>)actual).Factory("").Should().Be(value); }
public void ToCommand_ShouldCallAction( IObservable <object> value, ISchedulers schedulers) { //arrange bool actionCalled = false; var sut = new ObservableCommandBuilderOptions <string, object>(s => value, command => actionCalled = true, schedulers, "name"); //act sut.ToCommand(); //assert actionCalled.Should().BeTrue(); }
public void Get_UsingBuilderFactory_ShouldReturnCorrectValue( string name, ISchedulers schedulers, ICommandBuilder expected) { //arrange var sut = new CommandBuilderProvider(schedulers, (action, schedulers1, arg3) => expected); //act var actual = sut.Get(name); //assert actual.Should().Be(expected); }
public void Execute_ShouldExecuteAction( object arg, ISchedulers schedulers, Mock<ICanExecuteStrategy<object>> canExecute) { //arrange object actual = null; var sut = new Command<object>(o => actual = o, schedulers, "name", canExecute.Object); //act sut.Execute(arg); //assert actual.Should().Be(arg); }
public void CanExecute_ShouldReturnCorrectValue( bool canExecute, object arg, ISchedulers schedulers, Mock<ICanExecuteStrategy<object>> canExecuteStrat) { //arrange canExecuteStrat.Setup(c => c.CanExecute(It.IsAny<object>())).Returns(canExecute); var sut = new Command<object>(o => { }, schedulers, "name", canExecuteStrat.Object); //act var actual = sut.CanExecute(arg); //assert actual.Should().Be(canExecute); }
public async Task Sut_WhenAwaited_ShouldReturnCorrectValue( string expected, ISchedulers schedulers) { //arrange var sut = new ObservableProperty <string>(schedulers); sut.Value = expected; //act var actual = await sut; //assert actual.Should().Be(expected); }
public void CanExecute_ShouldReturnCorrectValue( bool canExecute, object arg, ISchedulers schedulers, Mock <ICanExecuteStrategy <object> > canExecuteStrat) { //arrange canExecuteStrat.Setup(c => c.CanExecute(It.IsAny <object>())).Returns(canExecute); var sut = new Command <object>(o => { }, schedulers, "name", canExecuteStrat.Object); //act var actual = sut.CanExecute(arg); //assert actual.Should().Be(canExecute); }
public void Execute_ShouldExecuteAction( object arg, ISchedulers schedulers, Mock <ICanExecuteStrategy <object> > canExecute) { //arrange object actual = null; var sut = new Command <object>(o => actual = o, schedulers, "name", canExecute.Object); //act sut.Execute(arg); //assert actual.Should().Be(arg); }
public CommandBuilderProvider( ISchedulers schedulers, Func <Action <ICommand>, ISchedulers, string, ICommandBuilder> builderFactory = null) { if (schedulers == null) { throw new ArgumentNullException("schedulers"); } if (builderFactory == null) { builderFactory = (action, schedulers1, name) => new CommandBuilder(action, schedulers1, name); } _schedulers = schedulers; _builderFactory = builderFactory; _visitors = new List <IMvvmCommandVisitor>(); }
public void CanExecute_ShouldBeCalledWithArg( object arg, ISchedulers schedulers, Mock<ICanExecuteStrategy<object>> canExecuteStrat) { //arrange object actual = null; canExecuteStrat.Setup(c => c.CanExecute(It.IsAny<object>())).Returns(true); var sut = new Command<object>(o => { }, schedulers, "name", canExecuteStrat.Object); //act sut.CanExecute(arg); //assert canExecuteStrat.Verify(c => c.CanExecute(arg)); }
public BaseReference() { _businessAccess = new BusinessAccessLayer.GetListValues(); _businessUser = new BusinessAccessLayer.AdminUserBAL(); _businessCountry = new BusinessAccessLayer.Admin.Country(); _businessMasterState = new BusinessAccessLayer.Admin.MasterState(); _businessMasterCity = new BusinessAccessLayer.Admin.MasterCity(); _businessMasterCategory = new BusinessAccessLayer.Admin.MasterCategory(); _businessAttractions = new BusinessAccessLayer.Admin.Attractions(); _businessAttractionsActiveStatus = new BusinessAccessLayer.Admin.AttractionsActiveStatus(); _businessMasterWeek = new BusinessAccessLayer.Admin.MasterWeek(); _businessAttractionTravelTimeDistance = new BusinessAccessLayer.Admin.AttractionTravelTimeDistance(); _businessMissingDistanceAttractionsRecords = new BusinessAccessLayer.Admin.BalMissingDistanceAttractionsRecords(); _businessSchedulers = new BusinessAccessLayer.Scheduler.BALScheduler(); _businessUserBAL = new BusinessAccessLayer.Users.UsersBAL(); }
protected CommandBase(ISchedulers schedulers, string name, ICanExecuteStrategy <T> canExecuteStrategy) { if (canExecuteStrategy == null) { throw new ArgumentNullException("canExecuteStrategy"); } if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } Name = name; _canExecuteStrategy = canExecuteStrategy; _disposable = _canExecuteStrategy.CanExecuteChanged .ObserveOn(schedulers.Dispatcher) .Subscribe(b => RaiseCanExecute()); }
public IntegerInputViewModel(ISchedulers schedulers, int value, int min = int.MinValue, int max = int.MaxValue) { if (value > max || value < min) { throw new ArgumentException($"{nameof(value)} out of bounds: {value}.", nameof(value)); } Text = new ViewSubject <string>(value.ToString()) .DisposeWith(_disposable); Value = Text .Select(text => int.TryParse(text, out int res) ? (int?)res : null) .SkipNull(); Valid = new ViewSubject <bool>(false) .DisposeWith(_disposable); Text .Select(text => int.TryParse(text, out var _)) .Subscribe(Valid) .DisposeWith(_disposable); var increase = ReactiveCommand.Create <object, object>( canExecute: Value .Select(newVal => newVal < max), execute: (param) => param, scheduler: schedulers.Dispatcher) .DisposeWith(_disposable); Increase = increase; increase .WithLatestFrom(Value, (_, newVal) => (newVal + 1).ToString()) .Subscribe(Text) .DisposeWith(_disposable); var decrease = ReactiveCommand.Create <object, object>( canExecute: Value .Select(newVal => newVal > min), execute: (param) => param, scheduler: schedulers.Dispatcher) .DisposeWith(_disposable); Decrease = decrease; decrease .WithLatestFrom(Value, (_, newVal) => (newVal - 1).ToString()) .Subscribe(Text) .DisposeWith(_disposable); }
public void Subscribe_ShouldCallOnNextWhenSettingProperty( string value, Mock <IObserver <string> > observer, ISchedulers schedulers ) { //arrange var sut = new ObservableProperty <string>(schedulers); sut.Subscribe(observer.Object); //act sut.Value = value; //assert observer.Verify(o => o.OnNext(value)); }
public void CanExecute_ShouldBeCalledWithArg( object arg, ISchedulers schedulers, Mock <ICanExecuteStrategy <object> > canExecuteStrat) { //arrange object actual = null; canExecuteStrat.Setup(c => c.CanExecute(It.IsAny <object>())).Returns(true); var sut = new Command <object>(o => { }, schedulers, "name", canExecuteStrat.Object); //act sut.CanExecute(arg); //assert canExecuteStrat.Verify(c => c.CanExecute(arg)); }
public SimilarityOptionsViewModel(ISchedulers schedulers, SimilarityOptions similarityOptions) { RenameDetectionMode = new EnumViewModel <RenameDetectionMode>(similarityOptions.RenameDetectionMode) .DisposeWith(_disposable); BreakRewriteThresholdInput = new IntegerInputViewModel(schedulers, similarityOptions.BreakRewriteThreshold) .DisposeWith(_disposable); CopyThresholdInput = new IntegerInputViewModel(schedulers, similarityOptions.CopyThreshold) .DisposeWith(_disposable); RenameFromRewriteThresholdInput = new IntegerInputViewModel(schedulers, similarityOptions.RenameFromRewriteThreshold) .DisposeWith(_disposable); RenameLimitInput = new IntegerInputViewModel(schedulers, similarityOptions.RenameLimit) .DisposeWith(_disposable); RenameThresholdInput = new IntegerInputViewModel(schedulers, similarityOptions.RenameThreshold) .DisposeWith(_disposable); WhitespaceMode = new EnumViewModel <WhitespaceMode>(similarityOptions.WhitespaceMode) .DisposeWith(_disposable); SimilarityObservable = Observable .CombineLatest( RenameDetectionMode.Value, BreakRewriteThresholdInput.Value, CopyThresholdInput.Value, RenameFromRewriteThresholdInput.Value, RenameLimitInput.Value, RenameThresholdInput.Value, WhitespaceMode.Value, ( renameDetectionMode, breakRewriteThreshold, copyThreshold, renameFromRewirteThreshold, renameLimit, renameThreshold, whitespaceMode) => new SimilarityOptions() { RenameDetectionMode = renameDetectionMode, BreakRewriteThreshold = breakRewriteThreshold, CopyThreshold = copyThreshold, RenameFromRewriteThreshold = renameFromRewirteThreshold, RenameLimit = renameLimit, RenameThreshold = renameThreshold, WhitespaceMode = whitespaceMode, }); }
public void Get_ShouldCallAccept( string name, ISchedulers schedulers, Mock<ICommandBuilder> commandBuilder, Mock<IMvvmCommand> command, IMvvmCommandVisitor visitor) { //arrange Action<ICommand> action = null; var sut = new CommandBuilderProvider(schedulers, (action1, schedulers1, n) => { action = action1; return commandBuilder.Object; }); sut.AddVisitor(visitor); //act sut.Get(""); action(command.As<ICommand>().Object); //assert command.Verify(c => c.Accept(visitor)); }
public ViewModelServices( IRuleProvider ruleProvider, IObservableRegistrationService observableRegistration, IValidator validator, ISchedulers schedulers, INavigationService navigationService, IRequestNavigation requestNavigation, IAsyncCommandBus commandBus, IAsyncQueryBus queryBus, ICommandEvents commandEvents, ICommandStateEvents commandStateEvents, IQueryStateEvents queryStateEvents) { if (ruleProvider == null) throw new ArgumentNullException("ruleProvider"); if (observableRegistration == null) throw new ArgumentNullException("observableRegistration"); if (validator == null) throw new ArgumentNullException("validator"); if (schedulers == null) throw new ArgumentNullException("schedulers"); if (navigationService == null) throw new ArgumentNullException("navigationService"); if (requestNavigation == null) throw new ArgumentNullException("requestNavigation"); if (commandBus == null) throw new ArgumentNullException("commandBus"); if (queryBus == null) throw new ArgumentNullException("queryBus"); if (commandEvents == null) throw new ArgumentNullException("commandEvents"); if (commandStateEvents == null) throw new ArgumentNullException("commandStateEvents"); if (queryStateEvents == null) throw new ArgumentNullException("queryStateEvents"); Schedulers = schedulers; Validator = validator; ObservableRegistration = observableRegistration; RuleProvider = ruleProvider; CommandStateEvents = commandStateEvents; QueryStateEvents = queryStateEvents; CommandEvents = commandEvents; QueryBus = queryBus; CommandBus = commandBus; RequestNavigation = requestNavigation; NavigationService = navigationService; }
public void Get_ShouldCallAccept( Mock<IObservableViewModelVisitor> visitor, IBindable parent, ISchedulers schedulers, Mock<IObservableViewModelBuilder> ovmBuilder, Mock<IObservableViewModel> ovm ) { //arrange Action<IObservableViewModel> action = null; var sut = new ObservableViewModelBuilderProvider(() => schedulers, (a, scheduler, arg3) => { action = a; return ovmBuilder.Object; }); sut.AddVisitor(visitor.Object); //act sut.Get("test"); action(ovm.Object); //assert ovm.Verify(o => o.Accept(visitor.Object)); }
public async Task Sut_WhenAwaited_ShouldReturnCorrectValue( string expected, ISchedulers schedulers) { //arrange var sut = new ObservableProperty<string>(schedulers); sut.Value = expected; //act var actual = await sut; //assert actual.Should().Be(expected); }
public SampleBindable(ISchedulers schedulers) : base(schedulers) { }
public void Subscribe_WithDefaultValue_ShouldNotCallOnNext( string value, Mock<IObserver<string>> observer, ISchedulers schedulers) { //arrange var sut = new ObservableProperty<string>(schedulers); sut.Subscribe(observer.Object); //assert observer.Verify(o => o.OnNext(It.IsAny<string>()), Times.Never()); }