public void ProfileDoesNotExist()
        {
            //initialize fresh log
            _testLogger.FullLog.Clear();
            var funcLoadReq = _functionLoadRequest.Clone();

            funcLoadReq.Metadata.Directory = AppDomain.CurrentDomain.BaseDirectory;

            try
            {
                FunctionLoader.SetupWellKnownPaths(funcLoadReq);
                _testManager.PerformRunspaceLevelInitialization();

                Assert.Single(_testLogger.FullLog);
                Assert.Matches("Trace: No 'profile.ps1' is found at the FunctionApp root folder: ", _testLogger.FullLog[0]);
            }
            finally
            {
                FunctionLoader.SetupWellKnownPaths(_functionLoadRequest);
            }
        }
        public void ProfileShouldWork()
        {
            //initialize fresh log
            _testLogger.FullLog.Clear();
            var funcLoadReq = _functionLoadRequest.Clone();

            funcLoadReq.Metadata.Directory = Path.Join(_functionDirectory, "ProfileBasic", "Func1");

            try
            {
                FunctionLoader.SetupWellKnownPaths(funcLoadReq);
                _testManager.PerformRunspaceLevelInitialization();

                Assert.Single(_testLogger.FullLog);
                Assert.Equal("Information: INFORMATION: Hello PROFILE", _testLogger.FullLog[0]);
            }
            finally
            {
                FunctionLoader.SetupWellKnownPaths(_functionLoadRequest);
            }
        }
        static HelperModuleTests()
        {
            var funcDirectory   = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "TestScripts", "PowerShell");
            var rpcFuncMetadata = new RpcFunctionMetadata()
            {
                Name       = "TestFuncApp",
                Directory  = funcDirectory,
                ScriptFile = Path.Join(funcDirectory, "testBasicFunction.ps1"),
                EntryPoint = string.Empty,
                Bindings   =
                {
                    { "req",    new BindingInfo {
                          Direction = BindingInfo.Types.Direction.In, Type = "httpTrigger"
                      } },
                    { Response, new BindingInfo {
                          Direction = BindingInfo.Types.Direction.Out, Type = "http"
                      } },
                    { Queue,    new BindingInfo {
                          Direction = BindingInfo.Types.Direction.Out, Type = "queue"
                      } },
                    { Foo,      new BindingInfo {
                          Direction = BindingInfo.Types.Direction.Out, Type = "new"
                      } },
                    { Bar,      new BindingInfo {
                          Direction = BindingInfo.Types.Direction.Out, Type = "new"
                      } },
                    { Food,     new BindingInfo {
                          Direction = BindingInfo.Types.Direction.Out, Type = "new"
                      } }
                }
            };

            var funcLoadReq = new FunctionLoadRequest {
                FunctionId = "FunctionId", Metadata = rpcFuncMetadata
            };

            FunctionLoader.SetupWellKnownPaths(funcLoadReq);
            s_pwsh     = Utils.NewPwshInstance();
            s_funcInfo = new AzFunctionInfo(rpcFuncMetadata);
        }
        public void ProfileWithNonTerminatingError()
        {
            //initialize fresh log
            _testLogger.FullLog.Clear();
            var funcLoadReq = _functionLoadRequest.Clone();

            funcLoadReq.Metadata.Directory = Path.Join(_functionDirectory, "ProfileWithNonTerminatingError", "Func1");

            try
            {
                FunctionLoader.SetupWellKnownPaths(funcLoadReq);
                _testManager.PerformRunspaceLevelInitialization();

                Assert.Equal(2, _testLogger.FullLog.Count);
                Assert.Equal("Error: ERROR: help me!", _testLogger.FullLog[0]);
                Assert.Matches("Error: Fail to run profile.ps1. See logs for detailed errors. Profile location: ", _testLogger.FullLog[1]);
            }
            finally
            {
                FunctionLoader.SetupWellKnownPaths(_functionLoadRequest);
            }
        }
        public PowerShellManagerTests()
        {
            _functionDirectory   = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "TestScripts", "PowerShell");
            _rpcFunctionMetadata = new RpcFunctionMetadata()
            {
                Name      = "TestFuncApp",
                Directory = _functionDirectory,
                Bindings  =
                {
                    { TestInputBindingName,  new BindingInfo {
                          Direction = BindingInfo.Types.Direction.In, Type = "httpTrigger"
                      } },
                    { TestOutputBindingName, new BindingInfo {
                          Direction = BindingInfo.Types.Direction.Out, Type = "http"
                      } }
                }
            };
            _functionLoadRequest = new FunctionLoadRequest {
                FunctionId = "FunctionId", Metadata = _rpcFunctionMetadata
            };
            FunctionLoader.SetupWellKnownPaths(_functionLoadRequest);

            _testLogger  = new ConsoleLogger();
            _testManager = new PowerShellManager(_testLogger);
            _testManager.PerformWorkerLevelInitialization();

            _testInputData = new List <ParameterBinding>
            {
                new ParameterBinding
                {
                    Name = TestInputBindingName,
                    Data = new TypedData
                    {
                        String = TestStringData
                    }
                }
            };
        }
Пример #6
0
        static TestUtils()
        {
            FunctionDirectory   = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "TestScripts", "PowerShell");
            RpcFunctionMetadata = new RpcFunctionMetadata()
            {
                Name      = "TestFuncApp",
                Directory = FunctionDirectory,
                Bindings  =
                {
                    { TestInputBindingName,  new BindingInfo {
                          Direction = BindingInfo.Types.Direction.In, Type = "httpTrigger"
                      } },
                    { TestOutputBindingName, new BindingInfo {
                          Direction = BindingInfo.Types.Direction.Out, Type = "http"
                      } }
                }
            };

            FunctionLoadRequest = new FunctionLoadRequest {
                FunctionId = "FunctionId", Metadata = RpcFunctionMetadata
            };
            FunctionLoader.SetupWellKnownPaths(FunctionLoadRequest);
        }