Exemplo n.º 1
0
        public void CustomComparerTest()
        {
            var items = new List <string> {
                "aaa", "AAA", "abb", "aaaa"
            };

            items.Sort(OrderedComparer <string> .OrderBy(x => x, StringComparer.Ordinal));
            Assert.True(items.SequenceEqual(new[] { "AAA", "aaa", "aaaa", "abb" }));

            items.Sort(OrderedComparer <string> .OrderByDescending(x => x.Length).ThenBy(x => x, StringComparer.Ordinal));
            Assert.True(items.SequenceEqual(new[] { "aaaa", "AAA", "aaa", "abb" }));

            items.Sort(OrderedComparer <string> .OrderBy(x => x.Length).ThenBy(x => x, StringComparer.Ordinal));
            Assert.True(items.SequenceEqual(new[] { "AAA", "aaa", "abb", "aaaa" }));

            items.Sort(OrderedComparer <string> .OrderBy(x => x.Length).ThenBy(x => x, StringComparer.OrdinalIgnoreCase));
            Assert.True(items.SequenceEqual(new[] { "AAA", "AAA", "abb", "aaaa" }, StringComparer.OrdinalIgnoreCase));
        }
        public void SmokeTest()
        {
            var adam = new Employee {
                Name = "Adam", Age = 50, Salary = 125
            };
            var alice = new Employee {
                Name = "Alice", Age = 25, Salary = 100
            };
            var bob = new Employee {
                Name = "Bob", Age = 30, Salary = 75
            };
            var carol = new Employee {
                Name = "Carol", Age = 35, Salary = 100
            };
            var xavier = new Employee {
                Name = "Xavier", Age = 35, Salary = 100
            };

            var employees = new List <Employee> {
                adam, alice, bob, carol, xavier
            };

            employees.Sort(OrderedComparer <Employee> .OrderBy(x => x.Name));
            Assert.True(employees.SequenceEqual(new[] { adam, alice, bob, carol, xavier }));

            employees.Sort(OrderedComparer <Employee>
                           .OrderByDescending(x => x.Age)
                           .ThenBy(x => x.Name)
                           );
            Assert.True(employees.SequenceEqual(new[] { adam, carol, xavier, bob, alice }));

            employees.Sort(OrderedComparer <Employee>
                           .OrderByDescending(x => x.Salary)
                           .ThenBy(x => x.Name, StringComparer.OrdinalIgnoreCase)
                           );
            Assert.True(employees.SequenceEqual(new[] { adam, alice, carol, xavier, bob }));

            employees.Sort(OrderedComparer <Employee>
                           .OrderByDescending(x => x.Age)
                           .ThenByDescending(x => x.Salary)
                           .ThenBy(x => x.Name)
                           );
            Assert.True(employees.SequenceEqual(new[] { adam, carol, xavier, bob, alice }));
        }
        protected void Refresh(IConnection connection)
        {
            if (connection == null)
            {
                LoggedIn          = false;
                IsVisible         = false;
                SectionConnection = null;
                if (Repositories != null)
                {
                    Repositories.CollectionChanged -= UpdateRepositoryList;
                }
                Repositories = null;
                settings     = null;

                if (sectionIndex == 0 && TEServiceProvider != null)
                {
                    var section = GetSection(TeamExplorerInvitationBase.TeamExplorerInvitationSectionGuid);
                    IsVisible = !(section?.IsVisible ?? true); // only show this when the invitation section is hidden. When in doubt, don't show it.
                    if (section != null)
                    {
                        section.PropertyChanged += (s, p) =>
                        {
                            if (p.PropertyName == "IsVisible")
                            {
                                IsVisible = LoggedIn || !((ITeamExplorerSection)s).IsVisible;
                            }
                        }
                    }
                    ;
                }
            }
            else
            {
                if (connection != SectionConnection)
                {
                    SectionConnection = connection;
                    Repositories      = SectionConnection.Repositories.CreateDerivedCollection(x => x,
                                                                                               orderer: OrderedComparer <ILocalRepositoryModel> .OrderBy(x => x.Name).Compare);
                    Repositories.CollectionChanged += UpdateRepositoryList;
                    Title      = connection.HostAddress.Title;
                    IsVisible  = true;
                    LoggedIn   = true;
                    settings   = packageSettings.UIState.GetOrCreateConnectSection(Title);
                    IsExpanded = settings.IsExpanded;
                }
                if (TEServiceProvider != null)
                {
                    RefreshRepositories().Forget();
                }
            }
        }
Exemplo n.º 4
0
        public RepositoryCloneViewModel(
            IConnection connection,
            IModelServiceFactory modelServiceFactory,
            IRepositoryCloneService cloneService,
            IOperatingSystem operatingSystem)
        {
            Guard.ArgumentNotNull(connection, nameof(connection));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(cloneService, nameof(cloneService));
            Guard.ArgumentNotNull(operatingSystem, nameof(operatingSystem));

            this.connection          = connection;
            this.modelServiceFactory = modelServiceFactory;
            this.operatingSystem     = operatingSystem;

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, connection.HostAddress.Title);

            Repositories = new TrackingCollection <IRemoteRepositoryModel>();
            repositories.ProcessingDelay = TimeSpan.Zero;
            repositories.Comparer        = OrderedComparer <IRemoteRepositoryModel> .OrderBy(x => x.Owner).ThenBy(x => x.Name).Compare;

            repositories.Filter        = FilterRepository;
            repositories.NewerComparer = OrderedComparer <IRemoteRepositoryModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            filterTextIsEnabled = this.WhenAny(x => x.IsBusy,
                                               loading => loading.Value || repositories.UnfilteredCount > 0 && !LoadingFailed)
                                  .ToProperty(this, x => x.FilterTextIsEnabled);

            this.WhenAny(
                x => x.repositories.UnfilteredCount,
                x => x.IsBusy,
                x => x.LoadingFailed,
                (unfilteredCount, loading, failed) =>
            {
                if (loading.Value)
                {
                    return(false);
                }

                if (failed.Value)
                {
                    return(false);
                }

                return(unfilteredCount.Value == 0);
            })
            .Subscribe(x =>
            {
                NoRepositoriesFound = x;
            });

            this.WhenAny(x => x.FilterText, x => x.Value)
            .DistinctUntilChanged(StringComparer.OrdinalIgnoreCase)
            .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
            .Subscribe(_ => repositories.Filter = FilterRepository);

            var baseRepositoryPath = this.WhenAny(
                x => x.BaseRepositoryPath,
                x => x.SelectedRepository,
                (x, y) => x.Value);

            BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(baseRepositoryPath)
                                          .IfNullOrEmpty(Resources.RepositoryCreationClonePathEmpty)
                                          .IfTrue(x => x.Length > 200, Resources.RepositoryCreationClonePathTooLong)
                                          .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters)
                                          .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid)
                                          .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists);

            var canCloneObservable = this.WhenAny(
                x => x.SelectedRepository,
                x => x.BaseRepositoryPathValidator.ValidationResult.IsValid,
                (x, y) => x.Value != null && y.Value);

            canClone     = canCloneObservable.ToProperty(this, x => x.CanClone);
            CloneCommand = ReactiveCommand.Create(canCloneObservable);

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());
            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
            .Subscribe();
            BaseRepositoryPath  = cloneService.DefaultClonePath;
            NoRepositoriesFound = true;
        }
Exemplo n.º 5
0
            public void DerivedCollectionsSmokeTest()
            {
                var adam = new ReactiveEmployee {
                    Name = "Adam", Age = 20, Salary = 100
                };
                var bob = new ReactiveEmployee {
                    Name = "Bob", Age = 30, Salary = 150
                };
                var carol = new ReactiveEmployee {
                    Name = "Carol", Age = 40, Salary = 200
                };
                var dan = new ReactiveEmployee {
                    Name = "Dan", Age = 50, Salary = 250
                };
                var eve = new ReactiveEmployee {
                    Name = "Eve", Age = 60, Salary = 300
                };

                var start = new[] { adam, bob, carol, dan, eve };

                var employees = new ReactiveCollection <ReactiveEmployee>(start)
                {
                    ChangeTrackingEnabled = true
                };

                var employeesByName = DerivedCollectionTestContainer.Create(
                    employees,
                    selector: x => x,
                    orderer: OrderedComparer <ReactiveEmployee> .OrderBy(x => x.Name)
                    );

                var employeesByAge = DerivedCollectionTestContainer.Create(
                    employees,
                    selector: x => x,
                    orderer: OrderedComparer <ReactiveEmployee> .OrderBy(x => x.Age)
                    );

                var employeesBySalary = DerivedCollectionTestContainer.Create(
                    employees,
                    selector: x => x,
                    orderer: OrderedComparer <ReactiveEmployee> .OrderBy(x => x.Salary)
                    );

                // special

                // filtered, ordered, reference
                var oldEmployeesByAge = DerivedCollectionTestContainer.Create(
                    employees,
                    selector: x => x,
                    filter: x => x.Age >= 50,
                    orderer: OrderedComparer <ReactiveEmployee> .OrderBy(x => x.Age)
                    );

                // ordered, not reference
                var employeeSalaries = DerivedCollectionTestContainer.Create(
                    employees,
                    selector: x => x.Salary,
                    orderer: Comparer <int> .Default
                    );

                // not filtered (derived filter), not reference, not ordered (derived order)
                oldEmployeesByAge.Derived.ChangeTrackingEnabled = true;
                var oldEmployeesSalariesByAge = DerivedCollectionTestContainer.Create(
                    oldEmployeesByAge.Derived,
                    selector: x => x.Salary
                    );

                var containers = new List <DerivedCollectionTestContainer> {
                    employeesByName, employeesByAge, employeesBySalary, oldEmployeesByAge,
                    employeeSalaries, oldEmployeesSalariesByAge
                };

                Action <Action> testAll = a => { a(); containers.ForEach(x => x.Test()); };

                containers.ForEach(x => x.Test());

                // if (isIncluded && !shouldBeIncluded)
                testAll(() => { dan.Age = 49; });

                // else if (!isIncluded && shouldBeIncluded)
                testAll(() => { dan.Age = eve.Age + 1; });

                // else if (isIncluded && shouldBeIncluded)
                testAll(() => { adam.Salary = 350; });

                testAll(() => { dan.Age = 50; });
                testAll(() => { dan.Age = 51; });
            }
Exemplo n.º 6
0
        public RepositoryCloneViewModel(
            IRepositoryHost repositoryHost,
            IRepositoryCloneService cloneService,
            IOperatingSystem operatingSystem,
            INotificationService notificationService,
            IUsageTracker usageTracker)
        {
            this.repositoryHost      = repositoryHost;
            this.cloneService        = cloneService;
            this.operatingSystem     = operatingSystem;
            this.notificationService = notificationService;
            this.usageTracker        = usageTracker;

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, repositoryHost.Title);

            Repositories = new TrackingCollection <IRepositoryModel>();
            repositories.ProcessingDelay = TimeSpan.Zero;
            repositories.Comparer        = OrderedComparer <IRepositoryModel> .OrderBy(x => x.Owner).ThenBy(x => x.Name).Compare;

            repositories.Filter        = FilterRepository;
            repositories.NewerComparer = OrderedComparer <IRepositoryModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            filterTextIsEnabled = this.WhenAny(x => x.IsLoading, x => x.Value)
                                  .Select(x => !x && repositories.UnfilteredCount > 0)
                                  .ToProperty(this, x => x.FilterTextIsEnabled);

            this.WhenAny(x => x.FilterTextIsEnabled, x => x.IsLoading, x => x.LoadingFailed
                         , (any, loading, failed) => !any.Value && !loading.Value && !failed.Value)
            .Subscribe(x => NoRepositoriesFound = x);

            this.WhenAny(x => x.FilterText, x => x.Value)
            .DistinctUntilChanged(StringComparer.OrdinalIgnoreCase)
            .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
            .Subscribe(_ => repositories.Filter = FilterRepository);

            var baseRepositoryPath = this.WhenAny(
                x => x.BaseRepositoryPath,
                x => x.SelectedRepository,
                (x, y) => x.Value);

            BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(baseRepositoryPath)
                                          .IfNullOrEmpty(Resources.RepositoryCreationClonePathEmpty)
                                          .IfTrue(x => x.Length > 200, Resources.RepositoryCreationClonePathTooLong)
                                          .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters)
                                          .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid)
                                          .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists);

            var canCloneObservable = this.WhenAny(
                x => x.SelectedRepository,
                x => x.BaseRepositoryPathValidator.ValidationResult.IsValid,
                (x, y) => x.Value != null && y.Value);

            canClone     = canCloneObservable.ToProperty(this, x => x.CanClone);
            CloneCommand = ReactiveCommand.CreateAsyncObservable(canCloneObservable, OnCloneRepository);

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());
            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
            .Subscribe();
            BaseRepositoryPath  = cloneService.DefaultClonePath;
            NoRepositoriesFound = true;
        }
Exemplo n.º 7
0
 private void OnPlaylistsChanged()
 {
     PlaylistView = Playlists.CreateDerivedCollection(_ => _,
                                                      orderer: OrderedComparer <Playlist> .OrderBy(_ => _.OrderNumber).Compare);
     ResetSelectedPlaylist();
 }
Exemplo n.º 8
0
 public IComparer <T> OrderBy <TValue>(Func <T, TValue> selector, IComparer <TValue> comparer) => OrderedComparer <T> .OrderBy(selector, comparer);