Пример #1
0
        public void ProcessOperationFromJsonFull()
        {
            MockRunspaceManager runspace = new MockRunspaceManager();
            GeneratedModule     module   = new GeneratedModule(runspace);

            module.Operations["thing_get"] = new OperationData("Thing_Get", "Get-Thing")
            {
                Parameters = new Dictionary <string, ParameterData>()
                {
                    { "parameter", new ParameterData()
                      {
                          Name = "Parameter", Type = new RuntimeTypeData(typeof(GeneratedModuleTestsObject))
                      } }
                }
            };

            string json = "{\"method\":\"Things.Thing_Get\",\"params\":{\"__reserved\":{\"credentials\":[{\"x-ps-credtype\":\"commandBased\",\"tenantId\":\"testTenantId\",\"clientId\":\"testClientId\",\"secret\":\"testSecret\"},{\"x-ps-credtype\":\"parameterBased\",\"tenantId\":\"testTenantId\",\"clientId\":\"testClientId\",\"secret\":\"testSecret\"}]},\"parameter\":{\"string\":\"testValue\",\"number\":500,\"object\":{\"decimal\":1.2,\"boolean\":true}}}}";
            LiveTestRequestConverter converter = new LiveTestRequestConverter(module);

            Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
            converter.RegisterSelf(settings);

            MockTestCredentialFactory credentialsFactory = new MockTestCredentialFactory();

            credentialsFactory.RegisterProvider("commandbased", new CommandBasedCredentialProvider());
            credentialsFactory.RegisterProvider("parameterbased", new ParameterBasedCredentialProvider());

            LiveTestRequest        request = Newtonsoft.Json.JsonConvert.DeserializeObject <LiveTestRequest>(json, settings);
            CommandExecutionResult result  = module.ProcessRequest(request, credentialsFactory);

            Assert.Equal("Login-Account [parameter {[String testValue] [Number 500] [Object [Decimal 1.2] [Boolean True]]}]", (string)runspace.InvokeHistory[0]);
            Assert.Equal("Login-Account [parameter {[String testValue] [Number 500] [Object [Decimal 1.2] [Boolean True]]}] [CredentialKey testCredentials]", (string)runspace.InvokeHistory[1]);
        }
Пример #2
0
        public void ProcessOperationWithCredentials()
        {
            MockRunspaceManager runspace = new MockRunspaceManager();
            GeneratedModule     module   = new GeneratedModule(runspace);

            module.Operations["thing_get"] = new OperationData("Thing_Get", "Get-Thing");

            MockTestCredentialFactory credentialsFactory = new MockTestCredentialFactory();

            credentialsFactory.RegisterProvider("commandbased", new CommandBasedCredentialProvider());
            credentialsFactory.RegisterProvider("parameterbased", new ParameterBasedCredentialProvider());
            LiveTestRequest request = new LiveTestRequest();

            request.Method      = "Things.Thing_Get";
            request.OperationId = "Thing_Get";
            request.Params      = new Dictionary <string, object>()
            {
                { "__reserved", new Dictionary <string, object>()
                  {
                      { "credentials", new LiveTestCredentials[] { new LiveTestCredentials()
                                                                   {
                                                                       Type       = "commandBased",
                                                                       Properties = new Dictionary <string, object>()
                                                                       {
                                                                           { "tenantId", "testTenantId" },
                                                                           { "clientId", "testClientId" },
                                                                           { "secret", "testSecret" }
                                                                       }
                                                                   }, new LiveTestCredentials()
                                                                   {
                                                                       Type       = "parameterBased",
                                                                       Properties = new Dictionary <string, object>()
                                                                       {
                                                                           { "tenantId", "testTenantId" },
                                                                           { "clientId", "testClientId" },
                                                                           { "secret", "testSecret" }
                                                                       }
                                                                   } } }
                  } }
            };
            request.Params["parameter"] = new GeneratedModuleTestsObject()
            {
                String = "testValue",
                Number = 500,
                Object = new GeneratedModuleTestsSubObject()
                {
                    Decimal = 1.2,
                    Boolean = true
                }
            };

            CommandExecutionResult result = module.ProcessRequest(request, credentialsFactory);

            Assert.Equal(2, runspace.InvokeHistory.Count);
            Assert.Equal("Login-Account", (string)runspace.InvokeHistory[0]);
            Assert.Equal("Login-Account [CredentialKey testCredentials]", (string)runspace.InvokeHistory[1]);
        }
Пример #3
0
        public void ProcessOperationSimpleParameters()
        {
            MockRunspaceManager runspace = new MockRunspaceManager();
            GeneratedModule     module   = new GeneratedModule(runspace);

            module.Operations["thing_get"] = new OperationData("Thing_Get", "Get-Thing")
            {
                Parameters = new Dictionary <string, ParameterData>()
                {
                    { "Integer", new ParameterData()
                      {
                          Name = "Integer", Type = new RuntimeTypeData(typeof(int))
                      } },
                    { "Boolean", new ParameterData()
                      {
                          Name = "Boolean", Type = new RuntimeTypeData(typeof(bool))
                      } },
                    { "Decimal", new ParameterData()
                      {
                          Name = "Decimal", Type = new RuntimeTypeData(typeof(double))
                      } },
                    { "String", new ParameterData()
                      {
                          Name = "String", Type = new RuntimeTypeData(typeof(string))
                      } }
                }
            };

            MockTestCredentialFactory credentialsFactory = new MockTestCredentialFactory();
            LiveTestRequest           request            = new LiveTestRequest();

            request.Method            = "Things.Thing_Get";
            request.OperationId       = "Thing_Get";
            request.Params            = new Dictionary <string, object>();
            request.Params["integer"] = 5;
            request.Params["boolean"] = true;
            request.Params["decimal"] = 1.2;
            request.Params["string"]  = "testValue";

            CommandExecutionResult result = module.ProcessRequest(request, credentialsFactory);

            Assert.Equal(1, runspace.InvokeHistory.Count);
            Assert.Equal("Get-Thing [Integer 5] [Boolean True] [Decimal 1.2] [String testValue]", ((string)runspace.InvokeHistory[0]));
        }
Пример #4
0
        public void ProcessOperationComplexParameters()
        {
            MockRunspaceManager runspace = new MockRunspaceManager();
            GeneratedModule     module   = new GeneratedModule(runspace);

            module.Operations["thing_get"] = new OperationData("Thing_Get", "Get-Thing")
            {
                Parameters = new Dictionary <string, ParameterData>()
                {
                    { "Parameter", new ParameterData()
                      {
                          Name = "Parameter", Type = new RuntimeTypeData(typeof(GeneratedModuleTestsObject))
                      } }
                }
            };

            MockTestCredentialFactory credentialsFactory = new MockTestCredentialFactory();
            LiveTestRequest           request            = new LiveTestRequest();

            request.Method              = "Things.Thing_Get";
            request.OperationId         = "Thing_Get";
            request.Params              = new Dictionary <string, object>();
            request.Params["parameter"] = new GeneratedModuleTestsObject()
            {
                String = "testValue",
                Number = 500,
                Object = new GeneratedModuleTestsSubObject()
                {
                    Decimal = 1.2,
                    Boolean = true
                }
            };

            CommandExecutionResult result = module.ProcessRequest(request, credentialsFactory);

            Assert.Equal(1, runspace.InvokeHistory.Count);
            Assert.Equal("Get-Thing [Parameter {[String testValue] [Number 500] [Object [Decimal 1.2] [Boolean True]]}]", (string)runspace.InvokeHistory[0]);
        }