コード例 #1
0
        private static async Task <T> ConvertAndDeserialize <T>(string resourceName) where T : class
        {
            var context    = GcfEventResources.CreateHttpContext(resourceName);
            var cloudEvent = await GcfConverters.ConvertGcfEventToCloudEvent(context.Request);

            return(CloudEventConverters.ConvertCloudEventData <T>(cloudEvent));
        }
コード例 #2
0
        public async Task ConvertGcfEvent(string resourceName, string expectedType, string expectedSource)
        {
            var context    = GcfEventResources.CreateHttpContext(resourceName);
            var cloudEvent = await GcfConverters.ConvertGcfEventToCloudEvent(context.Request);

            Assert.Equal(expectedType, cloudEvent.Type);
            Assert.Equal(new Uri(expectedSource), cloudEvent.Source);
        }
        public async Task ConvertGcfEvent(string resourceName, string expectedType, string expectedSource, string expectedSubject)
        {
            var context    = GcfEventResources.CreateHttpContext(resourceName);
            var cloudEvent = await GcfConverters.ConvertGcfEventToCloudEvent(context.Request, s_jsonFormatter);

            Assert.Equal(expectedType, cloudEvent.Type);
            Assert.Equal(expectedSource, cloudEvent.Source.ToString());
            Assert.Equal(expectedSubject, cloudEvent.Subject);
        }
コード例 #4
0
        private static async Task <T> ConvertAndDeserialize <T>(string resourceName) where T : class
        {
            var context   = GcfEventResources.CreateHttpContext(resourceName);
            var formatter = CloudEventFormatterAttribute.CreateFormatter(typeof(T))
                            ?? throw new InvalidOperationException("No formatter available");
            var cloudEvent = await GcfConverters.ConvertGcfEventToCloudEvent(context.Request, formatter);

            return((T)cloudEvent.Data);
        }
コード例 #5
0
        public async Task ConvertGcfEvent_ExtensionAttributes(string resourceName, string extensionAttributeName, string expectedValue)
        {
            var context    = GcfEventResources.CreateHttpContext(resourceName);
            var cloudEvent = await GcfConverters.ConvertGcfEventToCloudEvent(context.Request, s_jsonFormatter);

            var attributeValue = (string)cloudEvent[extensionAttributeName];

            Assert.Equal(expectedValue, attributeValue);
        }
コード例 #6
0
        public async Task PubSubTimeStampPrecision(string resourceName, string expectedPublishTime)
        {
            var context    = GcfEventResources.CreateHttpContext(resourceName);
            var cloudEvent = await GcfConverters.ConvertGcfEventToCloudEvent(context.Request, s_jsonFormatter);

            var data = (JsonElement)cloudEvent.Data;
            var actualPublishTime = data.GetProperty("message").GetProperty("publishTime").GetString();

            Assert.Equal(expectedPublishTime, actualPublishTime);
        }
        public async Task CheckAllProperties()
        {
            var context    = GcfEventResources.CreateHttpContext("storage.json");
            var cloudEvent = await GcfConverters.ConvertGcfEventToCloudEvent(context.Request, s_jsonFormatter);

            Assert.Equal("application/json", cloudEvent.DataContentType);
            Assert.Equal("1147091835525187", cloudEvent.Id);
            Assert.Equal("google.cloud.storage.object.v1.finalized", cloudEvent.Type);
            Assert.Equal(new DateTimeOffset(2020, 4, 23, 7, 38, 57, 772, TimeSpan.Zero), cloudEvent.Time);
            Assert.Equal("//storage.googleapis.com/projects/_/buckets/some-bucket", cloudEvent.Source.ToString());
            Assert.Equal("objects/folder/Test.cs", cloudEvent.Subject);
            Assert.Equal(CloudEventsSpecVersion.V1_0, cloudEvent.SpecVersion);
            Assert.Null(cloudEvent.DataSchema);
            Assert.IsType <JsonElement>(cloudEvent.Data);
        }
コード例 #8
0
        public async Task CheckAllProperties()
        {
            var context    = GcfEventResources.CreateHttpContext("storage.json");
            var cloudEvent = await GcfConverters.ConvertGcfEventToCloudEvent(context.Request);

            Assert.Equal("application/json", cloudEvent.DataContentType.MediaType);
            Assert.Equal("1147091835525187", cloudEvent.Id);
            Assert.Equal("com.google.cloud.storage.object.finalize.v0", cloudEvent.Type);
            Assert.Equal(new DateTime(2020, 4, 23, 7, 38, 57, 772), cloudEvent.Time);
            Assert.Equal(new Uri("//storage.googleapis.com/projects/_/buckets/some-bucket/objects/Test.cs"), cloudEvent.Source);
            Assert.Equal(CloudEventsSpecVersion.V1_0, cloudEvent.SpecVersion);
            Assert.Null(cloudEvent.Subject);
            Assert.Null(cloudEvent.DataSchema);
            Assert.IsType <string>(cloudEvent.Data);
        }
 public async Task InvalidRequest_FirebaseAnalytics(string resourceName)
 {
     var context = GcfEventResources.CreateHttpContext(resourceName);
     await Assert.ThrowsAsync <GcfConverters.ConversionException>(() => GcfConverters.ConvertGcfEventToCloudEvent(context.Request, s_jsonFormatter));
 }