示例#1
0
        public void StopAsync_WhenAlreadyStopping_ReturnsSameTask()
        {
            // Arrange
            JobHostOptions configuration = null;

            using (JobHost host = new JobHost(new OptionsWrapper <JobHostOptions>(configuration), new Mock <IJobHostContextFactory>().Object))
            {
                host.Start();

                // Replace (and cleanup) the existing listener to hook StopAsync.
                IListener oldRunner = host.Listener;
                oldRunner.StopAsync(CancellationToken.None).GetAwaiter().GetResult();

                TaskCompletionSource <object> stopTaskSource = new TaskCompletionSource <object>();
                Mock <IListener> listenerMock = new Mock <IListener>(MockBehavior.Strict);
                listenerMock.Setup(r => r.StopAsync(It.IsAny <CancellationToken>())).Returns(stopTaskSource.Task);
                listenerMock.Setup(r => r.Dispose());
                host.Listener = listenerMock.Object;
                Task alreadyStopping = host.StopAsync();

                // Act
                Task stoppingAgain = host.StopAsync();

                // Assert
                Assert.Same(alreadyStopping, stoppingAgain);

                // Cleanup
                stopTaskSource.SetResult(null);
                alreadyStopping.GetAwaiter().GetResult();
                stoppingAgain.GetAwaiter().GetResult();
            }
        }
        public LeaseExpirationTests()
        {
            RandomNameResolver nameResolver = new RandomNameResolver();

            _options = new JobHostOptions()
            {
                // NameResolver = nameResolver,
                // TODO: DI:
                //TypeLocator = new FakeTypeLocator(typeof(LeaseExpirationTests))
            };

            // TODO: DI:
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(null);//_config.StorageConnectionString);

            _queueClient = storageAccount.CreateCloudQueueClient();

            _queue = _queueClient.GetQueueReference(nameResolver.ResolveInString(TestQueueName));
            _queue.CreateIfNotExistsAsync().Wait();
        }
        public ProxyFunctionDescriptorProviderTests()
        {
            string rootPath = Path.Combine(Environment.CurrentDirectory, @"TestScripts\Proxies");

            var hostOptions    = new JobHostOptions();
            var eventManager   = new Mock <IScriptEventManager>();
            var contextFactory = new Mock <IJobHostContextFactory>();

            _proxyClient     = GetMockProxyClient();
            _settingsManager = ScriptSettingsManager.Instance;
            _host            = new HostBuilder()
                               .ConfigureDefaultTestWebScriptHost(o =>
            {
                o.ScriptPath = rootPath;
                o.LogPath    = TestHelpers.GetHostLogFileDirectory().Parent.FullName;
            })
                               .Build();

            _scriptHost = _host.GetScriptHost();
        }
示例#4
0
        public void StopAsync_WhenStarting_Throws()
        {
            // Arrange
            // TaskCompletionSource<IStorageAccount> getAccountTaskSource = new TaskCompletionSource<IStorageAccount>();
            JobHostOptions configuration = null; // CreateConfiguration(new LambdaStorageAccountProvider(

            //        (i1, i2) => getAccountTaskSource.Task));

            using (JobHost host = new JobHost(new OptionsWrapper <JobHostOptions>(configuration), new Mock <IJobHostContextFactory>().Object))
            {
                Task starting = host.StartAsync();
                Assert.False(starting.IsCompleted); // Guard

                // Act & Assert
                ExceptionAssert.ThrowsInvalidOperation(() => host.StopAsync(), "The host has not yet started.");

                // Cleanup
                // getAccountTaskSource.SetResult(null);
                starting.GetAwaiter().GetResult();
            }
        }