/// <summary>
 /// creates new knowledge base manager instance
 /// </summary>
 /// <param name="client">orbit client from which to fetch knowledge base information</param>
 /// <param name="logger">logger implementation to use for this knowledge base manager</param>
 public KnowledgeBaseManager(Orbit client, ILogger logger)
 {
     Logger    = logger.Setup(nameof(KnowledgeBaseManager));
     Client    = client;
     Actions   = client.Actions().Select(i => client.Actions(i));
     Macros    = Client.Macros().Select(i => client.Macros(i));
     Operators = new RhinoTestCaseFactory(Client).OperatorsMap;
 }
Esempio n. 2
0
 /// <summary>
 /// Creates a new instance of this Rhino.Agent.Domain.Repository.
 /// </summary>
 /// <param name="provider"><see cref="IServiceProvider"/> to use with this Rhino.Agent.Domain.RhinoTestCaseRepository.</param>
 public RhinoKbRepository(IServiceProvider provider)
     : base(provider)
 {
     Client      = provider.GetRequiredService <Orbit>();
     Macros      = Client.Macros().Select(i => Client.Macros(i));
     Operators   = new RhinoTestCaseFactory(Client).OperatorsMap;
     rhinoPlugin = provider.GetRequiredService <RhinoPluginRepository>();
 }
Esempio n. 3
0
        public async Task <IActionResult> Send()
        {
            // read test case from request body
            var requestBody = await Request.ReadAsync().ConfigureAwait(false);

            // parse into json token
            var token = JToken.Parse(requestBody);

            // parse test case & configuration
            var configuration = token["config"].ToObject <RhinoConfiguration>();
            var testCaseSrc   = JsonConvert.DeserializeObject <string[]>($"{token["test"]}");
            var testSuites    = $"{token["suite"]}".Split(";");

            // text connector
            if (configuration.ConnectorConfiguration.Connector.Equals(Connector.Text))
            {
                return(this.ContentTextResult(string.Join(Environment.NewLine, testCaseSrc), HttpStatusCode.OK));
            }

            // convert into bridge object
            var testCase = new RhinoTestCaseFactory(client)
                           .GetTestCases(string.Join(Environment.NewLine, testCaseSrc.Where(i => !string.IsNullOrEmpty(i))))
                           .First();

            testCase.TestSuites         = testSuites;
            testCase.Priority           = "2";
            testCase.Context["comment"] = Api.Extensions.Utilities.GetActionSignature("created");

            // get connector & create test case
            var connectorType = configuration.GetConnector(types);

            if (connectorType == default)
            {
                return(NotFound(new { Message = $"Connector [{configuration.ConnectorConfiguration.Connector}] was not found under the connectors repository." }));
            }

            var connector = (IConnector)Activator.CreateInstance(connectorType, new object[]
            {
                configuration, types, logger, false
            });

            connector.ProviderManager.CreateTestCase(testCase);

            // return results
            return(this.ContentResult(responseBody: testCase));
        }
        /// <summary>
        /// Generates a complete actions/macros knowledge base files under the current folder.
        /// </summary>
        /// <param name="path">Path under which to create the knowledge base files.</param>
        public void GenerateKnowledgeBase(string path)
        {
            // shortcuts
            var s = Assembly.GetExecutingAssembly();
            var m = Client.Macros();
            var a = Client.Actions();
            var l = Client.Locators().Select(i => i.PascalToSpaceCase());
            var o = new RhinoTestCaseFactory(Client).OperatorsMap.Select(i => i.Value);

            // layout
            path = path.EndsWith("\\") ? path : $"{path}\\";
            Directory.CreateDirectory(path + ActionsFolder);
            Directory.CreateDirectory(path + MacrosFolder);

            // generate knowledge base-files
            GenerateActionFiles(a, path);
            GenerateMacroFiles(m, path);
            GenerateReadmeFile(s, path);
            File.WriteAllLines($"{path}\\{Locators}", l);
            File.WriteAllLines($"{path}\\{OperatorsList}", o);
        }
 /// <summary>
 /// Creates a new instance of this Rhino.Api.Simulator.Framework.TextAutomationProvider.
 /// </summary>
 /// <param name="configuration">Rhino.Api.Contracts.Configuration.RhinoConfiguration to use with this provider.</param>
 /// <param name="types">A collection of <see cref="Type"/> to load for this repository.</param>
 /// <param name="logger">Gravity.Abstraction.Logging.ILogger implementation for this provider.</param>
 public TextAutomationProvider(RhinoConfiguration configuration, IEnumerable <Type> types, ILogger logger)
     : base(configuration, types, logger)
 {
     this.logger     = logger?.Setup(loggerName: nameof(TextAutomationProvider));
     testCaseFactory = new RhinoTestCaseFactory(logger);
 }
Esempio n. 6
0
        public async Task <IActionResult> Send()
        {
            // read test case from request body
            var requestBody = await Request.ReadAsync().ConfigureAwait(false);

            try
            {
                // parse into json token
                var token = JToken.Parse(requestBody);

                // parse test case & configuration
                var configuration = token["config"].ToObject <RhinoConfiguration>();
                var testCaseSrc   = JsonConvert.DeserializeObject <string[]>($"{token["test"]}");
                var testSuite     = $"{token["suite"]}";

                // text connector
                if (configuration.Connector.Equals(Connector.Text))
                {
                    return(new ContentResult
                    {
                        Content = string.Join(Environment.NewLine, testCaseSrc),
                        ContentType = MediaTypeNames.Text.Plain,
                        StatusCode = HttpStatusCode.OK.ToInt32()
                    });
                }

                // convert into bridge object
                var testCase = new RhinoTestCaseFactory(client)
                               .GetTestCases(string.Join(Environment.NewLine, testCaseSrc.Where(i => !string.IsNullOrEmpty(i))))
                               .First();
                testCase.TestSuite          = testSuite;
                testCase.Context["comment"] = Utilities.GetActionSignature("created");

                // get connector & create test case
                var connectorType = configuration.GetConnector(types);
                if (connectorType == default)
                {
                    return(NotFound(new { Message = $"Connector [{configuration.Connector}] was not found under the connectors repository." }));
                }

                var connector = (IConnector)Activator.CreateInstance(connectorType, new object[]
                {
                    configuration, types, logger, false
                });
                connector.ProviderManager.CreateTestCase(testCase);

                // return results
                return(new ContentResult
                {
                    Content = JsonConvert.SerializeObject(testCase),
                    ContentType = MediaTypeNames.Application.Json,
                    StatusCode = HttpStatusCode.Created.ToInt32()
                });
            }
            catch (Exception e) when(e != null)
            {
                return(new ContentResult
                {
                    Content = $"{e}",
                    ContentType = MediaTypeNames.Text.Plain,
                    StatusCode = HttpStatusCode.InternalServerError.ToInt32()
                });
            }
        }