Exemplo n.º 1
0
        protected virtual bool ProcessPortResponse()
        {
            bool complete = false;

            TimeoutTimer.Disarm();

            if (Test.Steps[CurrentStep].Response != null)
            {
                if (!string.IsNullOrEmpty(Test.Steps[CurrentStep].Response.Header))
                {
                    int index = ResponseBuffer.LastIndexOf(Test.Steps[CurrentStep].Response.Header);
                    if (index >= 0)
                    {
                        ResponseBuffer = ResponseBuffer.Substring(index);
                    }
                }
            }

            if (!string.IsNullOrEmpty(ResponseBuffer))
            {
                qf4net.QF.Instance.Publish(new RecorderEvent(QFSignal.RecorderRecord, Name, CurrentStep + 1, ResponseBuffer));
            }

            ResponseProcessor.Process(Test.Name, Test.Steps[CurrentStep], ResponseBuffer);
            ResponseBuffer = string.Empty;
            complete       = true;

            return(complete);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Makes a fetch call to scanii (http://docs.scanii.com/v2.1/resources.html#files)
        /// </summary>
        /// <param name="location">location (URL) of the content to be processed</param>
        /// <param name="callback">location (URL) to be notified and receive the result</param>
        /// <param name="metadata">optional metadata to be added to this file</param>
        /// <returns></returns>
        /// <exception cref="ScaniiException"></exception>
        public ScaniiResult Fetch(string location, string callback, Dictionary <string, string> metadata)
        {
            var req = new RestRequest("files/fetch", Method.POST);

            if (location != null)
            {
                req.AddParameter("location", location);
            }

            if (callback != null)
            {
                req.AddParameter("callback", callback);
            }

            foreach (var keyValuePair in metadata)
            {
                Log.Logger.Debug("medata item " + keyValuePair);
                req.AddParameter($"metadata[{keyValuePair.Key}]", keyValuePair.Value);
            }

            var resp = RestClient.Execute(req);

            if (resp.StatusCode != HttpStatusCode.Accepted)
            {
                throw new ScaniiException(
                          $"Invalid HTTP response from service, code: {resp.StatusCode} message: {resp.Content}");
            }

            Log.Logger.Information("response: " + resp.Content);
            Log.Logger.Debug("content " + resp.Content);
            Log.Logger.Debug("status code " + resp.StatusCode);

            return(ResponseProcessor.Process(resp));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Submits a file to be processed (http://docs.scanii.com/v2.1/resources.html#files)
        /// </summary>
        /// <param name="path">file path on the local system</param>
        /// <param name="metadata">optional metadata to be added to this file</param>
        /// <returns>processing result</returns>
        /// <exception cref="ScaniiException"></exception>
        public ScaniiResult Process(string path, Dictionary <string, string> metadata)
        {
            var req = new RestRequest("files", Method.POST);

            // adding payload
            req.AddFile("file", path);

            foreach (var keyValuePair in metadata)
            {
                Log.Logger.Debug("medata item " + keyValuePair);
                req.AddParameter($"metadata[{keyValuePair.Key}]", keyValuePair.Value);
            }

            var resp = RestClient.Execute(req);

            if (resp.StatusCode != HttpStatusCode.Created)
            {
                throw new ScaniiException(
                          $"Invalid HTTP response from service, code: {resp.StatusCode} message: {resp.Content}");
            }

            Log.Logger.Information("response: " + resp.Content);
            Log.Logger.Debug("content " + resp.Content);
            Log.Logger.Debug("status code " + resp.StatusCode);

            return(ResponseProcessor.Process(resp));
        }
Exemplo n.º 4
0
        private void ProcessQueue()
        {
            lock (m_ActionQueueLock)
            {
                if (m_ActionQueue.Count == 0)
                {
                    return;
                }
            }

            while (true)
            {
                ResponseProcessor action = null;
                bool bEmpty = false;
                lock (m_ActionQueueLock)
                {
                    action = m_ActionQueue.Dequeue();
                    bEmpty = m_ActionQueue.Count == 0;
                }
                action.Process();
                action.Dispose();

                if (bEmpty)
                {
                    break;
                }
            }
        }
        public void CanProcessResponse()
        {
            var responseProcessor = new ResponseProcessor(Constants.Iv, Constants.SecretKey);
            var testResult        = responseProcessor.Process(
                "cGhnd085RWpRNnJZdjVaVW9hVm9UWkR3cDB1L1Q1NE5LRlZraTlRNVI0a3RiaFczRnZqenBRcGFkU0EvanpPa3lqVVNJaDJjZmZXQ0VhSjJmTmFmMGVHRk5Sc3JVZmFmU2p0L0x3bENNOWdLZFJIa1RvRmtESnV5V1VtcUVmNjlFV3AwZ21TcjNRZW5xYmY0dlVUa29KV2dZeEg1M0tXd3Rja1pPd1IrbW1pZGNFbWJFR1d6dkFyTUVGVThzZW9oOVRkdDluZWo1dThnSHJ5TGxBSEI5TDBwUEFZS20yYUlZZWJsUFRsOU5yQW5ZdGFpcDJublFSNUcwU05Ob3pMR2xRcjFicDlxZ2lJb01pa29TdGRoOWxnUllwbWp2MDJqMER4ZGh0SkxaTjVFU2ZFTXdjRmpIdFM3REtkMnNLeVRvU3kvNTZncWlrc0VuRUlCTFRoUi8zUmp2VmRRbjRTd2IvNVVQRGhxNmpRZ0hYNkVqUVVaSitUZG9NYjR6Ty9VY3FEZjd1K0ZBeXdlR1RPVFh4Wm4wTHZkaFF6TVduYmJvOUREbm80RVBYMWQzMS9JaVM2d1F6dmhWU0UyZnl4ZHF6L3FoYk9WVzNJZS9PMFJ5UXJqemhvOC8zZ1ovWSt0NVJnS3gzeUxLTDBDN1Y3TW1aSlMrL0toUjJjUy9ETXVpenlUOE5hWmRXTy9zUTVOOU9aNm5iM3AwSUJ2TkRyRHV0R09jczJPSk1Jb21zeXFiOEs4ZXBVYnZNS0NURjUvZXhlNDZvMDRuZnN4aVorWkhmNWw4QVJWZzMrc1cvdzh0dmFndEM3NHc2c2Z0c0tzeEQ2ckVORU5zRDBlL0ltK1U3Qmc1UFhMaXhCNjFwdnArRGxRZ1R0bG5ReFlnV1h4SXE3WGhrNlEvL3Zmb2tYQzBCRGZjWm14ZGNHQXNZc2s=");
            var target = JsonConvert.DeserializeObject <PaymentResponse>(
                "{\"checkoutRequestID\":1721,\"totalAmount\":15000,\"accountNumber\":\"214577412301\",\"country\":\"KE\",\"currency\":\"KES\",\"payments\":[{\"payerTransactionID\":\"220055\",\"beepTransactionID\":\"998877\",\"amount\":\"3000\",\"accountNumber\":\"214577412301\",\"MSISDN\":\"254700000001\"},{\"payerTransactionID\":\"220055\",\"beepTransactionID\":\"998878\",\"amount\":\"500\",\"accountNumber\":\"214577412301\",\"MSISDN\":\"254700000001\"},{\"payerTransactionID\":\"220055\",\"beepTransactionID\":\"998879\",\"amount\":\"2000\",\"accountNumber\":\"214577412301\",\"MSISDN\":\"254700000001\"}]}");

            testResult.Should().BeEquivalentTo(target);
        }
Exemplo n.º 6
0
        public void TempuratureResponseTest()
        {
            XElement exerpt = XElement.Parse("<TestSets>" +
                                             "<TestSet Name=\"Bootup\">" +
                                             "<Test Type=\"Bootup\" Name=\"1A\">" +
                                             "<Step Type=\"Bootup\">" +
                                             "<Command>pro</Command>" +
                                             "<Response Delimiter=\"&#xA;\">" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'TEMPERATURES:*'</KeyExpression>" +
                                             "<Expected Trim=\"true\">" +
                                             "<KeyExpression>value like '*recvr*'</KeyExpression>" +
                                             "<Expression>value &gt;= -10</Expression>" +
                                             "<Expression>value &lt;= 70</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "<Expected Trim=\"true\"> Trim=\"true\"" +
                                             "<KeyExpression>value like '*bdc*'</KeyExpression>" +
                                             "<Expression>value &gt;= -10</Expression>" +
                                             "<Expression>value &lt;= 28</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "<Expected Trim=\"true\">" +
                                             "<KeyExpression>value like '*power supply*'</KeyExpression>" +
                                             "<Expression>value &gt;= -10</Expression>" +
                                             "<Expression>value &lt;= 35</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "</Response>" +
                                             "<Timeout>180</Timeout>" +
                                             "<BeginState>BOOT</BeginState>" +
                                             "<EndState>DSHELL</EndState>" +
                                             "<Retries>0</Retries>" +
                                             "</Step>" +
                                             "</Test>" +
                                             "</TestSet>" +
                                             "</TestSets>");

            TestSets collections = Hydrator.Hydrate("Test", exerpt);

            ResponseProcessor.Process("First Test", collections["Bootup"]["1A"].Steps[0], "TEMPERATURES: recvr 31 bdc 28 power supply 35");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Fetches the results of a previously processed file (http://docs.scanii.com/v2.1/resources.html#files)
        /// </summary>
        /// <param name="id">id of the content/file to be retrieved</param>
        /// <returns>ScaniiResult</returns>
        /// <exception cref="ScaniiException"></exception>
        public ScaniiResult Retrieve(string id)
        {
            var req = new RestRequest("files/{id}", Method.GET);

            req.AddParameter("id", id, ParameterType.UrlSegment);
            var resp = RestClient.Execute(req);

            if (resp.StatusCode != HttpStatusCode.OK)
            {
                throw new ScaniiException(
                          $"Invalid HTTP response from service, code: {resp.StatusCode} message: {resp.Content}");
            }

            return(ResponseProcessor.Process(resp));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new temporary authentication token (http://docs.scanii.com/v2.1/resources.html#auth-tokens)
        /// </summary>
        /// <param name="timeoutInSeconds">How long the token should be valid for</param>
        /// <returns>the new auth token</returns>
        /// <exception cref="ScaniiException"></exception>
        public ScaniiResult CreateAuthToken(int timeoutInSeconds = 300)
        {
            var req = new RestRequest("auth/tokens", Method.POST);

            req.AddParameter("timeout", timeoutInSeconds);
            var resp = RestClient.Execute(req);

            if (resp.StatusCode != HttpStatusCode.Created)
            {
                throw new ScaniiException(
                          $"Invalid HTTP response from service, code: {resp.StatusCode} message: {resp.Content}");
            }

            Log.Logger.Information("response: " + resp.Content);
            Log.Logger.Debug("content " + resp.Content);
            Log.Logger.Debug("status code " + resp.StatusCode);

            return(ResponseProcessor.Process(resp));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Retrieves a previously created auth token
        /// </summary>
        /// <param name="id">the id of the token to be retrieved</param>
        /// <returns></returns>
        /// <exception cref="ScaniiException"></exception>
        public ScaniiResult RetrieveAuthToken(string id)
        {
            var req = new RestRequest("auth/tokens/{id}", Method.GET);

            req.AddParameter("id", id, ParameterType.UrlSegment);

            var resp = RestClient.Execute(req);

            if (resp.StatusCode != HttpStatusCode.OK)
            {
                throw new ScaniiException(
                          $"Invalid HTTP response from service, code: {resp.StatusCode} message: {resp.Content}");
            }

            Log.Logger.Information("response: " + resp.Content);
            Log.Logger.Debug("content " + resp.Content);
            Log.Logger.Debug("status code " + resp.StatusCode);

            return(ResponseProcessor.Process(resp));
        }
Exemplo n.º 10
0
        public void COResponseFileTest()
        {
            TestSets testCollections = Hydrator.Hydrate("CO Command Test", COCommandXML);

            ResponseProcessor.BindEvents(testCollections["Bootup"], Assembly.GetAssembly(typeof(TruePosition.Test.Custom.CSharp.CustomCommandEvents))); //Assembly.GetAssembly(typeof(TruePosition.Test.Custom.CSharp.CustomCommandEvents)));

            ResponseProcessor.Process("1A", testCollections["Bootup"]["1A"].Steps[0], "ESN: " + "\n" +
                                      "GBE_CTLR:     NOT INSTALLED            " + "\n" +
                                      "GBE_LNA:      NOT INSTALLED            " + "\n" +
                                      "GBE:          NOT INSTALLED            " + "\n" +
                                      "GBE CUST ESN: NOT INSTALLED            " + "\n" +
                                      "LMU:          06162200D010082006501DA6 " + "\n" +
                                      "GPS RCVR:     06162200D010082006501DA6 " + "\n" +
                                      "RECEIVER:     06163900B0100820070403C2 " + "\n" +
                                      "BDC:          06164000C11008200704063B " + "\n" +
                                      "PSUPPLY:      06163400G0100820064300C1 " + "\n" +
                                      "CP/DSP:       06164100B1100820064700C2 " + "\n" +
                                      "DCARD:        06160301B010082006440005 " + "\n" +
                                      "EBOARD:       NOT INSTALLED            " + "\n" +
                                      "CUSTESN:      TRULMU5207872AE          " + "\n" +
                                      "TEMPERATURES: recvr 31 bdc 28 power supply 35" + "\n" +
                                      "TPESN:        06630000D010082007050130");
        }
Exemplo n.º 11
0
        public void COResponseStepTest()
        {
            XElement exerpt = XElement.Parse("<TestSets>" +
                                             "<TestSet Name=\"Bootup\">" +
                                             "<Test Type=\"Bootup\" Name=\"1A\">" +
                                             "<Step Type=\"Bootup\">" +
                                             "<Command>pro</Command>" +
                                             "<Response Delimiter=\"&#xA;\">" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'GPS RCVR:*'</KeyExpression>" +
                                             "<Expected Trim=\"true\">" +
                                             "<Expression>value lenge 24</Expression>" +
                                             "<Expression>value validesn</Expression>" +
                                             "<Expression>value not same</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage></FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'RECEIVER:*'</KeyExpression>" +
                                             "<Expected Trim=\"true\">" +
                                             "<Expression>value len 24</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage></FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'BDC:*'</KeyExpression>" +
                                             "<Expected Trim=\"true\">" +
                                             "<Expression>value lenge 24</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'PSUPPLY:*'</KeyExpression>" +
                                             "<Expected Trim=\"true\">" +
                                             "<Expression>value lenge 24</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'TEMPERATURES:*'</KeyExpression>" +
                                             "<Expected Trim=\"true\">" +
                                             "<KeyExpression>value like '*recvr*'</KeyExpression>" +
                                             "<Expression>value &gt;= -10</Expression>" +
                                             "<Expression>value &lt;= 31</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "<Expected Trim=\"true\">" +
                                             "<KeyExpression>value like '*bdc*'</KeyExpression>" +
                                             "<Expression>value &gt;= -10</Expression>" +
                                             "<Expression>value &lt;= 28</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>BDC Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "<Expected Trim=\"true\">" +
                                             "<KeyExpression>value like '*power supply*'</KeyExpression>" +
                                             "<Expression>value &gt;= -10</Expression>" +
                                             "<Expression>value &lt;= 35</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Power supply Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'CP/DSP:*'</KeyExpression>" +
                                             "<Expected Trim=\"true\">" +
                                             "<Expression>value len 24</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'DCARD:*'</KeyExpression>" +
                                             "<Expected Trim=\"true\">" +
                                             "<Expression>value lenge 24</Expression>" +
                                             "<Expression>value validesn</Expression>" +
                                             "<Expression>value not same</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'EBOARD:*'</KeyExpression>" +
                                             "<Expected Trim=\"false\">" +
                                             "<Expression>value lenge 24</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'CUSTESN:*'</KeyExpression>" +
                                             "<Expected Trim=\"true\">" +
                                             "<Expression>value lenge 15</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "<Element>" +
                                             "<KeyExpression>value like 'TPESN:*'</KeyExpression>" +
                                             "<Expected Trim=\"true\">" +
                                             "<Expression>value lenge 24</Expression>" +
                                             "<Destination>" +
                                             "<Name></Name>" +
                                             "<Default></Default>" +
                                             "</Destination>" +
                                             "<FailureMessage>Receiver Temperature outside limits</FailureMessage>" +
                                             "</Expected>" +
                                             "</Element>" +
                                             "</Response>" +
                                             "<Timeout>180</Timeout>" +
                                             "<BeginState>BOOT</BeginState>" +
                                             "<EndState>DSHELL</EndState>" +
                                             "<Retries>0</Retries>" +
                                             "</Step>" +
                                             "</Test>" +
                                             "</TestSet>" +
                                             "</TestSets>");

            TestSets collections = Hydrator.Hydrate("Test", exerpt);

            ResponseProcessor.Process("First Test", collections["Bootup"]["1A"].Steps[0], "ESN: " + "\n" +
                                      "GBE_CTLR:     NOT INSTALLED            " + "\n" +
                                      "GBE_LNA:      NOT INSTALLED            " + "\n" +
                                      "GBE:          NOT INSTALLED            " + "\n" +
                                      "GBE CUST ESN: NOT INSTALLED            " + "\n" +
                                      "GPS RCVR:     06162200D010082006501DA6 " + "\n" +
                                      "RECEIVER:     06163900B0100820070403C2 " + "\n" +
                                      "BDC:          06164000C11008200704063B " + "\n" +
                                      "PSUPPLY:      06163400G0100820064300C1 " + "\n" +
                                      "CP/DSP:       06164100B1100820064700C2 " + "\n" +
                                      "DCARD:        06160301B010082006440005 " + "\n" +
                                      "EBOARD:       NOT INSTALLED            " + "\n" +
                                      "CUSTESN:      TRULMU5207872AE          " + "\n" +
                                      "TEMPERATURES: recvr 31 bdc 28 power supply 35" + "\n" +
                                      "TPESN:        06630000D010082007050130");

            //element.Save(@"C:\Development\Kapsoft\True Position\Documents\COCommandTest.xml");
        }