Пример #1
0
        static PullRequestReviewCommentViewModel CreateTarget(
            IPullRequestSession session           = null,
            ICommentService commentService        = null,
            ICommentThreadViewModel thread        = null,
            ActorModel currentUser                = null,
            PullRequestReviewModel review         = null,
            PullRequestReviewCommentModel comment = null)
        {
            session        = session ?? CreateSession();
            commentService = commentService ?? Substitute.For <ICommentService>();
            thread         = thread ?? CreateThread();
            currentUser    = currentUser ?? new ActorModel {
                Login = "******"
            };
            comment = comment ?? new PullRequestReviewCommentModel();
            review  = review ?? CreateReview(comment);

            return(new PullRequestReviewCommentViewModel(
                       session,
                       commentService,
                       thread,
                       new ActorViewModel(currentUser),
                       review,
                       comment));
        }
        async Task <PullRequestReviewCommentThreadViewModel> CreateTarget(
            IMessageDraftStore draftStore             = null,
            IViewViewModelFactory factory             = null,
            IPullRequestSession session               = null,
            IPullRequestSessionFile file              = null,
            PullRequestReviewModel review             = null,
            IEnumerable <InlineCommentModel> comments = null,
            bool newThread = false)
        {
            draftStore = draftStore ?? Substitute.For <IMessageDraftStore>();
            factory    = factory ?? CreateFactory();
            session    = session ?? CreateSession();
            file       = file ?? CreateFile();
            review     = review ?? new PullRequestReviewModel();
            comments   = comments ?? CreateComments();

            var result = new PullRequestReviewCommentThreadViewModel(draftStore, factory);

            if (newThread)
            {
                await result.InitializeNewAsync(session, file, 10, DiffSide.Right, true);
            }
            else
            {
                var thread = Substitute.For <IInlineCommentThreadModel>();
                thread.Comments.Returns(comments.ToList());
                thread.LineNumber.Returns(10);

                await result.InitializeAsync(session, file, review, thread, true);
            }

            return(result);
        }
 static InlineCommentModel CreateReviewComment(PullRequestReviewModel review)
 {
     return(new InlineCommentModel
     {
         Review = review,
         Comment = new PullRequestReviewCommentModel(),
     });
 }
        public PullRequestReviewViewModelDesigner()
        {
            PullRequestModel = new PullRequestDetailModel
            {
                Number = 419,
                Title  = "Fix a ton of potential crashers, odd code and redundant calls in ModelService",
                Author = new ActorModel {
                    Login = "******"
                },
                UpdatedAt = DateTimeOffset.Now - TimeSpan.FromDays(2),
            };

            Model = new PullRequestReviewModel
            {
                SubmittedAt = DateTimeOffset.Now - TimeSpan.FromDays(1),
                Author      = new ActorModel {
                    Login = "******"
                },
            };

            Body = @"Just a few comments. I don't feel too strongly about them though.

Otherwise, very nice work here! ✨";

            StateDisplay = "approved";

            FileComments = new[]
            {
                new PullRequestReviewFileCommentViewModelDesigner
                {
                    Body         = @"These should probably be properties. Most likely they should be readonly properties. I know that makes creating instances of these not look as nice as using property initializers when constructing an instance, but if these properties should never be mutated after construction, then it guides future consumers to the right behavior.

However, if you're two-way binding these properties to a UI, then ignore the readonly part and make them properties. But in that case they should probably be reactive properties (or implement INPC).",
                    RelativePath = "src/GitHub.Exports.Reactive/ViewModels/IPullRequestListViewModel.cs",
                },
                new PullRequestReviewFileCommentViewModelDesigner
                {
                    Body         = "While I have no problems with naming a variable ass I think we should probably avoid swear words in case Microsoft runs their Policheck tool against this code.",
                    RelativePath = "src/GitHub.App/ViewModels/PullRequestListViewModel.cs",
                },
            };

            OutdatedFileComments = new[]
            {
                new PullRequestReviewFileCommentViewModelDesigner
                {
                    Body         = @"So this is just casting a mutable list to an IReadOnlyList which can be cast back to List. I know we probably won't do that, but I'm thinking of the next person to come along. The safe thing to do is to wrap List with a ReadOnlyList. We have an extension method ToReadOnlyList for observables. Wouldn't be hard to write one for IEnumerable.",
                    RelativePath = "src/GitHub.Exports.Reactive/ViewModels/IPullRequestListViewModel.cs",
                },
            };
        }
        /// <inheritdoc/>
        public async Task InitializeAsync(
            IPullRequestSession session,
            ICommentThreadViewModel thread,
            PullRequestReviewModel review,
            PullRequestReviewCommentModel comment,
            CommentEditState state)
        {
            Guard.ArgumentNotNull(session, nameof(session));

            await InitializeAsync(thread, session.User, comment, state).ConfigureAwait(true);

            this.session = session;
            IsPending    = review.State == PullRequestReviewState.Pending;
        }
Пример #6
0
        PullRequestReviewViewModel CreateTarget(
            IPullRequestEditorService editorService = null,
            IPullRequestSession session             = null,
            PullRequestDetailModel pullRequest      = null,
            PullRequestReviewModel model            = null)
        {
            editorService = editorService ?? Substitute.For <IPullRequestEditorService>();
            session       = session ?? Substitute.For <IPullRequestSession>();
            pullRequest   = pullRequest ?? CreatePullRequest();
            model         = model ?? pullRequest.Reviews[0];

            return(new PullRequestReviewViewModel(
                       editorService,
                       session,
                       model));
        }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PullRequestReviewViewModel"/> class.
        /// </summary>
        /// <param name="editorService">The pull request editor service.</param>
        /// <param name="session">The pull request session.</param>
        /// <param name="model">The pull request review model.</param>
        public PullRequestReviewViewModel(
            IPullRequestEditorService editorService,
            IPullRequestSession session,
            PullRequestReviewModel model)
        {
            Guard.ArgumentNotNull(editorService, nameof(editorService));
            Guard.ArgumentNotNull(session, nameof(session));
            Guard.ArgumentNotNull(model, nameof(model));

            Model        = model;
            Body         = string.IsNullOrWhiteSpace(Model.Body) ? null : Model.Body;
            StateDisplay = ToString(Model.State);

            var comments = new List <IPullRequestReviewFileCommentViewModel>();
            var outdated = new List <IPullRequestReviewFileCommentViewModel>();

            foreach (var comment in model.Comments)
            {
                if (comment.Thread != null)
                {
                    var vm = new PullRequestReviewCommentViewModel(
                        editorService,
                        session,
                        comment.Thread.Path,
                        comment);

                    if (comment.Thread.Position != null)
                    {
                        comments.Add(vm);
                    }
                    else
                    {
                        outdated.Add(vm);
                    }
                }
            }

            FileComments         = comments;
            OutdatedFileComments = outdated;

            HasDetails = Body != null ||
                         FileComments.Count > 0 ||
                         OutdatedFileComments.Count > 0;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PullRequestReviewCommentViewModel"/> class.
 /// </summary>
 /// <param name="session">The pull request session.</param>
 /// <param name="thread">The thread that the comment is a part of.</param>
 /// <param name="currentUser">The current user.</param>
 /// <param name="model">The comment model.</param>
 public PullRequestReviewCommentViewModel(
     IPullRequestSession session,
     ICommentThreadViewModel thread,
     IActorViewModel currentUser,
     PullRequestReviewModel review,
     PullRequestReviewCommentModel model)
     : this(
         session,
         thread,
         currentUser,
         model.Id,
         model.Body,
         CommentEditState.None,
         new ActorViewModel(model.Author),
         model.CreatedAt,
         review.State == PullRequestReviewState.Pending,
         model.Url != null ? new Uri(model.Url) : null)
 {
 }
        static async Task <PullRequestReviewCommentViewModel> CreateTarget(
            IPullRequestSession session           = null,
            ICommentService commentService        = null,
            ICommentThreadViewModel thread        = null,
            ActorModel currentUser                = null,
            PullRequestReviewModel review         = null,
            PullRequestReviewCommentModel comment = null)
        {
            session        = session ?? CreateSession();
            commentService = commentService ?? Substitute.For <ICommentService>();
            thread         = thread ?? CreateThread();
            currentUser    = currentUser ?? new ActorModel {
                Login = "******"
            };
            comment = comment ?? new PullRequestReviewCommentModel();
            review  = review ?? CreateReview(PullRequestReviewState.Approved, comment);

            var result = new PullRequestReviewCommentViewModel(commentService);
            await result.InitializeAsync(session, thread, review, comment, CommentEditState.None);

            return(result);
        }
Пример #10
0
        async Task <PullRequestReviewCommentThreadViewModel> CreateTarget(
            IViewViewModelFactory factory             = null,
            IPullRequestSession session               = null,
            IPullRequestSessionFile file              = null,
            PullRequestReviewModel review             = null,
            IEnumerable <InlineCommentModel> comments = null)
        {
            factory  = factory ?? CreateFactory();
            session  = session ?? CreateSession();
            file     = file ?? Substitute.For <IPullRequestSessionFile>();
            review   = review ?? new PullRequestReviewModel();
            comments = comments ?? CreateComments();

            var thread = Substitute.For <IInlineCommentThreadModel>();

            thread.Comments.Returns(comments.ToList());

            var result = new PullRequestReviewCommentThreadViewModel(factory);
            await result.InitializeAsync(session, file, review, thread, true);

            return(result);
        }