コード例 #1
0
        public async Task ExecuteAsync_Dispatches_TeamRoomMessagePosted()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.message.posted.json", "message.posted");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // Assert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<TeamRoomMessagePostedPayload>()), Times.Once());
        }
コード例 #2
0
        public async Task ExecuteAsync_Dispatches_WorkItemCommentedOn()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.workitem.commented.json", "workitem.commented");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // Assert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<WorkItemCommentedOnPayload>()), Times.Once());
        }
コード例 #3
0
        public async Task ExecuteAsync_Dispatches_BuildCompleted()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.build.complete.json", "build.complete");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // Assert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<BuildCompletedPayload>()), Times.Once());
        }
コード例 #4
0
        public async Task ExecuteAsync_Dispatches_CodeCheckedIn()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.tfvc.checkin.json", "tfvc.checkin");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // Assert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<CodeCheckedInPayload>()), Times.Once());
        }
コード例 #5
0
        public async Task ExecuteAsync_Dispatches_PackageDeleted()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.PackageDeletedMessage.json", "PackageDeletedWebHookEventPayloadV1");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // Assert
            _handlerMock.Verify(h => h.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<PackageDeletedPayload>()), Times.Once());
        }
コード例 #6
0
        public async Task ExecuteAsync_Handles_NoPayloadProperty()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.NoPayloadMessage.json", "None");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // Assert
            HttpError error = await _context.Response.Content.ReadAsAsync<HttpError>();
            Assert.Equal("The WebHook request must contain a 'Payload' JSON property containing the event payload.", error.Message);
        }
コード例 #7
0
 public override void UnknownEvent(WebHookHandlerContext context, JObject payload)
 {
     context.RequestContext.Configuration.DependencyResolver.GetLogger().Info($"Unknown event");
 }
コード例 #8
0
 public override void ClientEvent(WebHookHandlerContext context, ClientEventPayload payload)
 {
     context.RequestContext.Configuration.DependencyResolver.GetLogger().Info($"Client event");
 }
コード例 #9
0
 public override void MemberRemoved(WebHookHandlerContext context, MemberRemovedPayload payload)
 {
     context.RequestContext.Configuration.DependencyResolver.GetLogger().Info($"Member {payload.UserId} removed from channel {payload.Channel}");
 }
コード例 #10
0
        public override async Task ExecuteAsync(string generator, WebHookHandlerContext context)
        {
            var content = await context.Request.Content.ReadAsStringAsync();

            Trace.WriteLine(string.Format("Generator: {0} - Content: {1}", generator, content));
        }
コード例 #11
0
        public async Task ExecuteAsync_Handles_UnknownPayloadProperty()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.UnknownMessage.json", "Unknown");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // Assert
            _handlerMock.Verify(h => h.ExecuteUnknownPayloadAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<JObject>()), Times.Once());
        }
コード例 #12
0
        public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
        {
            // For more information about Slack WebHook payloads, please see
            // 'https://api.slack.com/outgoing-webhooks'
            NameValueCollection command = context.GetDataOrDefault <NameValueCollection>();

            // We can trace to see what is going on.
            Trace.WriteLine(command.ToString());

            // Switch over the IDs we used when configuring this WebHook
            switch (context.Id)
            {
            case "trigger":
                // Parse the trigger text of the form 'action parameters'.
                var triggerCommand = SlackCommand.ParseActionWithValue(command["subtext"]);

                // Information can be returned using a SlackResponse
                string reply1 = string.Format(
                    "Received trigger '{0}' with action '{1}' and value '{2}'",
                    command["trigger_word"],
                    triggerCommand.Key,
                    triggerCommand.Value);
                var triggerReply = new SlackResponse(reply1);
                context.Response = context.Request.CreateResponse(triggerReply);
                break;

            case "slash":
                // Parse the slash text of the form 'action p1=v1; p2=v2; ...'.
                var slashCommand = SlackCommand.ParseActionWithParameters(command["text"]);

                string reply2 = string.Format(
                    "Received slash command '{0}' with action '{1}' and value '{2}'",
                    command["command"],
                    slashCommand.Key,
                    slashCommand.Value.ToString());

                // Information can be returned using a SlackSlashResponse with attachments
                var slashReply = new SlackSlashResponse(reply2);

                // Slash replies can be augmented with attachments containing data, images, and more
                var att = new SlackAttachment("Attachment Text", "Fallback description")
                {
                    Color   = "#439FE0",
                    Pretext = "Hello from ASP.NET WebHooks!",
                    Title   = "Attachment title",
                };

                // Slash attachments can contain tabular data as well
                att.Fields.Add(new SlackField("Field1", "1234"));
                att.Fields.Add(new SlackField("Field2", "5678"));

                // A reply can contain multiple attachments
                slashReply.Attachments.Add(att);

                // Return slash command response
                context.Response = context.Request.CreateResponse(slashReply);
                break;
            }

            return(Task.FromResult(true));
        }
コード例 #13
0
 public override Task ExecuteAsync(WebHookHandlerContext context, GitPullRequestUpdatedPayload payload)
 {
     return(_updatedPullRequestHandler.Handle(payload));
 }
コード例 #14
0
    public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
    {
        CustomNotifications notifications = context.GetDataOrDefault <CustomNotifications>();

        foreach (var notification in notifications.Notifications)
        {
コード例 #15
0
 public override void ChannelOccupied(WebHookHandlerContext context, ChannelOccupiedPayload payload)
 {
     context.RequestContext.Configuration.DependencyResolver.GetLogger().Info($"Channel {payload.Channel} is occupied");
 }
コード例 #16
0
        public async Task ExecuteAsync_Dispatches_GitPullRequestUpdated()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.git.pullrequest.updated.json", "git.pullrequest.created");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // Assert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<GitPullRequestCreatedPayload>()), Times.Once());
        }
コード例 #17
0
        public async Task ExecuteAsync_Handles_UnknownEventType()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.bad.notMappedEventType.json", "unknown");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // Assert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<JObject>()), Times.Once());
        }
コード例 #18
0
 public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
 {
     WebHookCounter.AddToCount();
     return(Task.CompletedTask);
 }
コード例 #19
0
 /// <summary>
 /// This one processes the <see cref="PackageDeletedPayload"/> WebHook.
 /// </summary>
 public override Task ExecuteAsync(string receiver, WebHookHandlerContext context, PackageDeletedPayload payload)
 {
     return(Task.FromResult(true));
 }
コード例 #20
0
 public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
 {
     return(Task.FromResult(true));
 }
コード例 #21
0
        private static object GetWebHookData(Type dataType, WebHookHandlerContext context)
        {
            MethodInfo getDataMethod = _getWebHookDataMethod.Value.MakeGenericMethod(dataType);

            return(getDataMethod.Invoke(null, new object[] { context }));
        }
コード例 #22
0
        public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
        {
            GithubPayload payload = GetPayload(context);

            return(Task.WhenAll(_notifierProvider.Provide().Select(n => n.Notify(payload))));
        }
コード例 #23
0
        public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
        {
            IWebSubContent content = context.Data as IWebSubContent;

            return(Task.FromResult(true));
        }
コード例 #24
0
        private static GithubPayload GetPayload(WebHookHandlerContext context)
        {
            var json = context.GetDataOrDefault <JObject>();

            return(json.ToObject <GithubPayload>());
        }
コード例 #25
0
 public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
 {
     // Console.WriteLine("Received notification with payload:");
     SetWebHookData(context);
     return(Task.FromResult(true));
 }
コード例 #26
0
    public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
    {
        JObject entry = context.GetDataOrDefault <JObject>();

        return(Task.FromResult(true));
    }