public void DefaultTypeForTrigger()
        {
            var ext  = new JArrayTriggerExtension();
            var prog = new FakeTypeLocator();
            JobHostConfiguration config = TestHelpers.NewConfig(prog, ext);
            var host = new JobHost(config);
            IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();

            var attr = new Test9Attribute(null);
            var type = metadataProvider.GetDefaultType(attr, FileAccess.Read, null);

            Assert.Equal(typeof(JArray), type);
        }
        public void DefaultTypeForOpenTypeTrigger()
        {
            var ext  = new OpenTypeTriggerExtension();
            var prog = new FakeTypeLocator();
            JobHostConfiguration config = TestHelpers.NewConfig(prog, ext);
            var host = new JobHost(config);
            IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();

            var attr = new Test9Attribute(null);
            var type = metadataProvider.GetDefaultType(attr, FileAccess.Write, null);

            // The trigger handles Open type, which means it will first pull byte[].
            Assert.Equal(typeof(byte[]), type);
        }
        public void DefaultTypeForJObjectCollector()
        {
            var ext  = new TestExtension3();
            var prog = new FakeTypeLocator();
            JobHostConfiguration config = TestHelpers.NewConfig(prog, ext);
            var host = new JobHost(config);
            IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();

            var attr = new Test9Attribute(null);
            var type = metadataProvider.GetDefaultType(attr, FileAccess.Write, null);

            // Explicitly should be Jobject since that's all the collector is registered as.
            Assert.Equal(typeof(IAsyncCollector <JObject>), type);
        }
        public void DefaultTypeForTable()
        {
            JobHostConfiguration config = TestHelpers.NewConfig();
            var host2            = new JobHost(config);
            var metadataProvider = host2.CreateMetadataProvider();

            var t1 = metadataProvider.GetDefaultType(new TableAttribute("table1"), FileAccess.Read, null);

            Assert.Equal(typeof(JArray), t1);

            var t2 = metadataProvider.GetDefaultType(new TableAttribute("table1", "pk", "rk"), FileAccess.Read, null);

            Assert.Equal(typeof(JObject), t2);

            var t3 = metadataProvider.GetDefaultType(new TableAttribute("table1"), FileAccess.Write, null);

            Assert.Equal(typeof(IAsyncCollector <JObject>), t3);
        }
示例#5
0
        public void DefaultTypeForQueue()
        {
            JobHostConfiguration config = TestHelpers.NewConfig();
            var host2            = new JobHost(config);
            var metadataProvider = host2.CreateMetadataProvider();

            var t1 = metadataProvider.GetDefaultType(new QueueAttribute("q"), FileAccess.Read, typeof(byte[]));

            Assert.Equal(typeof(byte[]), t1);

            var t2 = metadataProvider.GetDefaultType(new QueueAttribute("q"), FileAccess.Read, null);

            Assert.Equal(typeof(string), t2);

            var t3 = metadataProvider.GetDefaultType(new QueueAttribute("q"), FileAccess.Write, null);

            Assert.Equal(typeof(IAsyncCollector <byte[]>), t3);
        }
        public void DefaultType()
        {
            var config = TestHelpers.NewConfig <ConfigNullOutParam>();

            config.AddExtension(new ConfigNullOutParam()); // Registers a BindToInput rule
            var host = new JobHost(config);
            IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();

            // Getting default type.
            var attr = new TestStreamAttribute("x", FileAccess.Read);
            {
                var defaultType = metadataProvider.GetDefaultType(attr, FileAccess.Read, null);
                Assert.Equal(typeof(Stream), defaultType);
            }

            {
                var defaultType = metadataProvider.GetDefaultType(attr, FileAccess.Write, null);
                Assert.Equal(typeof(Stream), defaultType);
            }
        }
        public void DefaultTypeForQueue()
        {
            JobHostConfiguration config = TestHelpers.NewConfig();
            var host2            = new JobHost(config);
            var metadataProvider = host2.CreateMetadataProvider();

            var t1 = metadataProvider.GetDefaultType(new QueueTriggerAttribute("q"), FileAccess.Read, typeof(byte[]));

            Assert.Equal(typeof(byte[]), t1);

            var t2 = metadataProvider.GetDefaultType(new QueueTriggerAttribute("q"), FileAccess.Read, null);

            Assert.Equal(typeof(string), t2);

            // Very important that this is byte[].
            // Script doesn't require Function.json for JScript to specify datatype.
            // JScript can convert Jobject, string to byte[].
            // But can't convert byte[] to JObject.
            // so byte[] is the safest default.
            var t3 = metadataProvider.GetDefaultType(new QueueAttribute("q"), FileAccess.Write, null);

            Assert.Equal(typeof(IAsyncCollector <byte[]>), t3);
        }
        public void TestMetadata()
        {
            JobHostConfiguration config = TestHelpers.NewConfig();
            var host2            = new JobHost(config);
            var metadataProvider = host2.CreateMetadataProvider();

            // Blob
            var blobAttr = GetAttr <TestStreamAttribute>(metadataProvider, new { path = "x" });

            Assert.Equal("x", blobAttr.Path);

            // Special casing to map Direction to Access field.
            blobAttr = GetAttr <TestStreamAttribute>(metadataProvider, new { path = "x", direction = "in" });
            Assert.Equal("x", blobAttr.Path);
            Assert.Equal(FileAccess.Read, blobAttr.Access);

            blobAttr = GetAttr <TestStreamAttribute>(metadataProvider, new { Path = "x", Direction = "out" });
            Assert.Equal("x", blobAttr.Path);
            Assert.Equal(FileAccess.Write, blobAttr.Access);

            blobAttr = GetAttr <TestStreamAttribute>(metadataProvider, new { path = "x", direction = "inout" });
            Assert.Equal("x", blobAttr.Path);
            Assert.Equal(FileAccess.ReadWrite, blobAttr.Access);
        }
        public void AttrBuilder()
        {
            JobHostConfiguration config = TestHelpers.NewConfig();
            var host2            = new JobHost(config);
            var metadataProvider = host2.CreateMetadataProvider();

            // Blob
            var blobAttr = GetAttr <BlobAttribute>(metadataProvider, new { path = "x" });

            Assert.Equal("x", blobAttr.BlobPath);
            Assert.Equal(null, blobAttr.Access);

            blobAttr = GetAttr <BlobAttribute>(metadataProvider, new { path = "x", direction = "in" });
            Assert.Equal("x", blobAttr.BlobPath);
            Assert.Equal(FileAccess.Read, blobAttr.Access);

            blobAttr = GetAttr <BlobAttribute>(metadataProvider, new { Path = "x", Direction = "out" });
            Assert.Equal("x", blobAttr.BlobPath);
            Assert.Equal(FileAccess.Write, blobAttr.Access);

            blobAttr = GetAttr <BlobAttribute>(metadataProvider, new { path = "x", direction = "inout" });
            Assert.Equal("x", blobAttr.BlobPath);
            Assert.Equal(FileAccess.ReadWrite, blobAttr.Access);

            blobAttr = GetAttr <BlobAttribute>(metadataProvider,
                                               new
            {
                path       = "x",
                direction  = "in",
                connection = "cx1"
            });
            Assert.Equal("x", blobAttr.BlobPath);
            Assert.Equal(FileAccess.Read, blobAttr.Access);
            Assert.Equal("cx1", blobAttr.Connection);

            blobAttr = GetAttr <BlobAttribute>(metadataProvider,
                                               new
            {
                path       = "x",
                direction  = "in",
                connection = ""   // empty, not null
            });
            Assert.Equal("x", blobAttr.BlobPath);
            Assert.Equal(FileAccess.Read, blobAttr.Access);
            Assert.Equal("", blobAttr.Connection); // empty is passed straight through.

            var blobTriggerAttr = GetAttr <BlobTriggerAttribute>(metadataProvider, new { path = "x" });

            Assert.Equal("x", blobTriggerAttr.BlobPath);

            // Queue
            var queueAttr = GetAttr <QueueAttribute>(metadataProvider, new { QueueName = "q1" });

            Assert.Equal("q1", queueAttr.QueueName);

            var queueTriggerAttr = GetAttr <QueueTriggerAttribute>(metadataProvider, new { QueueName = "q1" });

            Assert.Equal("q1", queueTriggerAttr.QueueName);

            // Table
            var tableAttr = GetAttr <TableAttribute>(metadataProvider, new { TableName = "t1" });

            Assert.Equal("t1", tableAttr.TableName);

            tableAttr = GetAttr <TableAttribute>(metadataProvider, new { TableName = "t1", partitionKey = "pk", Filter = "f1" });
            Assert.Equal("t1", tableAttr.TableName);
            Assert.Equal("pk", tableAttr.PartitionKey);
            Assert.Equal(null, tableAttr.RowKey);
            Assert.Equal("f1", tableAttr.Filter);
        }