public void TestByteArrayDispatch2()
        {
            var client = new FakeQueueClient();

            client.SetConverters = AddItem2ByteConverter;

            var items = Run <FunctionsByteArray>(client,
                                                 new FakeQueueData {
                Byte = 1
            },
                                                 new FakeQueueData {
                Byte = 2
            },
                                                 new FakeQueueData {
                Byte = 3
            }
                                                 );

            Assert.Single(items);

            // Received as 1 batch, with 3 entries.
            var bytes = new byte[] { 1, 2, 3 };

            Assert.Equal(bytes, items[0]);
        }
        private object[] Run <TFunction>(FakeQueueClient client, params FakeQueueData[] items) where TFunction : FunctionsBase, new()
        {
            var activator = new FakeActivator();
            var func1     = new TFunction();

            activator.Add(func1);

            var host = TestHelpers.NewJobHost <TFunction>(client, activator);

            foreach (var item in items)
            {
                client.AddAsync(item).Wait();
            }

            host.Start();
            TestHelpers.WaitOne(func1._stopEvent);
            host.Stop();

            // Add any items sent using [FakeQueue(Prefix=...)]
            foreach (var kv in client._prefixedItems)
            {
                func1._collected.AddRange(kv.Value);
            }

            return(func1._collected.ToArray());
        }
Example #3
0
        // Helper to send items to the listener, and return what they collected
        private object[] Run <TFunction>(params FakeQueueData[] items) where TFunction : FunctionsBase, new()
        {
            var activator = new FakeActivator();
            var func1     = new TFunction();

            activator.Add(func1);

            JobHostConfiguration config = new JobHostConfiguration()
            {
                TypeLocator  = new FakeTypeLocator(typeof(TFunction)),
                JobActivator = activator
            };

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

            extensions.RegisterExtension <IExtensionConfigProvider>(client);

            JobHost host = new JobHost(config);

            foreach (var item in items)
            {
                client.AddAsync(item).Wait();
            }

            host.Start();
            TestHelpers.WaitOne(func1._stopEvent);
            host.Stop();

            return(func1._collected.ToArray());
        }
        public async Task TestNoStringTriggerAdapter()
        {
            var queueClient = new FakeQueueClient();
            var config      = TestHelpers.NewConfig <ProgNoString>(new ExtNoStringConverter(), queueClient);
            var host        = new JobHost(config);

            var args = new Dictionary <string, object>();

            args["data"] = new FakeQueueData {
                Message = "15"
            };

            await host.CallAsync("FuncAsInt", args);

            Assert.Equal(15, ProgNoString._value);
        }
        public async Task GivenEnrichedMessage_WhenAskingToSend_ThenItShouldOnlyCallQueueClient()
        {
            // arrange
            const string           messageBody     = "{'Dammit':'Bobby!','Results':'Dirty hippies.'}";
            Message                message         = new Message(Encoding.UTF8.GetBytes(messageBody));
            FakeQueueClient        fakeQueueClient = new FakeQueueClient();
            FakePostman            fakePostman     = new FakePostman();
            ServiceBusQueuePostman postman         = new Privateer().Object <ServiceBusQueuePostman>(fakeQueueClient, messageBody, message, fakePostman);

            // act
            async Task func() => await postman.SendAsync();

            await func();

            // assert
            fakeQueueClient.CallCount.Should().Be(1);
            fakePostman.CallCount.Should().Be(0);
        }
        public void TestByteArrayDispatch3()
        {
            var client = new FakeQueueClient();

            client.SetConverters = AddItem2ByteArrayConverter;

            object[] items = Run <FunctionsDoubleByteArray>(client,
                                                            new FakeQueueData {
                Message = "AB"
            },
                                                            new FakeQueueData {
                Message = "CD"
            }
                                                            );
            Assert.Single(items);

            var arg = (byte[][])(items[0]);

            Assert.Equal(new byte[] { 65, 66 }, arg[0]);
            Assert.Equal(new byte[] { 67, 68 }, arg[1]);
        }
        public void TestByteArrayDispatch()
        {
            var e0 = new FakeQueueData
            {
                Message = "ABC"
            };

            var client = new FakeQueueClient();

            client.SetConverters = AddItem2ByteArrayConverter;

            var items = Run <FunctionsByteArray>(client, e0);

            Assert.Single(items);

            // This uses the Item --> byte[] converter. Dispatch as a single item.
            // Received as 1 object, a byte[].
            var bytes = System.Text.Encoding.UTF8.GetBytes(e0.Message);

            Assert.Equal(bytes, items[0]);
        }
        private object[] Run <TFunction>(Action <FakeQueueClient> clientSetup, params FakeQueueData[] items) where TFunction : FunctionsBase, new()
        {
            var activator = new FakeActivator();
            var func1     = new TFunction();

            activator.Add(func1);

            FakeQueueClient fakeClient = null;
            var             host       = new HostBuilder()
                                         .ConfigureDefaultTestHost <TFunction>(b => { }, activator: activator)
                                         .ConfigureServices(services =>
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <IExtensionConfigProvider, FakeQueueClient>(p =>
                {
                    fakeClient = new FakeQueueClient(p.GetService <INameResolver>(), p.GetService <IConverterManager>());
                    clientSetup?.Invoke(fakeClient);
                    foreach (var item in items)
                    {
                        fakeClient.AddAsync(item).Wait();
                    }
                    return(fakeClient);
                }));
            })
                                         .Build();

            host.Start();
            TestHelpers.WaitOne(func1._stopEvent);
            host.StopAsync().GetAwaiter().GetResult();

            // Add any items sent using [FakeQueue(Prefix=...)]
            foreach (var kv in fakeClient._prefixedItems)
            {
                func1._collected.AddRange(kv.Value);
            }

            return(func1._collected.ToArray());
        }
 public FakeQueueBindingProvider(FakeQueueClient client, IConverterManager converterManager)
 {
     _client = client;
     _converterManager = converterManager;
 }
 public FakeQueueListener(ITriggeredFunctionExecutor executor, FakeQueueClient client, bool singleDispatch)
 {
     this._executor = executor;
     this._singleDispatch = singleDispatch;
     this._client = client;
 }