Пример #1
0
        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 DecreaseCommand()
        {
            int value = 100;
            var vm    = new IntegerInputViewModel(new TestSchedulers(), 2, 0, 102);

            using var _ = vm.Value
                          .Subscribe(v => value = v);
            Assert.AreEqual(2, value);
            Assert.IsTrue(vm.Decrease.CanExecute(null));
            vm.Decrease.Execute(null);
            Assert.AreEqual(1, value);
            Assert.IsTrue(vm.Decrease.CanExecute(null));
            vm.Decrease.Execute(null);
            Assert.AreEqual(0, value);
            Assert.IsFalse(vm.Decrease.CanExecute(null));
        }
        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 InvalidInput()
        {
            int  value = 100;
            bool?valid = null;
            var  vm    = new IntegerInputViewModel(new TestSchedulers(), 50, 0, 100);

            using var _ = vm.Value
                          .Subscribe(v => value = v);
            using var _1 = vm.Valid
                           .Subscribe(v => valid = v);
            Assert.AreEqual(50, value);
            vm.Text.OnNext("rat");
            Assert.AreEqual(50, value);
            Assert.IsFalse(valid ?? true);
            Assert.IsTrue(vm.Increase.CanExecute(null));
            vm.Increase.Execute(null);
            Assert.AreEqual(51, value);
            Assert.AreEqual("51", vm.Text.Value);
            Assert.IsTrue(valid ?? false);
        }