public void HandleSubscriptionValidationEventThrowsWhenInvalidJsonProvided() { // arrange const string requestBody = "invalidjson"; var service = new EventGridSubscriberService(); // act and assert Assert.Throws <JsonReaderException>(() => service.HandleSubscriptionValidationEvent(requestBody, default)); }
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); }
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)); }
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); }
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); }