public void Add_AddsItem() { var items = new TrackingCollection <string>(); items.Add("foo"); items.Single().ShouldEqual("foo"); }
public void SendChangedTrackingCollectionToChangeTrackingCollection_CollectionMustChangeAndReturnThisCollection() { string trackingName = "name"; var trackingId = new Guid().ToString(); var eventId1 = new Guid().ToString(); var event1DateOfChange = new DateTimeOffset(); var eventId2 = new Guid().ToString(); var event2DateOfChange = new DateTimeOffset(); Event event1 = new Event(eventId1, trackingId, event1DateOfChange, 1, new Rating(1), "", event1DateOfChange, false); Event event2 = new Event(eventId2, trackingId, event2DateOfChange, 1, new Rating(1), "", event2DateOfChange, false); List <Event> eventCollection = new List <Event>(); eventCollection.Add(event1); eventCollection.Add(event2); Tracking tracking = new Tracking(trackingName, trackingId, event1DateOfChange, "Optional", "Optional", "Optional", event1DateOfChange, false, eventCollection); TrackingCollection trackingCollection = new TrackingCollection(); List <Tracking> trackings = new List <Tracking>(); trackings.Add(tracking); List <Tracking> returnedTrackings = trackingCollection.ChangeTrackingCollection(trackings); CollectionAssert.AreEqual(trackings, returnedTrackings); }
public ITrackingCollection <IPullRequestModel> GetPullRequests(ISimpleRepositoryModel repo) { // Since the api to list pull requests returns all the data for each pr, cache each pr in its own entry // and also cache an index that contains all the keys for each pr. This way we can fetch prs in bulk // but also individually without duplicating information. We store things in a custom observable collection // that checks whether an item is being updated (coming from the live stream after being retrieved from cache) // and replaces it instead of appending, so items get refreshed in-place as they come in. var keyobs = GetUserFromCache() .Select(user => string.Format(CultureInfo.InvariantCulture, "{0}|{1}|pr", user.Login, repo.Name)); var col = new TrackingCollection <IPullRequestModel>(); var source = Observable.Defer(() => keyobs .SelectMany(key => hostCache.GetAndFetchLatestFromIndex(key, () => apiClient.GetPullRequestsForRepository(repo.CloneUrl.Owner, repo.CloneUrl.RepositoryName) .Select(PullRequestCacheItem.Create), item => col.RemoveItem(Create(item)), TimeSpan.FromMinutes(5), TimeSpan.FromDays(1)) ) .Select(Create) ); col.Listen(source); return(col); }
public void TestTrackbackCreation() { EntryCollection entries = new EntryCollection(); entries = blogService.GetEntriesForDay(DateTime.MaxValue.AddDays(-2), DateTimeZone.Utc, String.Empty, int.MaxValue, int.MaxValue, String.Empty); int numberOfTrackings = 3; for (int i = 0; i < numberOfTrackings; i++) { Tracking t = new Tracking(); t.PermaLink = "http://www.foo.com/" + i; t.RefererBlogName = "Trackback " + i; t.RefererExcerpt = ""; t.RefererTitle = "Trackback " + i; t.TargetEntryId = entries[0].EntryId; t.TargetTitle = entries[0].Title; t.TrackingType = TrackingType.Trackback; blogService.AddTracking(t); } System.Threading.Thread.Sleep(2000); TrackingCollection trackingCollection = blogService.GetTrackingsFor(entries[0].EntryId); Assert.IsTrue(trackingCollection.Count == numberOfTrackings); }
public PullRequestListViewModel( IRepositoryHost repositoryHost, ILocalRepositoryModel repository, IPackageSettings settings) { this.repositoryHost = repositoryHost; this.repository = repository; this.settings = settings; Title = Resources.PullRequestsNavigationItemText; this.listSettings = settings.UIState .GetOrCreateRepositoryState(repository.CloneUrl) .PullRequests; States = new List <PullRequestState> { new PullRequestState { IsOpen = true, Name = "Open" }, new PullRequestState { IsOpen = false, Name = "Closed" }, new PullRequestState { Name = "All" } }; trackingAuthors = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(), OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare); trackingAssignees = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(), OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare); trackingAuthors.Subscribe(); trackingAssignees.Subscribe(); Authors = trackingAuthors.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAuthor)); Assignees = trackingAssignees.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAssignee)); PullRequests = new TrackingCollection <IPullRequestModel>(); pullRequests.Comparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare; pullRequests.NewerComparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare; this.WhenAny(x => x.SelectedState, x => x.Value) .Where(x => PullRequests != null) .Subscribe(s => UpdateFilter(s, SelectedAssignee, SelectedAuthor)); this.WhenAny(x => x.SelectedAssignee, x => x.Value) .Where(x => PullRequests != null && x != EmptyUser && IsLoaded) .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor)); this.WhenAny(x => x.SelectedAuthor, x => x.Value) .Where(x => PullRequests != null && x != EmptyUser && IsLoaded) .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a)); SelectedState = States.FirstOrDefault(x => x.Name == listSettings.SelectedState) ?? States[0]; OpenPullRequest = ReactiveCommand.Create(); OpenPullRequest.Subscribe(DoOpenPullRequest); CreatePullRequest = ReactiveCommand.Create(); CreatePullRequest.Subscribe(_ => DoCreatePullRequest()); }
public async Task DisplaysErrorMessageWhenExceptionOccurs() { var col = TrackingCollection.Create(Observable.Empty <IRemoteRepositoryModel>()); var repositoryHost = Substitute.For <IRepositoryHost>(); repositoryHost.ModelService.GetRepositories(Arg.Any <ITrackingCollection <IRemoteRepositoryModel> >()).Returns(_ => col); var cloneService = Substitute.For <IRepositoryCloneService>(); cloneService.CloneRepository(Args.String, Args.String, Args.String) .Returns(Observable.Throw <Unit>(new InvalidOperationException("Oh my! That was bad."))); var notificationService = Substitute.For <INotificationService>(); var vm = GetVM( repositoryHost, cloneService, Substitute.For <IOperatingSystem>(), notificationService, Substitute.For <IUsageTracker>()); vm.BaseRepositoryPath = @"c:\fake"; var repository = Substitute.For <IRemoteRepositoryModel>(); repository.Name.Returns("octokit"); vm.SelectedRepository = repository; await vm.CloneCommand.ExecuteAsync(null); notificationService.Received().ShowError("Failed to clone the repository 'octokit'\r\nEmail [email protected] if you continue to have problems."); }
public PullRequestListViewModel( IRepositoryHost repositoryHost, ILocalRepositoryModel repository, IPackageSettings settings) { this.repositoryHost = repositoryHost; this.repository = repository; this.settings = settings; this.listSettings = settings.UIState .GetOrCreateRepositoryState(repository.CloneUrl) .PullRequests; openPullRequestCommand = ReactiveCommand.Create(); openPullRequestCommand.Subscribe(_ => { VisualStudio.Services.DefaultExportProvider.GetExportedValue <IVisualStudioBrowser>().OpenUrl(repositoryHost.Address.WebUri); }); States = new List <PullRequestState> { new PullRequestState { IsOpen = true, Name = "Open" }, new PullRequestState { IsOpen = false, Name = "Closed" }, new PullRequestState { Name = "All" } }; trackingAuthors = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(), OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare); trackingAssignees = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(), OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare); trackingAuthors.Subscribe(); trackingAssignees.Subscribe(); Authors = trackingAuthors.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAuthor)); Assignees = trackingAssignees.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAssignee)); PullRequests = new TrackingCollection <IPullRequestModel>(); pullRequests.Comparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare; pullRequests.NewerComparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare; this.WhenAny(x => x.SelectedState, x => x.Value) .Where(x => PullRequests != null) .Subscribe(s => UpdateFilter(s, SelectedAssignee, SelectedAuthor)); this.WhenAny(x => x.SelectedAssignee, x => x.Value) .Where(x => PullRequests != null && x != EmptyUser && IsLoaded) .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor)); this.WhenAny(x => x.SelectedAuthor, x => x.Value) .Where(x => PullRequests != null && x != EmptyUser && IsLoaded) .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a)); SelectedState = States.FirstOrDefault(x => x.Name == listSettings.SelectedState) ?? States[0]; }
public async Task InitializeAsync(IConnection connection) { modelService = await modelServiceFactory.CreateAsync(connection); Title = string.Format(CultureInfo.CurrentCulture, Resources.CreateTitle, connection.HostAddress.Title); accounts = modelService.GetAccounts() .ObserveOn(RxApp.MainThreadScheduler) .ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection <IAccount>(new IAccount[] { })); this.WhenAny(x => x.Accounts, x => x.Value) .Select(accts => accts?.FirstOrDefault()) .WhereNotNull() .Subscribe(a => SelectedAccount = a); GitIgnoreTemplates = TrackingCollection.CreateListenerCollectionAndRun( modelService.GetGitIgnoreTemplates(), new[] { GitIgnoreItem.None }, OrderedComparer <GitIgnoreItem> .OrderByDescending(item => GitIgnoreItem.IsRecommended(item.Name)).Compare, x => { if (x.Name.Equals("VisualStudio", StringComparison.OrdinalIgnoreCase)) { SelectedGitIgnoreTemplate = x; } }); Licenses = TrackingCollection.CreateListenerCollectionAndRun( modelService.GetLicenses(), new[] { LicenseItem.None }, OrderedComparer <LicenseItem> .OrderByDescending(item => LicenseItem.IsRecommended(item.Name)).Compare); }
public async Task LoadsRepositories() { var repos = new IRemoteRepositoryModel[] { Substitute.For <IRemoteRepositoryModel>(), Substitute.For <IRemoteRepositoryModel>(), Substitute.For <IRemoteRepositoryModel>() }; var col = TrackingCollection.Create(repos.ToObservable()); var repositoryHost = Substitute.For <IRepositoryHost>(); repositoryHost.ModelService.GetRepositories(Arg.Any <ITrackingCollection <IRemoteRepositoryModel> >()).Returns(_ => col); var cloneService = Substitute.For <IRepositoryCloneService>(); var vm = GetVM( repositoryHost, cloneService, Substitute.For <IOperatingSystem>(), Substitute.For <INotificationService>(), Substitute.For <IUsageTracker>()); await col.OriginalCompleted; Assert.Equal(3, vm.Repositories.Count); }
void CreatePullRequests() { PullRequests = new TrackingCollection <IPullRequestModel>(); pullRequests.Comparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare; pullRequests.NewerComparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare; }
public void IsInvalidWhenDestinationRepositoryExists() { var repo = Substitute.For <IRemoteRepositoryModel>(); repo.Id.Returns(1); repo.Name.Returns("bar"); var data = new[] { repo }.ToObservable(); var col = new TrackingCollection <IRemoteRepositoryModel>(data); var repositoryHost = Substitute.For <IRepositoryHost>(); repositoryHost.ModelService.GetRepositories(Arg.Any <ITrackingCollection <IRemoteRepositoryModel> >()).Returns(_ => col); var cloneService = Substitute.For <IRepositoryCloneService>(); var os = Substitute.For <IOperatingSystem>(); var directories = Substitute.For <IDirectoryFacade>(); os.Directory.Returns(directories); directories.Exists(@"c:\foo\bar").Returns(true); var vm = GetVM( repositoryHost, cloneService, os, Substitute.For <INotificationService>(), Substitute.For <IUsageTracker>()); vm.BaseRepositoryPath = @"c:\foo"; vm.SelectedRepository = repo; Assert.Equal(ValidationStatus.Invalid, vm.BaseRepositoryPathValidator.ValidationResult.Status); }
public async Task IsFalseWhenLoadingAndCompletedWithRepository() { var repoSubject = new Subject <IRemoteRepositoryModel>(); var col = TrackingCollection.Create(repoSubject); var repositoryHost = Substitute.For <IRepositoryHost>(); repositoryHost.ModelService.GetRepositories(Arg.Any <ITrackingCollection <IRemoteRepositoryModel> >()).Returns(_ => col); var cloneService = Substitute.For <IRepositoryCloneService>(); var vm = GetVM( repositoryHost, cloneService, Substitute.For <IOperatingSystem>(), Substitute.For <INotificationService>(), Substitute.For <IUsageTracker>()); repoSubject.OnNext(Substitute.For <IRemoteRepositoryModel>()); Assert.False(vm.NoRepositoriesFound); repoSubject.OnCompleted(); await col.OriginalCompleted; await Task.Delay(100); Assert.Equal(1, vm.Repositories.Count); Assert.False(vm.NoRepositoriesFound); }
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<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.IsLoading, loading => loading.Value || repositories.UnfilteredCount > 0 && !LoadingFailed) .ToProperty(this, x => x.FilterTextIsEnabled); this.WhenAny(x => x.IsLoading, x => x.LoadingFailed, (loading, failed) => !loading.Value && !failed.Value && repositories.UnfilteredCount == 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.CreateAsyncObservable(canCloneObservable, OnCloneRepository); browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog()); this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value) .Subscribe(); BaseRepositoryPath = cloneService.DefaultClonePath; NoRepositoriesFound = true; }
public PullRequestListViewModelDesigner() { var prs = new TrackingCollection <IPullRequestModel>(Observable.Empty <IPullRequestModel>()); prs.Add(new PullRequestModel(399, "Let's try doing this differently", new AccountDesigner { Login = "******", IsUser = true }, DateTimeOffset.Now - TimeSpan.FromDays(1)) { Assignee = new AccountDesigner { Login = "******", IsUser = true }, }); prs.Add(new PullRequestModel(389, "Build system upgrade", new AccountDesigner { Login = "******", IsUser = true }, DateTimeOffset.Now - TimeSpan.FromMinutes(2)) { CommentCount = 4, HasNewComments = false, Assignee = new AccountDesigner { Login = "******", IsUser = true }, }); prs.Add(new PullRequestModel(409, "Fix publish button style and a really, really long name for this thing... OMG look how long this name is yusssss", new AccountDesigner { Login = "******", IsUser = true }, DateTimeOffset.Now - TimeSpan.FromHours(5)) { CommentCount = 27, HasNewComments = true, Assignee = new AccountDesigner { Login = "******", IsUser = true }, }); PullRequests = prs; States = new List <PullRequestState> { new PullRequestState { IsOpen = true, Name = "Open" }, new PullRequestState { IsOpen = false, Name = "Closed" }, new PullRequestState { Name = "All" } }; SelectedState = States[0]; Assignees = new ObservableCollection <IAccount>(prs.Select(x => x.Assignee)); Authors = new ObservableCollection <IAccount>(prs.Select(x => x.Author)); SelectedAssignee = Assignees.ElementAt(1); SelectedAuthor = Authors.ElementAt(1); IsLoaded = true; }
/// <summary> /// Initializes a new instance of the <see cref="LoggerResult" /> class. /// </summary> public LoggerResult(string moduleName = null) { Module = moduleName; Messages = new TrackingCollection <ILogMessage>(); IsLoggingProgressAsInfo = false; // By default, all logs are enabled for a local logger. ActivateLog(LogMessageType.Debug); }
public User(string userId, string pictureUrl, DateTimeOffset nicknameDateOfChange) { NicknameDateOfChange = nicknameDateOfChange; PictureUrl = pictureUrl; UserId = userId; UserNickname = userId; TrackingCollection = new TrackingCollection(); }
/// <summary> /// Initializes a new instance of the <see cref="InputManager"/> class. /// </summary> /// <param name="gameContext">The game context.</param> public InputManager() { Gestures = new TrackingCollection <GestureConfig>(); Gestures.CollectionChanged += GesturesOnCollectionChanged; Sources = new TrackingCollection <IInputSource>(); Sources.CollectionChanged += SourcesOnCollectionChanged; }
/// <summary> /// Initializes a new instance of the <see cref="RenderPass"/> class. /// </summary> /// <param name="name">The name.</param> public RenderPass(string name) : base(name) { Parameters = new ParameterCollection(); Enabled = true; // create Renderers lists renderers = new TrackingCollection <Renderer>(); renderers.CollectionChanged += (o, e) => { var processor = (Renderer)e.Item; switch (e.Action) { case NotifyCollectionChangedAction.Add: // Check consistency of Parent before setting it if (processor.Pass != null) { throw new InvalidOperationException("Renderer.Pass is already attached to another pass."); } processor.Pass = this; break; case NotifyCollectionChangedAction.Remove: // Check consistency of Parent before setting it if (processor.Pass != this) { throw new InvalidOperationException("Renderer.Pass is not attached to a this pass.."); } //processor.Pass = null; break; } }; // Create children passes children = new TrackingCollection <RenderPass>(); children.CollectionChanged += (o, e) => { var renderPass = (RenderPass)e.Item; switch (e.Action) { case NotifyCollectionChangedAction.Add: // Check consistency of Parent before setting it if (renderPass.Parent != null) { throw new InvalidOperationException("Pass.Parent should be null."); } renderPass.Parent = this; break; case NotifyCollectionChangedAction.Remove: // Check consistency of Parent before setting it if (renderPass.Parent != this) { throw new InvalidOperationException("Pass.Parent is not set properly."); } renderPass.Parent = null; break; } }; }
/// <summary> /// Initializes a new instance of the <see cref="Scene"/> class. /// </summary> public Scene() { Id = Guid.NewGuid(); Entities = new TrackingCollection <Entity>(); Entities.CollectionChanged += Entities_CollectionChanged; Children = new TrackingCollection <Scene>(); Children.CollectionChanged += Children_CollectionChanged; }
/// <summary> /// Initializes a new instance of the <see cref="ParticlePlugin" /> class. /// </summary> /// <param name="name">Name of this particle manager</param> public ParticlePlugin(string name) : base(name) { meshesToRender = new RenderPassListEnumerator(); Updaters = new TrackingCollection<ParticleEmitterComponent>(); currentUpdaters = new List<ParticleUpdaterState>(); updatersToRemove = new List<ParticleUpdaterState>(); Updaters.CollectionChanged += UpdatersOnCollectionChanged; EnableSorting = true; }
/// <summary> /// Initializes a new instance of the <see cref="ParticlePlugin" /> class. /// </summary> /// <param name="name">Name of this particle manager</param> public ParticlePlugin(string name) : base(name) { meshesToRender = new RenderPassListEnumerator(); Updaters = new TrackingCollection <ParticleEmitterComponent>(); currentUpdaters = new List <ParticleUpdaterState>(); updatersToRemove = new List <ParticleUpdaterState>(); Updaters.CollectionChanged += UpdatersOnCollectionChanged; EnableSorting = true; }
public LightReceiverProcessor(LightProcessor lightProcessor) : base(new PropertyKey[] { MeshComponent.Key }) { this.lightProcessor = lightProcessor; var globalLights = new TrackingCollection <LightComponent>(); globalLights.CollectionChanged += globalLights_CollectionChanged; GlobalLights = globalLights; }
public PullRequestListViewModel(IRepositoryHost repositoryHost, ISimpleRepositoryModel repository) { this.repositoryHost = repositoryHost; this.repository = repository; openPullRequestCommand = ReactiveCommand.Create(); openPullRequestCommand.Subscribe(_ => { VisualStudio.Services.DefaultExportProvider.GetExportedValue <IVisualStudioBrowser>().OpenUrl(repositoryHost.Address.WebUri); }); States = new List <PullRequestState> { new PullRequestState { IsOpen = true, Name = "Open" }, new PullRequestState { IsOpen = false, Name = "Closed" }, new PullRequestState { Name = "All" } }; SelectedState = States[0]; this.WhenAny(x => x.SelectedState, x => x.Value) .Where(x => PullRequests != null) .Subscribe(s => UpdateFilter(s, SelectedAssignee, SelectedAuthor)); this.WhenAny(x => x.SelectedAssignee, x => x.Value) .Where(x => PullRequests != null) .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor)); this.WhenAny(x => x.SelectedAuthor, x => x.Value) .Where(x => PullRequests != null) .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a)); trackingAuthors = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(), OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare); trackingAssignees = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(), OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare); trackingAuthors.Subscribe(); trackingAssignees.Subscribe(); Authors = trackingAuthors.CreateListenerCollection(new List <IAccount> { EmptyUser }); Assignees = trackingAssignees.CreateListenerCollection(new List <IAccount> { EmptyUser }); PullRequests = new TrackingCollection <IPullRequestModel>(); pullRequests.Comparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare; pullRequests.Filter = (pr, i, l) => pr.IsOpen; pullRequests.NewerComparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare; }
public void When_Item_Added_Raises_ItemAdded() { string addedItem = null; var items = new TrackingCollection<string>(); using(items.OnItemAdded(x => addedItem = x)) { items.Add("foo"); } addedItem.ShouldEqual("foo"); }
protected PhysicsElementBase() { CanScaleShape = true; ColliderShapes = new TrackingCollection<IInlineColliderShapeDesc>(); ColliderShapes.CollectionChanged += (sender, args) => { ColliderShapeChanged = true; }; }
static TrackingCollection <Thing> CreateSource() { var result = new TrackingCollection <Thing>(Observable.Empty <Thing>()); result.Subscribe(); result.AddItem(new Thing(1, "item1", DateTimeOffset.MinValue)); result.AddItem(new Thing(2, "item2", DateTimeOffset.MinValue)); result.AddItem(new Thing(3, "item3", DateTimeOffset.MinValue)); return(result); }
protected PhysicsElementBase() { CanScaleShape = true; ColliderShapes = new TrackingCollection <IInlineColliderShapeDesc>(); ColliderShapes.CollectionChanged += (sender, args) => { ColliderShapeChanged = true; }; }
/// <summary> /// Initializes a new instance of the <see cref="SceneInstance" /> class. /// </summary> /// <param name="services">The services.</param> /// <param name="sceneEntityRoot">The scene entity root.</param> /// <param name="enableScripting">if set to <c>true</c> [enable scripting].</param> /// <exception cref="System.ArgumentNullException">services /// or /// sceneEntityRoot</exception> public SceneInstance(IServiceRegistry services, Scene sceneEntityRoot, ExecutionMode executionMode = ExecutionMode.Runtime) : base(services) { if (services == null) throw new ArgumentNullException("services"); ExecutionMode = executionMode; VisibilityGroups = new TrackingCollection<VisibilityGroup>(); VisibilityGroups.CollectionChanged += VisibilityGroups_CollectionChanged; Scene = sceneEntityRoot; Load(); }
/// <summary> /// Initializes a new instance of the <see cref="InputManager"/> class. /// </summary> internal InputManager(IServiceRegistry registry) : base(registry) { Enabled = true; Gestures = new TrackingCollection <GestureConfig>(); Gestures.CollectionChanged += GesturesOnCollectionChanged; Sources = new TrackingCollection <IInputSource>(); Sources.CollectionChanged += SourcesOnCollectionChanged; }
public PullRequestListViewModel( IRepositoryHost repositoryHost, ILocalRepositoryModel repository, IPackageSettings settings) { this.repositoryHost = repositoryHost; this.repository = repository; this.settings = settings; Title = Resources.PullRequestsNavigationItemText; this.listSettings = settings.UIState .GetOrCreateRepositoryState(repository.CloneUrl) .PullRequests; openPullRequestCommand = ReactiveCommand.Create(); openPullRequestCommand.Subscribe(_ => { VisualStudio.Services.DefaultExportProvider.GetExportedValue<IVisualStudioBrowser>().OpenUrl(repositoryHost.Address.WebUri); }); States = new List<PullRequestState> { new PullRequestState { IsOpen = true, Name = "Open" }, new PullRequestState { IsOpen = false, Name = "Closed" }, new PullRequestState { Name = "All" } }; trackingAuthors = new TrackingCollection<IAccount>(Observable.Empty<IAccount>(), OrderedComparer<IAccount>.OrderByDescending(x => x.Login).Compare); trackingAssignees = new TrackingCollection<IAccount>(Observable.Empty<IAccount>(), OrderedComparer<IAccount>.OrderByDescending(x => x.Login).Compare); trackingAuthors.Subscribe(); trackingAssignees.Subscribe(); Authors = trackingAuthors.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAuthor)); Assignees = trackingAssignees.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAssignee)); PullRequests = new TrackingCollection<IPullRequestModel>(); pullRequests.Comparer = OrderedComparer<IPullRequestModel>.OrderByDescending(x => x.UpdatedAt).Compare; pullRequests.NewerComparer = OrderedComparer<IPullRequestModel>.OrderByDescending(x => x.UpdatedAt).Compare; this.WhenAny(x => x.SelectedState, x => x.Value) .Where(x => PullRequests != null) .Subscribe(s => UpdateFilter(s, SelectedAssignee, SelectedAuthor)); this.WhenAny(x => x.SelectedAssignee, x => x.Value) .Where(x => PullRequests != null && x != EmptyUser && IsLoaded) .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor)); this.WhenAny(x => x.SelectedAuthor, x => x.Value) .Where(x => PullRequests != null && x != EmptyUser && IsLoaded) .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a)); SelectedState = States.FirstOrDefault(x => x.Name == listSettings.SelectedState) ?? States[0]; }
/// <summary> /// Initializes a new instance of the <see cref="TransformationComponent" /> class. /// </summary> public TransformationComponent() { var children = new TrackingCollection <TransformationComponent>(); children.CollectionChanged += ChildrenCollectionChanged; Children = children; UseTRS = true; Scaling = Vector3.One; }
public void When_Item_Added_Raises_ItemAdded() { string addedItem = null; var items = new TrackingCollection <string>(); using (items.OnItemAdded(x => addedItem = x)) { items.Add("foo"); } addedItem.ShouldEqual("foo"); }
public void Should_not_raise_event_once_handler_detached() { var addedItems = new List<string>(); var items = new TrackingCollection<string>(); using(items.OnItemAdded(addedItems.Add)) { items.Add("foo"); } items.Add("bar"); addedItems.Count.ShouldEqual(1); }
/// <summary> /// Initializes a new instance of the <see cref="TransformComponent" /> class. /// </summary> public TransformComponent() { var children = new TrackingCollection<TransformComponent>(); children.CollectionChanged += ChildrenCollectionChanged; Children = children; UseTRS = true; Scale = Vector3.One; Rotation = Quaternion.Identity; }
public void Should_not_raise_event_once_handler_detached() { var addedItems = new List <string>(); var items = new TrackingCollection <string>(); using (items.OnItemAdded(addedItems.Add)) { items.Add("foo"); } items.Add("bar"); addedItems.Count.ShouldEqual(1); }
/// <summary> /// Initializes a new instance of the <see cref="TransformComponent" /> class. /// </summary> public TransformComponent() { var children = new TrackingCollection <TransformComponent>(); children.CollectionChanged += ChildrenCollectionChanged; Children = children; UseTRS = true; Scale = Vector3.One; Rotation = Quaternion.Identity; }
public ViewModel() { _selectedView = View.vwOpsChecklistLoad; //_selectedView = View.vwDueToday | View.vwAssignedTasks;//this sets the initial View _tasks = new TrackingCollection(); Refreshing = false; IsUpdating = false; regionalSettings = new RegionalSetting(this); LoggedInUserInfo = new UserInfo(); memberOfGroups = new ObservableCollection<string>(); MemberOfGroups.CollectionChanged += MemberOfGroups_CollectionChanged; }
public async Task NonExpiredIndexReturnsCacheAsync() { var expected = 5; var username = "******"; var reponame = "repo"; var cache = new InMemoryBlobCache(); var apiClient = Substitute.For <IApiClient>(); var modelService = CreateTarget(apiClient: apiClient, hostCache: cache); var user = CreateOctokitUser(username); apiClient.GetUser().Returns(Observable.Return(user)); apiClient.GetOrganizations().Returns(Observable.Empty <Organization>()); var act = modelService.GetAccounts().ToEnumerable().First().First(); var repo = Substitute.For <LocalRepositoryModel>(); repo.Name.Returns(reponame); repo.CloneUrl.Returns(new UriString("https://github.com/" + username + "/" + reponame)); var indexKey = string.Format(CultureInfo.InvariantCulture, "{0}|{1}:{2}", CacheIndex.PRPrefix, user.Login, repo.Name); var prcache = Enumerable.Range(1, expected) .Select(id => CreatePullRequest(user, id, ItemState.Open, "Cache " + id, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow)); // seed the cache prcache .Select(item => new PullRequestCacheItem(item)) .Select(item => item.Save <PullRequestCacheItem>(cache, indexKey).ToEnumerable().First()) .SelectMany(item => CacheIndex.AddAndSaveToIndex(cache, indexKey, item).ToEnumerable()) .ToList(); var prlive = Observable.Range(1, expected) .Select(id => CreatePullRequest(user, id, ItemState.Open, "Live " + id, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow)) .DelaySubscription(TimeSpan.FromMilliseconds(10)); apiClient.GetPullRequestsForRepository(user.Login, repo.Name).Returns(prlive); await modelService.InsertUser(new AccountCacheItem(user)); ITrackingCollection <IPullRequestModel> col = new TrackingCollection <IPullRequestModel>(); modelService.GetPullRequests(repo, col); col.ProcessingDelay = TimeSpan.Zero; col.Subscribe(); await col.OriginalCompleted.Timeout(TimeSpan.FromMilliseconds(Timeout));; Assert.That(expected, Is.EqualTo(col.Count)); //Assert.Collection(col, col.Select(x => new Action<IPullRequestModel>(t => Assert.That("Cache", StartsWith(x.Title)))).ToArray()); }
protected PhysicsComponent() { CanScaleShape = true; ColliderShapes = new TrackingCollection<IInlineColliderShapeDesc>(); ColliderShapes.CollectionChanged += (sender, args) => { ColliderShapeChanged = true; }; NewPairChannel = new Channel<Collision> { Preference = ChannelPreference.PreferSender }; PairEndedChannel = new Channel<Collision> { Preference = ChannelPreference.PreferSender }; }
/// <summary> /// Initializes a new instance of the <see cref="SceneInstance" /> class. /// </summary> /// <param name="services">The services.</param> /// <param name="sceneEntityRoot">The scene entity root.</param> /// <param name="enableScripting">if set to <c>true</c> [enable scripting].</param> /// <exception cref="System.ArgumentNullException">services /// or /// sceneEntityRoot</exception> public SceneInstance(IServiceRegistry services, Scene sceneEntityRoot, ExecutionMode executionMode = ExecutionMode.Runtime) : base(services) { if (services == null) { throw new ArgumentNullException("services"); } ExecutionMode = executionMode; VisibilityGroups = new TrackingCollection <VisibilityGroup>(); VisibilityGroups.CollectionChanged += VisibilityGroups_CollectionChanged; Scene = sceneEntityRoot; Load(); }
public void OrderByUpdatedFilter() { var count = 3; ITrackingCollection<Thing> col = new TrackingCollection<Thing>( Observable.Never<Thing>(), OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare, (item, position, list) => true, OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare); col.ProcessingDelay = TimeSpan.Zero; var list1 = new List<Thing>(Enumerable.Range(1, count).Select(i => GetThing(i, i, count - i, "Run 1")).ToList()); var list2 = new List<Thing>(Enumerable.Range(1, count).Select(i => GetThing(i, i, i + count, "Run 2")).ToList()); var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == list1.Count) evt.Set(); }, () => { }); count = 0; // add first items foreach (var l in list1) col.AddItem(l); evt.WaitOne(); evt.Reset(); Assert.AreEqual(list1.Count, col.Count); list1.Sort(new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderByDescending(x => x.CreatedAt).Compare)); CollectionAssert.AreEqual(col, list1); count = 0; // replace items foreach (var l in list2) col.AddItem(l); evt.WaitOne(); evt.Reset(); Assert.AreEqual(list2.Count, col.Count); CollectionAssert.AreEqual(col, list2); col.Dispose(); }
public MainWindow() { InitializeComponent(); DataContext = this; /* stuff.CollectionChanged += (s, e) => { Console.WriteLine(e.Action); e.NewItems?.OfType<Thing>().All(thing => { Console.WriteLine("{0} {1}:{2}", e.Action, thing.Number, thing.UpdatedAt); return true; }); }; */ Activated += (s, e) => { }; col = new TrackingCollection<Thing>( OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare); col.ProcessingDelay = TimeSpan.FromMilliseconds(30); }
public void MultipleSortingAndFiltering() { var expectedTotal = 20; var rnd = new Random(214748364); var titles1 = Enumerable.Range(1, expectedTotal).Select(x => ((char)('a' + x)).ToString()).ToList(); var dates1 = Enumerable.Range(1, expectedTotal).Select(x => Now + TimeSpan.FromMinutes(x)).ToList(); var idstack1 = new Stack<int>(Enumerable.Range(1, expectedTotal).OrderBy(rnd.Next)); var datestack1 = new Stack<DateTimeOffset>(dates1); var titlestack1 = new Stack<string>(titles1.OrderBy(_ => rnd.Next())); var titles2 = Enumerable.Range(1, expectedTotal).Select(x => ((char)('c' + x)).ToString()).ToList(); var dates2 = Enumerable.Range(1, expectedTotal).Select(x => Now + TimeSpan.FromMinutes(x)).ToList(); var idstack2 = new Stack<int>(Enumerable.Range(1, expectedTotal).OrderBy(rnd.Next)); var datestack2 = new Stack<DateTimeOffset>(new List<DateTimeOffset>() { dates2[2], dates2[0], dates2[1], dates2[3], dates2[5], dates2[9], dates2[15], dates2[6], dates2[7], dates2[8], dates2[13], dates2[10], dates2[16], dates2[11], dates2[12], dates2[14], dates2[17], dates2[18], dates2[19], dates2[4], }); var titlestack2 = new Stack<string>(titles2.OrderBy(_ => rnd.Next())); var list1 = Observable.Defer(() => Enumerable.Range(1, expectedTotal) .OrderBy(rnd.Next) .Select(x => new Thing(idstack1.Pop(), titlestack1.Pop(), datestack1.Pop())) .ToObservable()) .Replay() .RefCount(); var list2 = Observable.Defer(() => Enumerable.Range(1, expectedTotal) .OrderBy(rnd.Next) .Select(x => new Thing(idstack2.Pop(), titlestack2.Pop(), datestack2.Pop())) .ToObservable()) .Replay() .RefCount(); var col = new TrackingCollection<Thing>( list1.Concat(list2), OrderedComparer<Thing>.OrderByDescending(x => x.CreatedAt).Compare, (item, idx, list) => idx < 5 ) { ProcessingDelay = TimeSpan.Zero }; var count = 0; var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == expectedTotal * 2) evt.Set(); }, () => { }); evt.WaitOne(); evt.Reset(); // it's initially sorted by date, so id list should not match CollectionAssert.AreNotEqual(list1.Select(x => x.Number).ToEnumerable(), list2.Select(x => x.Number).ToEnumerable()); var sortlist = list1.ToEnumerable().ToArray(); Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderByDescending(x => x.CreatedAt).Compare)); CollectionAssert.AreEqual(sortlist.Take(5), col); col.SetComparer(OrderedComparer<Thing>.OrderBy(x => x.Number).Compare); sortlist = list1.ToEnumerable().ToArray(); Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderBy(x => x.Number).Compare)); CollectionAssert.AreEqual(sortlist.Take(5), col); col.SetComparer(OrderedComparer<Thing>.OrderBy(x => x.CreatedAt).Compare); sortlist = list1.ToEnumerable().ToArray(); Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderBy(x => x.CreatedAt).Compare)); CollectionAssert.AreEqual(sortlist.Take(5), col); col.SetComparer(OrderedComparer<Thing>.OrderByDescending(x => x.Title).Compare); sortlist = list1.ToEnumerable().ToArray(); Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderByDescending(x => x.Title).Compare)); CollectionAssert.AreEqual(sortlist.Take(5), col); col.SetComparer(OrderedComparer<Thing>.OrderBy(x => x.Title).Compare); sortlist = list1.ToEnumerable().ToArray(); Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderBy(x => x.Title).Compare)); CollectionAssert.AreEqual(sortlist.Take(5), col); col.Dispose(); }
public void DisposingThrows() { var col = new TrackingCollection<Thing>(Observable.Empty<Thing>()); col.Dispose(); Assert.Throws<ObjectDisposedException>(() => col.SetFilter(null)); Assert.Throws<ObjectDisposedException>(() => col.SetComparer(null)); Assert.Throws<ObjectDisposedException>(() => col.Subscribe()); Assert.Throws<ObjectDisposedException>(() => col.AddItem(GetThing(1))); Assert.Throws<ObjectDisposedException>(() => col.RemoveItem(GetThing(1))); }
public void Removing() { var source = new Subject<Thing>(); var col = new TrackingCollection<Thing>( source, OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare, (item, position, list) => (position > 2 && position < 5) || (position > 6 && position < 8)) { ProcessingDelay = TimeSpan.Zero }; var count = 0; var expectedCount = 0; var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == expectedCount) evt.Set(); }, () => { }); expectedCount = 11; Add(source, GetThing(0, 0)); Add(source, GetThing(1, 1)); Add(source, GetThing(2, 2)); Add(source, GetThing(3, 3)); Add(source, GetThing(4, 4)); Add(source, GetThing(5, 5)); Add(source, GetThing(6, 6)); Add(source, GetThing(7, 7)); Add(source, GetThing(8, 8)); Add(source, GetThing(9, 9)); Add(source, GetThing(10, 10)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(3, 3), GetThing(4, 4), GetThing(7, 7), }); expectedCount = 12; col.RemoveItem(GetThing(2)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(4, 4), GetThing(5, 5), GetThing(8, 8), }); expectedCount = 13; col.RemoveItem(GetThing(5)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(4, 4), GetThing(6, 6), GetThing(9, 9), }); col.SetFilter(null); expectedCount = 14; col.RemoveItem(GetThing(100)); // this one won't result in a new element from the observable col.RemoveItem(GetThing(10)); evt.WaitOne(); evt.Reset(); Assert.AreEqual(8, col.Count); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(0, 0), GetThing(1, 1), GetThing(3, 3), GetThing(4, 4), GetThing(6, 6), GetThing(7, 7), GetThing(8, 8), GetThing(9, 9), }); col.Dispose(); }
public void ChangingComparers() { var source = new Subject<Thing>(); var col = new TrackingCollection<Thing>(source, OrderedComparer<Thing>.OrderBy(x => x.CreatedAt).Compare) { ProcessingDelay = TimeSpan.Zero }; var count = 0; var evt = new ManualResetEvent(false); var list1 = new List<Thing> { GetThing(1, 1, 9), GetThing(2, 2, 8), GetThing(3, 3, 7), GetThing(4, 4, 6), GetThing(5, 5, 5), GetThing(6, 6, 4), GetThing(7, 7, 3), GetThing(8, 8, 2), GetThing(9, 9, 1), }; col.Subscribe(t => { if (++count == list1.Count) evt.Set(); }, () => { }); foreach (var l in list1) Add(source, l); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, list1); col.SetComparer(null); CollectionAssert.AreEqual(col, list1.Reverse<Thing>().ToArray()); col.Dispose(); }
public void RemovingItemsFromCollectionManuallyThrows2() { var source = new Subject<Thing>(); var col = new TrackingCollection<Thing>(source) { ProcessingDelay = TimeSpan.Zero }; var count = 0; var expectedCount = 2; var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == expectedCount) evt.Set(); }, () => { }); Add(source, GetThing(1, 1)); Add(source, GetThing(2, 2)); evt.WaitOne(); evt.Reset(); Assert.Throws<InvalidOperationException>(() => col.RemoveAt(0)); col.Dispose(); }
public void InsertingItemsIntoCollectionManuallyThrows() { var col = new TrackingCollection<Thing>(Observable.Empty<Thing>()); Assert.Throws<InvalidOperationException>(() => col.Insert(0, GetThing(1))); col.Dispose(); }
public void ChangingFilterUpdatesCollection() { var source = new Subject<Thing>(); var col = new TrackingCollection<Thing>( source, OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare, (item, position, list) => item.UpdatedAt < Now + TimeSpan.FromMinutes(10)) { ProcessingDelay = TimeSpan.Zero }; var count = 0; var expectedCount = 0; var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == expectedCount) evt.Set(); }, () => { }); expectedCount = 9; Add(source, GetThing(1, 1)); Add(source, GetThing(2, 2)); Add(source, GetThing(3, 3)); Add(source, GetThing(4, 4)); Add(source, GetThing(5, 5)); Add(source, GetThing(6, 6)); Add(source, GetThing(7, 7)); Add(source, GetThing(8, 8)); Add(source, GetThing(9, 9)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(1, 1), GetThing(2, 2), GetThing(3, 3), GetThing(4, 4), GetThing(5, 5), GetThing(6, 6), GetThing(7, 7), GetThing(8, 8), GetThing(9, 9), }); col.SetFilter((item, position, list) => item.UpdatedAt < Now + TimeSpan.FromMinutes(8)); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(1, 1), GetThing(2, 2), GetThing(3, 3), GetThing(4, 4), GetThing(5, 5), GetThing(6, 6), GetThing(7, 7), }); col.Dispose(); }
public void OnlyTimesEqualOrHigherThan3Minutes() { var count = 6; var list1 = new List<Thing>(Enumerable.Range(1, count).Select(i => GetThing(i, i, count - i, "Run 1")).ToList()); var col = new TrackingCollection<Thing>( Observable.Never<Thing>(), OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare, (item, position, list) => item.UpdatedAt >= Now + TimeSpan.FromMinutes(3) && item.UpdatedAt <= Now + TimeSpan.FromMinutes(5)); col.ProcessingDelay = TimeSpan.Zero; var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == list1.Count) evt.Set(); }, () => { }); count = 0; // add first items foreach (var l in list1) col.AddItem(l); evt.WaitOne(); evt.Reset(); Assert.AreEqual(3, col.Count); #if DEBUG CollectionAssert.AreEqual(list1.Reverse<Thing>(), col.DebugInternalList); #endif CollectionAssert.AreEqual(col, new List<Thing>() { list1[2], list1[1], list1[0] }); col.Dispose(); }
public void OrderByMatchesOriginalOrder() { var count = 0; var total = 1000; var list1 = new List<Thing>(Enumerable.Range(1, total).Select(i => GetThing(i, i, total - i, "Run 1")).ToList()); var list2 = new List<Thing>(Enumerable.Range(1, total).Select(i => GetThing(i, i, total - i, "Run 2")).ToList()); var col = new TrackingCollection<Thing>( list1.ToObservable(), OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare, (item, position, list) => item.Title.Equals("Run 2")); col.ProcessingDelay = TimeSpan.Zero; count = 0; var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == list1.Count) evt.Set(); }, () => { }); evt.WaitOne(); evt.Reset(); Assert.AreEqual(total, count); Assert.AreEqual(0, col.Count); count = 0; // add new items foreach (var l in list2) col.AddItem(l); evt.WaitOne(); evt.Reset(); Assert.AreEqual(total, count); Assert.AreEqual(total, col.Count); CollectionAssert.AreEqual(col, list2); col.Dispose(); }
public void NotInitializedCorrectlyThrows2() { var col = new TrackingCollection<Thing>(OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare); Assert.Throws<InvalidOperationException>(() => col.Subscribe(_ => { }, () => { })); }
internal void LoadDayExtra(string fullPath) { FileStream fileStream = FileUtils.OpenForRead(fullPath); if (fileStream != null) { try { XmlSerializer ser = new XmlSerializer(typeof (DayExtra), Data.NamespaceURI); using (StreamReader reader = new StreamReader(fileStream)) { //XmlNamespaceUpgradeReader upg = new XmlNamespaceUpgradeReader(reader, "", Data.NamespaceURI); DayExtra e = (DayExtra)ser.Deserialize(reader); this._comments = e.Comments; this._trackings = e.Trackings; } } catch (Exception e) { ErrorTrace.Trace(TraceLevel.Error, e); } finally { fileStream.Close(); } //RepairComments(); } }
public void OrderByDescendingNoFilter1000() { var count = 1000; var total = 1000; var list1 = new List<Thing>(Enumerable.Range(1, count).Select(i => GetThing(i, i, count - i, "Run 1")).ToList()); var list2 = new List<Thing>(Enumerable.Range(1, count).Select(i => GetThing(i, i, count - i, "Run 2")).ToList()); var col = new TrackingCollection<Thing>( Observable.Never<Thing>(), OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare); col.ProcessingDelay = TimeSpan.Zero; var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == list1.Count) evt.Set(); }, () => { }); count = 0; // add first items foreach (var l in list1) col.AddItem(l); evt.WaitOne(); evt.Reset(); Assert.AreEqual(total, col.Count); CollectionAssert.AreEqual(col, list1); count = 0; foreach (var l in list2) col.AddItem(l); evt.WaitOne(); evt.Reset(); Assert.AreEqual(total, col.Count); count = 0; foreach (var l in list2) col.AddItem(l); evt.WaitOne(); evt.Reset(); Assert.AreEqual(total, col.Count); col.Dispose(); }
public void ProcessingDelayPingsRegularly() { int count, total; count = total = 400; var list1 = new List<Thing>(Enumerable.Range(1, count).Select(i => GetThing(i, i, count - i)).ToList()); var col = new TrackingCollection<Thing>( list1.ToObservable().Delay(TimeSpan.FromMilliseconds(10)), OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare); col.ProcessingDelay = TimeSpan.FromMilliseconds(10); var sub = new Subject<Thing>(); var times = new List<DateTimeOffset>(); sub.Subscribe(t => { times.Add(DateTimeOffset.UtcNow); }); count = 0; var evt = new ManualResetEvent(false); col.Subscribe(t => { sub.OnNext(t); if (++count == list1.Count) { sub.OnCompleted(); evt.Set(); } }, () => { }); evt.WaitOne(); evt.Reset(); Assert.AreEqual(total, col.Count); CollectionAssert.AreEqual(col, list1); long totalTime = 0; for (var j = 1; j < times.Count; j++) totalTime += (times[j] - times[j - 1]).Ticks; var avg = TimeSpan.FromTicks(totalTime / times.Count).TotalMilliseconds; Assert.GreaterOrEqual(avg, 9); Assert.LessOrEqual(avg, 12); col.Dispose(); }
public void ChangingSortUpdatesCollection() { var source = new Subject<Thing>(); var col = new TrackingCollection<Thing>( source, OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare, (item, position, list) => item.UpdatedAt < Now + TimeSpan.FromMinutes(10)) { ProcessingDelay = TimeSpan.Zero }; var count = 0; var evt = new ManualResetEvent(false); var list1 = new List<Thing> { GetThing(1, 1), GetThing(2, 2), GetThing(3, 3), GetThing(4, 4), GetThing(5, 5), GetThing(6, 6), GetThing(7, 7), GetThing(8, 8), GetThing(9, 9), }; col.Subscribe(t => { if (++count == list1.Count) evt.Set(); }, () => { }); foreach (var l in list1) Add(source, l); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, list1); col.SetComparer(OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare); CollectionAssert.AreEqual(col, list1.Reverse<Thing>().ToArray()); col.Dispose(); }
public void NoChangingAfterDisposed2() { var col = new TrackingCollection<Thing>(Observable.Never<Thing>(), OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare); col.Dispose(); Assert.Throws<ObjectDisposedException>(() => col.RemoveItem(new Thing())); }
public void SortingTestWithFilterMoves() { var source = new Subject<Thing>(); var col = new TrackingCollection<Thing>( source, OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare, (item, position, list) => (position >= 1 && position <= 2) || (position >= 5 && position <= 7)) { ProcessingDelay = TimeSpan.Zero }; var count = 0; var expectedCount = 0; var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == expectedCount) evt.Set(); }, () => { }); expectedCount = 9; Add(source, GetThing(1, 1)); Add(source, GetThing(2, 3)); Add(source, GetThing(3, 5)); Add(source, GetThing(4, 7)); Add(source, GetThing(5, 9)); Add(source, GetThing(6, 11)); Add(source, GetThing(7, 13)); Add(source, GetThing(8, 15)); Add(source, GetThing(9, 17)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(2, 3), GetThing(3, 5), GetThing(6, 11), GetThing(7, 13), GetThing(8, 5), }); expectedCount = 10; Add(source, GetThing(7, 4)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(2, 3), GetThing(7, 4), GetThing(5, 9), GetThing(6, 11), GetThing(8, 5), }); expectedCount = 11; Add(source, GetThing(9, 2)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(9, 2), GetThing(2, 3), GetThing(4, 7), GetThing(5, 9), GetThing(6, 11), }); col.Dispose(); }
public void SortingTestWithFilterBetween6And12() { var source = new Subject<Thing>(); var col = new TrackingCollection<Thing>( source, OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare, (item, position, list) => item.UpdatedAt.Minute >= 6 && item.UpdatedAt.Minute <= 12); col.ProcessingDelay = TimeSpan.Zero; var count = 0; var expectedCount = 0; var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == expectedCount) evt.Set(); }, () => { }); // testing ADD expectedCount = 1; // add a thing with UpdatedAt=0:0:10 Add(source, GetThing(1, 10)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(1, 10), }); // testing ADD // add another thing with UpdatedAt=0:0:2 expectedCount = 2; Add(source, GetThing(2, 2)); evt.WaitOne(); evt.Reset(); // check that list has {0:0:10,0:0:2} CollectionAssert.AreEqual(col, new List<Thing> { GetThing(1, 10), }); // testing MOVE // replace thing with UpdatedAt=0:0:2 to UpdatedAt=0:0:12 expectedCount = 3; Add(source, GetThing(2, 12)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(2, 12), GetThing(1, 10), }); // testing INSERT expectedCount = 4; Add(source, GetThing(3, 11)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(2, 12), GetThing(3, 11), GetThing(1, 10), }); // testing INSERT expectedCount = 7; Add(source, GetThing(4, 5)); Add(source, GetThing(5, 14)); Add(source, GetThing(6, 13)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(2, 12), GetThing(3, 11), GetThing(1, 10), }); // testing MOVE from top to middle expectedCount = 8; Add(source, GetThing(5, 5)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(2, 12), GetThing(3, 11), GetThing(1, 10), }); // testing MOVE from top to bottom expectedCount = 9; Add(source, GetThing(6, 4)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(2, 12), GetThing(3, 11), GetThing(1, 10), }); // testing MOVE from bottom to top expectedCount = 10; Add(source, GetThing(6, 14)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(2, 12), GetThing(3, 11), GetThing(1, 10), }); // testing MOVE from middle bottom to middle top expectedCount = 11; Add(source, GetThing(3, 14)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(2, 12), GetThing(1, 10), }); // testing MOVE from middle top to middle bottom expectedCount = 12; Add(source, GetThing(2, 9)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(1, 10), GetThing(2, 9), }); // testing MOVE from middle bottom to middle top more than 1 position expectedCount = 13; Add(source, GetThing(5, 12)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(5, 12), GetThing(1, 10), GetThing(2, 9), }); expectedCount = 14; col.RemoveItem(GetThing(1, 10)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(5, 12), GetThing(2, 9), }); col.Dispose(); }
public void ChangingItemContentRemovesItFromFilteredList2() { var source = new Subject<Thing>(); var now = new DateTimeOffset(0, TimeSpan.FromTicks(0)); var col = new TrackingCollection<Thing>( source, OrderedComparer<Thing>.OrderBy(x => x.CreatedAt).Compare, (item, position, list) => item.UpdatedAt > now + TimeSpan.FromMinutes(2) && item.UpdatedAt < now + TimeSpan.FromMinutes(8)) { ProcessingDelay = TimeSpan.Zero }; var count = 0; var expectedCount = 0; var evt = new ManualResetEvent(false); col.Subscribe(t => { if (++count == expectedCount) evt.Set(); }, () => { }); expectedCount = 5; Add(source, GetThing(1, 1, 1)); Add(source, GetThing(3, 3, 3)); Add(source, GetThing(5, 5, 5)); Add(source, GetThing(7, 7, 7)); Add(source, GetThing(9, 9, 9)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(3, 3, 3), GetThing(5, 5, 5), GetThing(7, 7, 7), }); expectedCount = 6; Add(source, GetThing(7, 7, 8)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(3, 3, 3), GetThing(5, 5, 5), }); expectedCount = 7; Add(source, GetThing(7, 7, 7)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(3, 3, 3), GetThing(5, 5, 5), GetThing(7, 7, 7), }); expectedCount = 8; Add(source, GetThing(3, 3, 2)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(5, 5, 5), GetThing(7, 7, 7), }); expectedCount = 9; Add(source, GetThing(3, 3, 3)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(3, 3, 3), GetThing(5, 5, 5), GetThing(7, 7, 7), }); expectedCount = 10; Add(source, GetThing(5, 5, 1)); evt.WaitOne(); evt.Reset(); CollectionAssert.AreEqual(col, new List<Thing> { GetThing(3, 3, 3), GetThing(7, 7, 7), }); col.Dispose(); }