Exemplo n.º 1
0
 private void ValidateApiVersion(WebhooksEvent unmarshalledEvent)
 {
     if (!"v1".Equals(unmarshalledEvent.ApiVersion))
     {
         throw new ApiVersionMismatchException(unmarshalledEvent.ApiVersion, "v1");
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Unmarshals the given body, while also validating it using the given request headers.
        /// </summary>
        /// <exception cref="SignatureValidationException">If the body could not be validated successfully.</exception>
        /// <exception cref="ApiVersionMismatchException"> If the resulting event has an API version that this version of the SDK does not support.</exception>
        public WebhooksEvent Unmarshal(byte[] body, IEnumerable <IRequestHeader> requestHeaders)
        {
            Validate(body, requestHeaders);
            WebhooksEvent unmarshalledEvent = _marshaller.Unmarshal <WebhooksEvent>(StringUtils.Encoding.GetString(body));

            ValidateApiVersion(unmarshalledEvent);
            return(unmarshalledEvent);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Unmarshals the given body, while also validating it using the given request headers.
        /// </summary>
        /// <exception cref="SignatureValidationException">If the body could not be validated successfully.</exception>
        /// <exception cref="ApiVersionMismatchException"> If the resulting event has an API version that this version of the SDK does not support.</exception>
        public WebhooksEvent Unmarshal(string body, IEnumerable <IRequestHeader> requestHeaders)
        {
            Validate(body, requestHeaders);
            WebhooksEvent unmarshalledEvent = _marshaller.Unmarshal <WebhooksEvent>(body);

            ValidateApiVersion(unmarshalledEvent);
            return(unmarshalledEvent);
        }
        public void GetWebooksEvents()
        {
            try
            {
                string wehooksResponsePayload = "{\"eventNotifications\":[{\"realmId\":\"1269959970\",\"dataChangeEvent\":{\"entities\":[{\"name\":\"Vendor\",\"id\":\"40\",\"operation\":\"Update\",\"lastUpdated\":\"2016-10-05T03:09:04.000Z\"},{\"name\":\"Customer\",\"id\":\"43\",\"operation\":\"Create\",\"lastUpdated\":\"2016-10-05T03:07:04.000Z\"}]}}]}";

                WebhooksEvent webhooksEvent = webhooksServiceTestCases.GetWebooksEvents(wehooksResponsePayload);

                Assert.AreEqual(webhooksEvent.EventNotifications[0].RealmId, "1269959970");
                Assert.AreEqual(webhooksEvent.EventNotifications[0].DataChangeEvent.Entities[0].Name, "Vendor");
            }
            catch (System.Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }