示例#1
0
        public void HandleSubscriptionValidationEventThrowsWhenInvalidJsonProvided()
        {
            // arrange
            const string requestBody = "invalidjson";
            var          service     = new EventGridSubscriberService();

            // act and assert
            Assert.Throws <JsonReaderException>(() => service.HandleSubscriptionValidationEvent(requestBody, default));
        }
示例#2
0
        public void HandleSubscriptionValidationEventReturnsNullWhenNotSubscriptionValidationEvent()
        {
            // arrange
            const string requestBody = "[{\r\n  \"id\": \"2d1781af-3a4c-4d7c-bd0c-e34b19da4e66\",\r\n  \"topic\": \"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\r\n  \"subject\": \"\",\r\n  \"data\": {},\r\n  \"eventType\": \"Custom\",\r\n  \"eventTime\": \"2018-01-25T22:12:19.4556811Z\",\r\n  \"metadataVersion\": \"1\",\r\n  \"dataVersion\": \"1\"\r\n}]";
            var          service     = new EventGridSubscriberService();

            // act
            var result = service.HandleSubscriptionValidationEvent(requestBody, default);

            // assert
            Assert.Null(result);
        }
示例#3
0
        public void HandleSubscriptionValidationEvent_ThrowsWhenInvalidJsonProvided()
        {
            // arrange
            var requestBody = "invalidjson";
            var req         = new DefaultHttpRequest(new DefaultHttpContext())
            {
                Body = GetStreamFromString(requestBody)
            };
            var service = new EventGridSubscriberService();

            // act and assert
            Assert.Throws <JsonReaderException>(() => service.HandleSubscriptionValidationEvent(req));
        }
示例#4
0
        public void HandleSubscriptionValidationEventReturnsValidationResponse()
        {
            // arrange
            const string requestBody = "[{\r\n  \"id\": \"2d1781af-3a4c-4d7c-bd0c-e34b19da4e66\",\r\n  \"topic\": \"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\r\n  \"subject\": \"\",\r\n  \"data\": {\r\n    \"validationCode\": \"512d38b6-c7b8-40c8-89fe-f46f9e9622b6\"\r\n  },\r\n  \"eventType\": \"Microsoft.EventGrid.SubscriptionValidationEvent\",\r\n  \"eventTime\": \"2018-01-25T22:12:19.4556811Z\",\r\n  \"metadataVersion\": \"1\",\r\n  \"dataVersion\": \"1\"\r\n}]";
            var          headers     = new StringValues("SubscriptionValidation");

            var service = new EventGridSubscriberService();

            // act
            var result = service.HandleSubscriptionValidationEvent(requestBody, headers);

            // assert
            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            dynamic dynamicallyTypedResult = ((OkObjectResult)result).Value;

            Assert.Equal("512d38b6-c7b8-40c8-89fe-f46f9e9622b6", (string)dynamicallyTypedResult.validationResponse);
        }
示例#5
0
        public void HandleSubscriptionValidationEvent_ReturnsValidationResponse()
        {
            // arrange
            var requestBody = "[{\r\n  \"id\": \"2d1781af-3a4c-4d7c-bd0c-e34b19da4e66\",\r\n  \"topic\": \"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\r\n  \"subject\": \"\",\r\n  \"data\": {\r\n    \"validationCode\": \"512d38b6-c7b8-40c8-89fe-f46f9e9622b6\"\r\n  },\r\n  \"eventType\": \"Microsoft.EventGrid.SubscriptionValidationEvent\",\r\n  \"eventTime\": \"2018-01-25T22:12:19.4556811Z\",\r\n  \"metadataVersion\": \"1\",\r\n  \"dataVersion\": \"1\"\r\n}]";
            var req         = new DefaultHttpRequest(new DefaultHttpContext())
            {
                Body    = GetStreamFromString(requestBody),
                Headers =
                {
                    new KeyValuePair <string, StringValues>(EventGridSubscriberService.EventGridSubscriptionValidationHeaderKey, new StringValues("SubscriptionValidation"))
                }
            };
            var service = new EventGridSubscriberService();

            // act
            var result = service.HandleSubscriptionValidationEvent(req);

            // assert
            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            dynamic dynamicallyTypedResult = ((OkObjectResult)result).Value;

            Assert.Equal("512d38b6-c7b8-40c8-89fe-f46f9e9622b6", (string)dynamicallyTypedResult.validationResponse);
        }