예제 #1
0
        public void SignWebHookRequest_HandlesNullWebHook()
        {
            WebHookWorkItem workItem = CreateWorkItem();
            HttpRequestMessage request = new HttpRequestMessage();
            _sender = new WebHookSenderMock(_loggerMock.Object);
            JObject body = _sender.CreateWebHookRequestBody(workItem);
            workItem.WebHook = null;

            // Act
            ArgumentException ex = Assert.Throws<ArgumentException>(() => _sender.SignWebHookRequest(workItem, request, body));

            // Assert
            Assert.StartsWith("Invalid 'WebHookSenderMock' instance: 'WebHook' cannot be null.", ex.Message);
        }
예제 #2
0
        public void SignWebHookRequest_HandlesNullWebHook()
        {
            WebHookWorkItem    workItem = CreateWorkItem();
            HttpRequestMessage request  = new HttpRequestMessage();

            _sender = new WebHookSenderMock(_loggerMock.Object);
            JObject body = _sender.CreateWebHookRequestBody(workItem);

            workItem.WebHook = null;

            // Act
            ArgumentException ex = Assert.Throws <ArgumentException>(() => _sender.SignWebHookRequest(workItem, request, body));

            // Assert
            Assert.StartsWith("Invalid 'WebHookSenderMock' instance: 'WebHook' cannot be null.", ex.Message);
        }
예제 #3
0
        public async Task SignWebHookRequest_SignsBodyCorrectly()
        {
            // Arrange
            WebHookWorkItem workItem = CreateWorkItem();
            HttpRequestMessage request = new HttpRequestMessage();
            _sender = new WebHookSenderMock(_loggerMock.Object);
            JObject body = _sender.CreateWebHookRequestBody(workItem);

            // Act
            _sender.SignWebHookRequest(workItem, request, body);

            // Assert
            IEnumerable<string> signature;
            request.Headers.TryGetValues("ms-signature", out signature);
            Assert.Equal(WebHookSignature, signature.Single());

            string requestBody = await request.Content.ReadAsStringAsync();
            Assert.Equal(SerializedWebHook, requestBody);

            Assert.Equal("application/json; charset=utf-8", request.Content.Headers.ContentType.ToString());
        }
예제 #4
0
        public async Task SignWebHookRequest_SignsBodyCorrectly()
        {
            // Arrange
            WebHookWorkItem    workItem = CreateWorkItem();
            HttpRequestMessage request  = new HttpRequestMessage();

            _sender = new WebHookSenderMock(_loggerMock.Object);
            JObject body = _sender.CreateWebHookRequestBody(workItem);

            // Act
            _sender.SignWebHookRequest(workItem, request, body);

            // Assert
            IEnumerable <string> signature;

            request.Headers.TryGetValues("ms-signature", out signature);
            Assert.Equal(WebHookSignature, signature.Single());

            string requestBody = await request.Content.ReadAsStringAsync();

            Assert.Equal(SerializedWebHook, requestBody);

            Assert.Equal("application/json; charset=utf-8", request.Content.Headers.ContentType.ToString());
        }