Exemple #1
0
        public void AddingInvokerToCommandCreatesAdapter()
        {
            mapSvc.Register(typeof(MockInvoker), typeof(MockAdapter));
            Command cmd = new Command();

            container.Items.Add(cmd);

            MockInvoker inv = new MockInvoker();

            cmd.AddInvoker(inv, "Event");

            ReadOnlyCollection <MockAdapter> list = cmd.FindAdapters <MockAdapter>();

            Assert.AreEqual(1, list.Count);
        }
Exemple #2
0
        public void DisposeUnwiresAllInvokers()
        {
            EventCommandAdapter <MockInvoker> adapter = new EventCommandAdapter <MockInvoker>();
            MockInvoker invoker = new MockInvoker();

            adapter.AddInvoker(invoker, "Event");
            MockInvoker invokerB = new MockInvoker();

            adapter.AddInvoker(invokerB, "Event");
            adapter.AddInvoker(invokerB, "Event2");

            adapter.Dispose();

            Assert.AreEqual(0, adapter.Invokers.Count);
        }
Exemple #3
0
        public void InvokerIsWiredUp()
        {
            Command     command = new Command();
            MockInvoker invoker = new MockInvoker();
            EventCommandAdapter <MockInvoker> adapter = new EventCommandAdapter <MockInvoker>(invoker, "Event");

            command.AddCommandAdapter(adapter);
            MockListener listener = new MockListener();

            command.ExecuteAction += listener.CatchCommand;

            invoker.DoInvokeEvent();

            Assert.IsTrue(listener.CommandFired);
        }
        public FunctionInvokerBaseTests()
        {
            _metricsLogger = new TestMetricsLogger();
            _traceWriter   = new TestTraceWriter(TraceLevel.Verbose);
            var config = new ScriptHostConfiguration();

            config.HostConfig.AddService <IMetricsLogger>(_metricsLogger);
            var hostMock = new Mock <ScriptHost>(MockBehavior.Strict, new object[] { new NullScriptHostEnvironment(), config, null });

            hostMock.Object.TraceWriter = _traceWriter;

            var metadata = new FunctionMetadata
            {
                Name = "TestFunction"
            };

            _invoker = new MockInvoker(hostMock.Object, metadata);
        }
Exemple #5
0
        public FunctionInvokerBaseTests()
        {
            _metricsLogger      = new TestMetricsLogger();
            _testLoggerProvider = new TestLoggerProvider();

            var scriptHostConfiguration = new ScriptHostConfiguration
            {
                HostConfig          = new JobHostConfiguration(),
                FileLoggingMode     = FileLoggingMode.Always,
                FileWatchingEnabled = true
            };

            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(_testLoggerProvider);
            scriptHostConfiguration.HostConfig.LoggerFactory = loggerFactory;

            scriptHostConfiguration.HostConfig.AddService <IMetricsLogger>(_metricsLogger);

            var eventManager = new ScriptEventManager();

            var host = new Mock <ScriptHost>(new NullScriptHostEnvironment(), eventManager, scriptHostConfiguration, null, null, null);

            host.CallBase = true;

            host.SetupGet(h => h.IsPrimary).Returns(true);

            var funcDescriptor  = new FunctionDescriptor();
            var funcDescriptors = new Collection <FunctionDescriptor>();

            funcDescriptors.Add(funcDescriptor);
            host.SetupGet(h => h.Functions).Returns(funcDescriptors);

            var metadata = new FunctionMetadata
            {
                Name = "TestFunction"
            };

            _invoker = new MockInvoker(host.Object, _metricsLogger, metadata);
            funcDescriptor.Metadata = metadata;
            funcDescriptor.Invoker  = _invoker;
            funcDescriptor.Name     = metadata.Name;
        }
        public FunctionInvokerBaseTests()
        {
            _metricsLogger      = new TestMetricsLogger();
            _testLoggerProvider = new TestLoggerProvider();

            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(_testLoggerProvider);

            var eventManager = new ScriptEventManager();

            var metadata = new FunctionMetadata
            {
                Name       = "TestFunction",
                ScriptFile = "index.js",
                Language   = "node"
            };
            JObject binding = JObject.FromObject(new
            {
                type      = "manualTrigger",
                name      = "manual",
                direction = "in"
            });

            metadata.Bindings.Add(BindingMetadata.Create(binding));

            var metadataManager = new MockMetadataManager(new[] { metadata });

            _host = new HostBuilder()
                    .ConfigureDefaultTestWebScriptHost()
                    .ConfigureServices(s =>
            {
                s.AddSingleton <IFunctionMetadataManager>(metadataManager);
            })
                    .Build();

            _scriptHost = _host.GetScriptHost();
            _scriptHost.InitializeAsync().Wait();

            _invoker = new MockInvoker(_scriptHost, _metricsLogger, metadataManager, metadata, loggerFactory);
        }
Exemple #7
0
        public void AddedInvokerFiresTheCommand()
        {
            mapSvc.Register(typeof(MockInvoker), typeof(MockAdapter));
            Command cmd    = new Command();
            bool    called = false;

            cmd.ExecuteAction += delegate(object sender, EventArgs e)
            {
                called = true;
            };

            container.Items.Add(cmd);

            MockInvoker invoker = new MockInvoker();

            cmd.AddInvoker(invoker, "Event");

            invoker.DoInvoke();

            Assert.IsTrue(called);
        }
 public void CreatingWithNullEventThrows()
 {
     MockInvoker invoker = new MockInvoker();
     EventCommandAdapter <MockInvoker> adapter = new EventCommandAdapter <MockInvoker>(invoker, null);
 }
 public void CreateingWithNullInvokerThrows()
 {
     MockInvoker invoker = new MockInvoker();
     EventCommandAdapter <MockInvoker> adapter = new EventCommandAdapter <MockInvoker>(null, "Event");
 }
Exemple #10
0
 public override void AddInvoker(object invoker, string evenName)
 {
     this.invoker        = (MockInvoker)invoker;
     this.invoker.Event += InvokerEventHandler;
 }
Exemple #11
0
 public void VerifyChainOfThreeInvokers()
 {
     Chain.Start(StartInvoker, TestInvokerArgs);
     MockInvoker.Verify(invoker => invoker.InvokeFrom(It.IsAny <InvokerArgs>()), Times.Once());
 }
Exemple #12
0
 public void VerifyChainOfTwoInvokers()
 {
     SetupTwoInvokerChain();
     Chain.Start(StartInvoker, TestInvokerArgs);
     MockInvoker.Verify(invoker => invoker.InvokeFrom(It.Is <InvokerArgs>(args => args == TestInvokerArgs)), Times.Once());
 }