Exemple #1
0
        public async void SetServices_RestartsNodeJSProcessWithNewServices()
        {
            // Arrange
            const string dummyTestVariableName   = "TEST_VARIABLE_1";
            const string dummyTestVariableValue1 = "testVariableValue1";
            const string dummyTestVariableValue2 = "testVariableValue2";

            StaticNodeJSService.Configure <NodeJSProcessOptions>(options => options.EnvironmentVariables.Add(dummyTestVariableName, dummyTestVariableValue1));
            string result1 = await StaticNodeJSService.
                             InvokeFromStringAsync <string>($"module.exports = (callback) => callback(null, process.env.{dummyTestVariableName});").ConfigureAwait(false);

            var dummyServices = new ServiceCollection();

            dummyServices.
            AddNodeJS().
            Configure <NodeJSProcessOptions>(options => options.EnvironmentVariables.Add(dummyTestVariableName, dummyTestVariableValue2));

            // Act
            StaticNodeJSService.SetServices(dummyServices);

            // Assert
            string result2 = await StaticNodeJSService.
                             InvokeFromStringAsync <string>($"module.exports = (callback) => callback(null, process.env.{dummyTestVariableName});").ConfigureAwait(false);

            Assert.Equal(dummyTestVariableValue1, result1);
            Assert.Equal(dummyTestVariableValue2, result2);
        }
        public async void Configure_ConfiguresOptions()
        {
            // Arrange
            const int    dummyInitialInvocationResult = 1;
            const string dummyTestVariableName1       = "TEST_VARIABLE_1";
            const string dummyTestVariableValue1      = "testVariableValue1";
            const string dummyTestVariableName2       = "TEST_VARIABLE_2";
            const string dummyTestVariableValue2      = "testVariableValue2";

            // Act
            // Invoke javascript once to ensure that an initial NodeJSService is created. The invocation after configuration should properly dispose of this initial instance and create a new one with the
            // specified options.
            int initialInvocationResult = await StaticNodeJSService.
                                          InvokeFromStringAsync <int>($"module.exports = (callback) => callback(null, {dummyInitialInvocationResult});").ConfigureAwait(false);

            StaticNodeJSService.
            Configure <NodeJSProcessOptions>(options => options.EnvironmentVariables.Add(dummyTestVariableName1, dummyTestVariableValue1));
            StaticNodeJSService.
            Configure <NodeJSProcessOptions>(options => options.EnvironmentVariables.Add(dummyTestVariableName2, dummyTestVariableValue2));

            // Assert
            Assert.Equal(dummyInitialInvocationResult, initialInvocationResult);
            DummyResult result = await StaticNodeJSService.
                                 InvokeFromStringAsync <DummyResult>($"module.exports = (callback) => callback(null, {{result: process.env.{dummyTestVariableName1} + process.env.{dummyTestVariableName2}}});").
                                 ConfigureAwait(false);

            Assert.Equal(dummyTestVariableValue1 + dummyTestVariableValue2, result.Result);
        }
Exemple #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMemoryCache();
            services.AddSignalR();
            services.AddDotNetify();

            StaticNodeJSService.Configure <OutOfProcessNodeJSServiceOptions>(options => options.TimeoutMS = 2000);
        }
Exemple #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add OpenID Connect server to produce JWT access tokens.
            services.AddAuthenticationServer();

            services.AddSignalR()
            //.AddMessagePackProtocol()
            ;
            services.AddDotNetify();
            services.AddDotNetifyPulse();
            services.AddMvc();

            services.AddScoped <IEmployeeRepository, EmployeeRepository>();
            services.AddSingleton <IMovieService, MovieService>();
            services.AddSingleton <IWebStoreService, WebStoreService>();

            StaticNodeJSService.Configure <OutOfProcessNodeJSServiceOptions>(options => options.TimeoutMS = 2000);
        }
Exemple #5
0
        public async void DisposeServiceProvider_RestartsNodeJSProcess()
        {
            // Arrange
            const string dummyTestVariableName  = "TEST_VARIABLE";
            const string dummyTestVariableValue = "testVariableValue";

            StaticNodeJSService.Configure <NodeJSProcessOptions>(options => options.EnvironmentVariables.Add(dummyTestVariableName, dummyTestVariableValue));
            string result1 = await StaticNodeJSService.
                             InvokeFromStringAsync <string>($"module.exports = (callback) => callback(null, process.env.{dummyTestVariableName});").ConfigureAwait(false);

            // Act
            StaticNodeJSService.DisposeServiceProvider(); // Dispose, environment variable should not be set in the next call

            // Assert
            string result2 = await StaticNodeJSService.
                             InvokeFromStringAsync <string>($"module.exports = (callback) => callback(null, process.env.{dummyTestVariableName});").ConfigureAwait(false);

            Assert.Equal(dummyTestVariableValue, result1);
            Assert.Equal(string.Empty, result2);
        }
        public async void DisposeServiceProvider_DisposesServiceProvider()
        {
            // Arrange
            const string dummyTestVariableName  = "TEST_VARIABLE";
            const string dummyTestVariableValue = "testVariableValue";

            StaticNodeJSService.
            Configure <NodeJSProcessOptions>(options => options.EnvironmentVariables.Add(dummyTestVariableName, dummyTestVariableValue));
            DummyResult initialInvocationResult = await StaticNodeJSService.
                                                  InvokeFromStringAsync <DummyResult>($"module.exports = (callback) => callback(null, {{result: process.env.{dummyTestVariableName}}});").
                                                  ConfigureAwait(false);

            // Act
            StaticNodeJSService.DisposeServiceProvider(); // Dispose, environment variable should not be set in the next call
            DummyResult result = await StaticNodeJSService.
                                 InvokeFromStringAsync <DummyResult>($"module.exports = (callback) => callback(null, {{result: process.env.{dummyTestVariableName}}});").
                                 ConfigureAwait(false);

            // Assert
            Assert.Equal(dummyTestVariableValue, initialInvocationResult.Result);
            Assert.Null(result.Result);
        }