public DaprTestBase(ITestOutputHelper output,
                            IDictionary <string, string> environmentVariables)
        {
            this.logProvider  = new TestLogProvider(output);
            this.typeLocator  = new TestFunctionTypeLocator();
            this.nameResolver = new TestNameResolver();

            foreach (var kvPair in DefaultEnvironmentVariables)
            {
                if (!environmentVariables.ContainsKey(kvPair.Key))
                {
                    environmentVariables[kvPair.Key] = kvPair.Value;
                }
            }

            foreach (var kvPair in environmentVariables)
            {
                this.nameResolver.AddSetting(kvPair.Key, kvPair.Value);
            }

            this.functionsHost = new HostBuilder()
                                 .ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(this.logProvider))
                                 .ConfigureWebJobs(webJobsBuilder => webJobsBuilder.AddDapr())
                                 .ConfigureServices(
                collection =>
            {
                collection.AddSingleton <INameResolver>(this.nameResolver);
                collection.AddSingleton <ITypeLocator>(this.typeLocator);
            })
                                 .Build();
            this.daprRuntime = new DaprRuntimeEmulator(DaprPort);
        }
Exemplo n.º 2
0
        public IntegrationTestBase(ITestOutputHelper output)
        {
            this.logProvider      = new TestLogProvider(output);
            this.typeLocator      = new TestFunctionTypeLocator();
            this.settingsResolver = new TestSettingsResolver();

            this.functionsHost = new HostBuilder()
                                 .ConfigureLogging(
                loggingBuilder =>
            {
                loggingBuilder.AddProvider(this.logProvider);
                loggingBuilder.SetMinimumLevel(LogLevel.Information);
            })
                                 .ConfigureWebJobs(webJobsBuilder => webJobsBuilder.AddDurableTask())
                                 .ConfigureServices(
                services =>
            {
                services.AddSingleton <INameResolver>(this.settingsResolver);
                services.AddSingleton <IConnectionStringResolver>(this.settingsResolver);
                services.AddSingleton <ITypeLocator>(this.typeLocator);
                services.AddSingleton <IDurabilityProviderFactory, NetheriteProviderFactory>();
            })
                                 .Build();

            this.AddFunctions(typeof(ClientFunctions));
        }
Exemplo n.º 3
0
        public IntegrationTestBase(ITestOutputHelper output)
        {
            this.logProvider      = new TestLogProvider(output);
            this.typeLocator      = new TestFunctionTypeLocator();
            this.settingsResolver = new TestSettingsResolver();

            this.settingsResolver.AddSetting("SQLDB_Connection", SharedTestHelpers.GetDefaultConnectionString());

            this.functionsHost = new HostBuilder()
                                 .ConfigureLogging(
                loggingBuilder =>
            {
                loggingBuilder.AddProvider(this.logProvider);
                loggingBuilder.SetMinimumLevel(LogLevel.Information);
            })
                                 .ConfigureWebJobs(
                webJobsBuilder =>
            {
                webJobsBuilder.AddDurableTask(options =>
                {
                    options.StorageProvider["type"] = SqlDurabilityProvider.Name;
                });
            })
                                 .ConfigureServices(
                services =>
            {
                services.AddSingleton <INameResolver>(this.settingsResolver);
                services.AddSingleton <IConnectionStringResolver>(this.settingsResolver);
                services.AddSingleton <ITypeLocator>(this.typeLocator);
                services.AddSingleton <IDurabilityProviderFactory, SqlDurabilityProviderFactory>();
            })
                                 .Build();

            this.AddFunctions(typeof(ClientFunctions));
        }
Exemplo n.º 4
0
            public void ShouldLoadScriptPacksIfScriptNameIsSet(IConsole console, TestLogProvider logProvider, IScriptEngine engine)
            {
                var builder = new ScriptServicesBuilder(console, logProvider);

                builder.Overrides[typeof(IScriptEngine)] = engine.GetType();
                builder.ScriptName("");
                builder.Build();
                var runtimeServices = (RuntimeServices)builder.RuntimeServices;

                runtimeServices.InitDirectoryCatalog.ShouldBeTrue();
            }
            public void ShouldLoadScriptPacksIfReplIsTrue(IConsole console, TestLogProvider logProvider)
            {
                var builder = new ScriptServicesBuilder(console, logProvider);

                builder.Overrides[typeof(IScriptEngine)] = typeof(MockScriptEngine);
                builder.Repl();
                builder.Build();
                var runtimeServices = (RuntimeServices)builder.RuntimeServices;

                runtimeServices.InitDirectoryCatalog.ShouldBeTrue();
            }
Exemplo n.º 6
0
 protected override void Write(MvxLogLevel logLevel, string message, Exception e = null)
 {
     try
     {
         var formatted = TestLogProvider.MessageFormatter(_name, logLevel, message, e);
         _testOuputHelper.WriteLine(formatted);
     }
     catch (InvalidOperationException)
     {
         // not ready to log yet, usually happens before test actually started
         // however, MvvmCross is already setting up things in fixture and logging
     }
 }
Exemplo n.º 7
0
        public void ReloadHappyPath()
        {
            var source = new TestConfigurationSource();

            source.Provider.Set("CustomLogProvider:Foo", "123");
            source.Provider.Set("CustomLogProvider:Bar", "abc");

            var configuration = new ConfigurationBuilder()
                                .Add(source)
                                .Build();

            var services = new ServiceCollection();

            services.Configure <TestOptions>("MyLogger", configuration.GetSection("CustomLogProvider"));

            var serviceProvider = services.BuildServiceProvider();

            var optionsMonitor = serviceProvider.GetRequiredService <IOptionsMonitor <TestOptions> >();
            var options        = optionsMonitor.Get("MyLogger");
            Func <TestOptions, ILogProvider> createLogProvider = o =>
                                                                 new TestLogProvider {
                Foo = o.Foo, Bar = o.Bar
            };
            string name = "MyLogger";
            Action <TestOptions> configureOptions = null;

            var reloadingLogProvider = ReloadingLogProviderOfTestOptions.New(optionsMonitor, options, createLogProvider, name, configureOptions);

            TestLogProvider logProvider1 = reloadingLogProvider._logProvider;

            logProvider1.Foo.Should().Be(123);
            logProvider1.Bar.Should().Be("abc");

            source.Provider.Set("CustomLogProvider:Foo", "456");
            source.Provider.Set("CustomLogProvider:Bar", "xyz");
            source.Provider.Reload();

            TestLogProvider logProvider2 = reloadingLogProvider._logProvider;

            logProvider2.Should().NotBeSameAs(logProvider1);
            logProvider2.Foo.Should().Be(456);
            logProvider2.Bar.Should().Be("xyz");
        }
Exemplo n.º 8
0
            public void ShouldAliasCommandWithNewName(
                Mock <IFileSystem> fileSystem,
                Mock <IScriptEngine> engine,
                Mock <IObjectSerializer> serializer,
                TestLogProvider logProvider,
                Mock <IScriptLibraryComposer> composer,
                Mock <IConsole> console,
                Mock <IFilePreProcessor> filePreProcessor)
            {
                // arrange
                var currentDir   = @"C:\";
                var dummyCommand = new Mock <IReplCommand>();

                dummyCommand.Setup(x => x.CommandName).Returns("foo");

                fileSystem.Setup(x => x.BinFolder).Returns(Path.Combine(currentDir, "bin"));
                fileSystem.Setup(x => x.DllCacheFolder).Returns(Path.Combine(currentDir, "cache"));

                var executor = new Repl(
                    new string[0],
                    fileSystem.Object,
                    engine.Object,
                    serializer.Object,
                    logProvider,
                    composer.Object,
                    console.Object,
                    filePreProcessor.Object,
                    new List <IReplCommand> {
                    dummyCommand.Object
                },
                    new Printers(serializer.Object),
                    new ScriptInfo());

                var cmd = new AliasCommand(console.Object);

                // act
                cmd.Execute(executor, new[] { "foo", "bar" });

                // assert
                executor.Commands.Count.ShouldEqual(2);
                executor.Commands["bar"].ShouldBeSameAs(executor.Commands["foo"]);
            }
Exemplo n.º 9
0
        public void ConstructorHappyPath()
        {
            var source = new TestConfigurationSource();

            source.Provider.Set("CustomLogProvider:Foo", "123");
            source.Provider.Set("CustomLogProvider:Bar", "abc");

            var configuration = new ConfigurationBuilder()
                                .Add(source)
                                .Build();

            var services = new ServiceCollection();

            services.Configure <TestOptions>("MyLogger", configuration.GetSection("CustomLogProvider"));

            var serviceProvider = services.BuildServiceProvider();

            var optionsMonitor = serviceProvider.GetRequiredService <IOptionsMonitor <TestOptions> >();
            var options        = optionsMonitor.Get("MyLogger");
            Func <TestOptions, ILogProvider> createLogProvider = o =>
                                                                 new TestLogProvider {
                Foo = o.Foo, Bar = o.Bar
            };
            string name = "MyLogger";
            Action <TestOptions> configureOptions = opt => { };

            var reloadingLogProvider = ReloadingLogProviderOfTestOptions.New(optionsMonitor, options, createLogProvider, name, configureOptions);

            string actualName = reloadingLogProvider._name;

            actualName.Should().BeSameAs(name);

            TestLogProvider logProvider = reloadingLogProvider._logProvider;

            logProvider.Foo.Should().Be(123);
            logProvider.Bar.Should().Be("abc");

            Action <TestOptions> actualConfigureOptions = reloadingLogProvider._configureOptions;

            actualConfigureOptions.Should().BeSameAs(configureOptions);
        }
Exemplo n.º 10
0
        public DaprTestBase(ITestOutputHelper output)
        {
            this.logProvider  = new TestLogProvider(output);
            this.typeLocator  = new TestFunctionTypeLocator();
            this.nameResolver = new TestNameResolver();

            // Use 3501 to avoid conflicting with the real Dapr port number
            int daprPort = 3501;

            this.nameResolver.AddSetting("DAPR_HTTP_PORT", daprPort.ToString());

            this.functionsHost = new HostBuilder()
                                 .ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(this.logProvider))
                                 .ConfigureWebJobs(webJobsBuilder => webJobsBuilder.AddDapr())
                                 .ConfigureServices(
                collection =>
            {
                collection.AddSingleton <INameResolver>(this.nameResolver);
                collection.AddSingleton <ITypeLocator>(this.typeLocator);
            })
                                 .Build();
            this.daprRuntime = new DaprRuntimeEmulator(daprPort);
        }
Exemplo n.º 11
0
            public void ShouldAliasCommandWithNewName(
                Mock<IFileSystem> fileSystem,
                Mock<IScriptEngine> engine,
                Mock<IObjectSerializer> serializer,
                TestLogProvider logProvider,
                Mock<IScriptLibraryComposer> composer,
                Mock<IConsole> console,
                Mock<IFilePreProcessor> filePreProcessor)
            {
                // arrange
                var currentDir = @"C:\";
                var dummyCommand = new Mock<IReplCommand>();
                dummyCommand.Setup(x => x.CommandName).Returns("foo");

                fileSystem.Setup(x => x.BinFolder).Returns(Path.Combine(currentDir, "bin"));
                fileSystem.Setup(x => x.DllCacheFolder).Returns(Path.Combine(currentDir, "cache"));

                var executor = new Repl(
                    new string[0],
                    fileSystem.Object,
                    engine.Object,
                    serializer.Object,
                    logProvider,
                    composer.Object,
                    console.Object,
                    filePreProcessor.Object,
                    new List<IReplCommand> { dummyCommand.Object });

                var cmd = new AliasCommand(console.Object);

                // act
                cmd.Execute(executor, new[] { "foo", "bar" });

                // assert
                executor.Commands.Count.ShouldEqual(2);
                executor.Commands["bar"].ShouldBeSameAs(executor.Commands["foo"]);
            }
Exemplo n.º 12
0
            public void ShouldNotLoadScriptPacksIfLoadScriptPacksIsFalse(IConsole console, TestLogProvider logProvider, IScriptEngine engine)
            {
                var builder = new ScriptServicesBuilder(console, logProvider);

                builder.Overrides[typeof(IScriptEngine)] = engine.GetType();
                builder.LoadScriptPacks(false);
                builder.Build();
                var runtimeServices = (RuntimeServices)builder.RuntimeServices;

                runtimeServices.InitDirectoryCatalog.ShouldBeFalse();
            }
Exemplo n.º 13
0
 public DatabaseManagement(ITestOutputHelper output)
 {
     this.logProvider = new TestLogProvider(output);
     this.output      = output;
 }
 public MonoTestScriptEngine(IScriptHostFactory scriptHostFactory, TestLogProvider logProvider)
     : base(scriptHostFactory, logProvider)
 {
 }