示例#1
0
        public void TestError()
        {
            IHost host = new HostBuilder()
                         .ConfigureDefaultTestHost <ErrorProgram>(b =>
            {
                b.AddExtension <FakeQueueClient>();
            })
                         .Build();

            FakeQueueClient client  = host.GetExtension <FakeQueueClient>();
            JobHost         jobHost = host.GetJobHost();
            var             p       = host.GetTestLoggerProvider();

            // Call 'ok' method which has no errors. Should still get the indexing errors from the other method.
            var m = typeof(ErrorProgram).GetMethod(nameof(ErrorProgram.ValidMethod));

            try
            {
                jobHost.CallAsync(m); // Will force indexing.
            }
            catch (FunctionIndexingException e)
            {
                Assert.Equal("ErrorProgram.Func", e.MethodName);
            }
        }
示例#2
0
        static async Task <FakeQueueData[]> InvokeAsync(JobHost host, FakeQueueClient client, string name)
        {
            var method = typeof(Functions).GetMethod(name, BindingFlags.Public | BindingFlags.Static);
            await host.CallAsync(method);

            var data = client._items.ToArray();

            client._items.Clear();
            return(data);
        }
示例#3
0
        static async Task <T[]> InvokeJsonAsync <T>(JobHost host, FakeQueueClient client, string name)
        {
            var method = typeof(Functions).GetMethod(name, BindingFlags.Public | BindingFlags.Static);
            await host.CallAsync(method);

            var data = client._items.ToArray();

            var obj = Array.ConvertAll(data, x => JsonConvert.DeserializeObject <T>(x.Message));

            client._items.Clear();
            return(obj);
        }
        public void TestError()
        {
            FakeQueueClient client = new FakeQueueClient();

            // Call 'ok' method which has no errors. Should still get the indexing errors from the other method.
            var host = TestHelpers.NewJobHost <ErrorProgram>(client);
            var m    = typeof(ErrorProgram).GetMethod("ValidMethod");

            try
            {
                host.Call("ValidMethod"); // Will force indexing.
            }
            catch (FunctionIndexingException e)
            {
                Assert.Equal("ErrorProgram.Func", e.MethodName);
            }
        }
 public FakeQueueBindingProvider(FakeQueueClient client, IConverterManager converterManager)
 {
     _client           = client;
     _converterManager = converterManager;
 }
示例#6
0
 public FakeQueueListener(ITriggeredFunctionExecutor executor, FakeQueueClient client, bool singleDispatch)
 {
     this._executor       = executor;
     this._singleDispatch = singleDispatch;
     this._client         = client;
 }
示例#7
0
 public static async Task SendDirectClient(
     [FakeQueue("CustomConstructor", CustomPolicy = "Custom")] FakeQueueClient client)
 {
     await client.AddAsync(new FakeQueueData { Message = "abc", ExtraPropertery = "def" });
 }
示例#8
0
        public async Task Test()
        {
            IHost host = new HostBuilder()
                         .ConfigureDefaultTestHost <Functions>(b =>
            {
                b.AddExtension <FakeQueueClient>();
            })
                         .Build();

            JobHost         jobHost = host.GetJobHost();
            FakeQueueClient client  = host.GetExtension <FakeQueueClient>();

            var p7 = await InvokeAsync(jobHost, client, "SendDirectClient");

            Assert.Single(p7);
            Assert.Equal("abc", p7[0].Message);
            Assert.Equal("def", p7[0].ExtraPropertery);

            var p8 = await InvokeAsync(jobHost, client, "SendOneDerivedNative");

            Assert.Single(p8);
            DerivedFakeQueueData pd8 = (DerivedFakeQueueData)p8[0];

            Assert.Equal("Bonus!", pd8.Bonus); // verify derived prop that wouldn't serialize.

            var p9 = await InvokeAsync(jobHost, client, "SendOneOtherNative");

            Assert.Single(p9);
            Assert.Equal("direct", p9[0].ExtraPropertery); // Set by the  DirectFakeQueueData.ToEvent

            // Single items
            var p1 = await InvokeJsonAsync <Payload>(jobHost, client, "SendOnePoco");

            Assert.Single(p1);
            Assert.Equal(123, p1[0].val1);

            var p2 = await InvokeAsync(jobHost, client, "SendOneNative");

            Assert.Single(p2);
            Assert.Equal("message", p2[0].Message);
            Assert.Equal("extra", p2[0].ExtraPropertery);

            var p3 = await InvokeAsync(jobHost, client, "SendOneString");

            Assert.Single(p3);
            Assert.Equal("stringvalue", p3[0].Message);

            foreach (string methodName in new string[] { "SendDontQueue", "SendArrayNull", "SendArrayLen0" })
            {
                var p6 = await InvokeAsync(jobHost, client, methodName);

                Assert.Empty(p6);
            }

            // batching
            foreach (string methodName in new string[] {
                "SendSyncCollectorBytes", "SendArrayString", "SendSyncCollectorString", "SendAsyncCollectorString", "SendCollectorNative"
            })
            {
                var p4 = await InvokeAsync(jobHost, client, methodName);

                Assert.Equal(2, p4.Length);
                Assert.Equal("first", p4[0].Message);
                Assert.Equal("second", p4[1].Message);
            }

            foreach (string methodName in new string[] { "SendCollectorPoco", "SendArrayPoco" })
            {
                var p5 = await InvokeJsonAsync <Payload>(jobHost, client, methodName);

                Assert.Equal(2, p5.Length);
                Assert.Equal(100, p5[0].val1);
                Assert.Equal(200, p5[1].val1);
            }
        }
        public void Test()
        {
            FakeQueueClient client = new FakeQueueClient();
            var             host   = TestHelpers.NewJobHost <Functions>(client);

            var p7 = Invoke(host, client, "SendDirectClient");

            Assert.Single(p7);
            Assert.Equal("abc", p7[0].Message);
            Assert.Equal("def", p7[0].ExtraPropertery);

            var p8 = Invoke(host, client, "SendOneDerivedNative");

            Assert.Single(p8);
            DerivedFakeQueueData pd8 = (DerivedFakeQueueData)p8[0];

            Assert.Equal("Bonus!", pd8.Bonus); // verify derived prop that wouldn't serialize.

            var p9 = Invoke(host, client, "SendOneOtherNative");

            Assert.Single(p9);
            Assert.Equal("direct", p9[0].ExtraPropertery); // Set by the  DirectFakeQueueData.ToEvent

            // Single items
            var p1 = InvokeJson <Payload>(host, client, "SendOnePoco");

            Assert.Single(p1);
            Assert.Equal(123, p1[0].val1);

            var p2 = Invoke(host, client, "SendOneNative");

            Assert.Single(p2);
            Assert.Equal("message", p2[0].Message);
            Assert.Equal("extra", p2[0].ExtraPropertery);

            var p3 = Invoke(host, client, "SendOneString");

            Assert.Single(p3);
            Assert.Equal("stringvalue", p3[0].Message);

            foreach (string methodName in new string[] { "SendDontQueue", "SendArrayNull", "SendArrayLen0" })
            {
                var p6 = Invoke(host, client, methodName);
                Assert.Empty(p6);
            }

            // batching
            foreach (string methodName in new string[] {
                "SendSyncCollectorBytes", "SendArrayString", "SendSyncCollectorString", "SendAsyncCollectorString", "SendCollectorNative"
            })
            {
                var p4 = Invoke(host, client, methodName);
                Assert.Equal(2, p4.Length);
                Assert.Equal("first", p4[0].Message);
                Assert.Equal("second", p4[1].Message);
            }

            foreach (string methodName in new string[] { "SendCollectorPoco", "SendArrayPoco" })
            {
                var p5 = InvokeJson <Payload>(host, client, methodName);
                Assert.Equal(2, p5.Length);
                Assert.Equal(100, p5[0].val1);
                Assert.Equal(200, p5[1].val1);
            }
        }
示例#10
0
 public static async Task SendDirectClient(
     [FakeQueue] FakeQueueClient client)
 {
     await client.AddAsync(new FakeQueueData { Message = "abc", ExtraPropertery = "def" });
 }
        public void Test()
        {
            JobHostConfiguration config = new JobHostConfiguration()
            {
                TypeLocator = new FakeTypeLocator(typeof(Functions))
            };

            FakeQueueClient    client     = new FakeQueueClient();
            IExtensionRegistry extensions = config.GetService <IExtensionRegistry>();

            extensions.RegisterExtension <IExtensionConfigProvider>(client);

            JobHost host = new JobHost(config);

            var p8 = Invoke(host, client, "SendOneDerivedNative");

            Assert.Equal(1, p8.Length);
            DerivedFakeQueueData pd8 = (DerivedFakeQueueData)p8[0];

            Assert.Equal("Bonus!", pd8.Bonus); // verify derived prop that wouldn't serialize.

            var p9 = Invoke(host, client, "SendOneOtherNative");

            Assert.Equal(1, p9.Length);
            Assert.Equal("direct", p9[0].ExtraPropertery); // Set by the  DirectFakeQueueData.ToEvent

            // Single items
            var p1 = InvokeJson <Payload>(host, client, "SendOnePoco");

            Assert.Equal(1, p1.Length);
            Assert.Equal(123, p1[0].val1);

            var p2 = Invoke(host, client, "SendOneNative");

            Assert.Equal(1, p2.Length);
            Assert.Equal("message", p2[0].Message);
            Assert.Equal("extra", p2[0].ExtraPropertery);

            var p3 = Invoke(host, client, "SendOneString");

            Assert.Equal(1, p3.Length);
            Assert.Equal("stringvalue", p3[0].Message);

            foreach (string methodName in new string[] { "SendDontQueue", "SendArrayNull", "SendArrayLen0" })
            {
                var p6 = Invoke(host, client, methodName);
                Assert.Equal(0, p6.Length);
            }

            // batching
            foreach (string methodName in new string[] {
                "SendSyncCollectorBytes", "SendArrayString", "SendSyncCollectorString", "SendAsyncCollectorString", "SendCollectorNative"
            })
            {
                var p4 = Invoke(host, client, methodName);
                Assert.Equal(2, p4.Length);
                Assert.Equal("first", p4[0].Message);
                Assert.Equal("second", p4[1].Message);
            }

            foreach (string methodName in new string[] { "SendCollectorPoco", "SendArrayPoco" })
            {
                var p5 = InvokeJson <Payload>(host, client, methodName);
                Assert.Equal(2, p5.Length);
                Assert.Equal(100, p5[0].val1);
                Assert.Equal(200, p5[1].val1);
            }
        }