Export init args to environment. (#44)

diff --git a/core/dotnet3.1/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs b/core/dotnet3.1/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs
index ab04deb..fd8732f 100644
--- a/core/dotnet3.1/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs
+++ b/core/dotnet3.1/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs
@@ -20,6 +20,7 @@
 using System.Reflection;
 using System.Threading;
 using System.Threading.Tasks;
+using System.Collections.Generic;
 using Microsoft.AspNetCore.Http;
 using Newtonsoft.Json.Linq;
 
@@ -120,6 +121,17 @@
 
                 try
                 {
+                    // Export init arguments as environment variables
+                    if (message["env"] != null && message["env"].HasValues)
+                    {
+                        Dictionary<string, string> dictEnv = message["env"].ToObject<Dictionary<string, string>>();
+                        foreach (KeyValuePair<string, string> entry in dictEnv) {
+                            // See https://docs.microsoft.com/en-us/dotnet/api/system.environment.setenvironmentvariable
+                            // If entry.Value is null or the empty string, the variable is not set
+                            Environment.SetEnvironmentVariable(entry.Key, entry.Value);
+                        }
+                    }
+
                     Assembly assembly = Assembly.LoadFrom(assemblyPath);
                     Type = assembly.GetType(mainParts[1]);
                     if (Type == null)
diff --git a/tests/dotnetshared/Init.cs b/tests/dotnetshared/Init.cs
new file mode 100644
index 0000000..1c92aeb
--- /dev/null
+++ b/tests/dotnetshared/Init.cs
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using Newtonsoft.Json.Linq;
+
+namespace Apache.OpenWhisk.Tests.Dotnet
+{
+    public class Init
+    {
+        public static string SOME_VAR = System.Environment.GetEnvironmentVariable("SOME_VAR");
+        public static string ANOTHER_VAR = System.Environment.GetEnvironmentVariable("ANOTHER_VAR");
+
+        public JObject Main(JObject args)
+        {
+            JObject message = new JObject();
+            // an empty env variable is null, convert it to empty string to conform to test invariant
+            message.Add("SOME_VAR", new JValue(SOME_VAR != null ? SOME_VAR : ""));
+            message.Add("ANOTHER_VAR", new JValue(ANOTHER_VAR != null ? ANOTHER_VAR : ""));
+            return (message);
+        }
+    }
+}
diff --git a/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests.scala b/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests.scala
index a34d20b..8436252 100644
--- a/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests.scala
+++ b/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests.scala
@@ -47,6 +47,10 @@
     TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Environment::Main")
   }
 
+  override val testEnvParameters = {
+    TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Init::Main")
+  }
+
   override val testEcho = {
     TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.AltEcho::Main")
   }
diff --git a/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests_2_2.scala b/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests_2_2.scala
index 236051e..c3002e7 100644
--- a/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests_2_2.scala
+++ b/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests_2_2.scala
@@ -47,6 +47,10 @@
     TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Environment::Main")
   }
 
+  override val testEnvParameters = {
+    TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Init::Main")
+  }
+
   override val testEcho = {
     TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.AltEcho::Main")
   }