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;
        }
Пример #2
0
        /// <summary>
        /// Validates the specified instance asynchronously.
        /// </summary>
        /// <param name="context">Validation Context</param>
        /// <returns>A ValidationResult object containing any validation failures.</returns>
        public virtual Task <ValidationResult> ValidateAsync(ValidationContext <T> context)
        {
            context.Guard("Cannot pass null to Validate");
            var failures = new List <ValidationFailure>();

            return(TaskHelpers.Iterate(
                       nestedValidators
                       .Select(v => v.ValidateAsync(context).Then(fs => failures.AddRange(fs), runSynchronously: true)))
                   .Then(() => new ValidationResult(failures)
                         ));
        }
Пример #3
0
        public async Task NonExpiredIndexReturnsCache()
        {
            var expected = 5;

            var username = "******";
            var reponame = "repo";

            var cache        = new InMemoryBlobCache();
            var apiClient    = Substitute.For <IApiClient>();
            var modelService = new ModelService(apiClient, cache, Substitute.For <IAvatarProvider>());
            var user         = CreateOctokitUser(username);

            apiClient.GetUser().Returns(Observable.Return(new UserAndScopes(user, null)));
            apiClient.GetOrganizations().Returns(Observable.Empty <Organization>());
            var act = modelService.GetAccounts().ToEnumerable().First().First();

            var repo = Substitute.For <ILocalRepositoryModel>();

            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;

            Assert.Equal(expected, col.Count);
            Assert.Collection(col, col.Select(x => new Action <IPullRequestModel>(t => Assert.True(x.Title.StartsWith("Cache")))).ToArray());
        }
Пример #4
0
        /// <summary>
        /// Validates the specified instance asynchronously.
        /// </summary>
        /// <param name="context">Validation Context</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns>A ValidationResult object containing any validation failures.</returns>
        public virtual Task <ValidationResult> ValidateAsync(ValidationContext <T> context, CancellationToken cancellation = new CancellationToken())
        {
            context.Guard("Cannot pass null to Validate");
            context.InstanceToValidate.Guard("Cannot pass null model to ValidateAsync.");

            if (Request == null)
            {
                Request = context.Request;
            }

            var failures = new List <ValidationFailure>();

            return(TaskHelpers.Iterate(
                       nestedValidators
                       .Select(v => v.ValidateAsync(context, cancellation).Then(fs => failures.AddRange(fs), runSynchronously: true))
                       ).Then(
                       () => new ValidationResult(failures)
            {
                Request = Request
            }
                       ));
        }
Пример #5
0
        public async Task ExpiredIndexReturnsLive()
        {
            var expected = 5;

            var username = "******";
            var reponame = "repo";

            var cache        = new InMemoryBlobCache();
            var apiClient    = Substitute.For <IApiClient>();
            var modelService = new ModelService(apiClient, cache, Substitute.For <IAvatarProvider>());
            var user         = CreateOctokitUser(username);

            apiClient.GetUser().Returns(Observable.Return(new UserAndScopes(user, null)));
            apiClient.GetOrganizations().Returns(Observable.Empty <Organization>());
            var act = modelService.GetAccounts().ToEnumerable().First().First();

            var repo = Substitute.For <ISimpleRepositoryModel>();

            repo.Name.Returns(reponame);
            repo.CloneUrl.Returns(new UriString("https://github.com/" + username + "/" + reponame));

            var indexKey = string.Format(CultureInfo.InvariantCulture, "{0}|{1}|pr", user.Login, repo.Name);

            var prcache = Enumerable.Range(1, expected)
                          .Select(id => CreatePullRequest(user, id, ItemState.Open, "Cache " + id, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow, 0));

            // seed the cache
            prcache
            .Select(item => new ModelService.PullRequestCacheItem(item))
            .Select(item => item.Save <ModelService.PullRequestCacheItem>(cache, indexKey).ToEnumerable().First())
            .SelectMany(item => CacheIndex.AddAndSaveToIndex(cache, indexKey, item).ToEnumerable())
            .ToList();

            // expire the index
            var indexobj = await cache.GetObject <CacheIndex>(indexKey);

            indexobj.UpdatedAt = DateTimeOffset.UtcNow - TimeSpan.FromMinutes(6);
            await cache.InsertObject(indexKey, indexobj);

            var prlive = Observable.Range(1, expected)
                         .Select(id => CreatePullRequest(user, id, ItemState.Open, "Live " + id, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow, 0))
                         .DelaySubscription(TimeSpan.FromMilliseconds(10));

            apiClient.GetPullRequestsForRepository(user.Login, repo.Name).Returns(prlive);

            await modelService.InsertUser(new AccountCacheItem(user));

            ITrackingCollection <IPullRequestModel> col = new TrackingCollection <IPullRequestModel>();

            col = modelService.GetPullRequests(repo, col);
            col.ProcessingDelay = TimeSpan.Zero;

            var count = 0;
            var done  = new Subject <Unit>();

            done.Subscribe();

            col.Subscribe(t =>
            {
                if (++count == expected * 2)
                {
                    done.OnNext(Unit.Default);
                    done.OnCompleted();
                }
            }, () => { });

            await done;

            Assert.Collection(col, col.Select(x => new Action <IPullRequestModel>(t => Assert.True(x.Title.StartsWith("Live")))).ToArray());
        }
Пример #6
0
        public async Task ExpiredIndexReturnsLive()
        {
            var expected = 5;

            var username = "******";
            var reponame = "repo";

            var cache = new InMemoryBlobCache();
            var apiClient = Substitute.For<IApiClient>();
            var modelService = new ModelService(apiClient, cache, Substitute.For<IAvatarProvider>());
            var user = CreateOctokitUser(username);
            apiClient.GetUser().Returns(Observable.Return(new UserAndScopes(user, null)));
            apiClient.GetOrganizations().Returns(Observable.Empty<Organization>());
            var act = modelService.GetAccounts().ToEnumerable().First().First();

            var repo = Substitute.For<ILocalRepositoryModel>();
            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 ModelService.PullRequestCacheItem(item))
                .Select(item => item.Save<ModelService.PullRequestCacheItem>(cache, indexKey).ToEnumerable().First())
                .SelectMany(item => CacheIndex.AddAndSaveToIndex(cache, indexKey, item).ToEnumerable())
                .ToList();

            // expire the index
            var indexobj = await cache.GetObject<CacheIndex>(indexKey);
            indexobj.UpdatedAt = DateTimeOffset.UtcNow - TimeSpan.FromMinutes(6);
            await cache.InsertObject(indexKey, indexobj);

            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;

            var count = 0;
            var done = new ReplaySubject<Unit>();
            done.OnNext(Unit.Default);
            done.Subscribe();

            col.Subscribe(t =>
            {
                if (++count == expected * 2)
                {
                    done.OnCompleted();
                }
            }, () => { });

            await done;

            Assert.Collection(col, col.Select(x => new Action<IPullRequestModel>(t => Assert.True(x.Title.StartsWith("Live")))).ToArray());
        }