Exemplo n.º 1
0
        public override FindRecordingResultList GetRecordingSearchResults(string SearchToken,
                                                                          int MinResults,
                                                                          bool MinResultsSpecified, int MaxResults, bool MaxResultsSpecified, string WaitTime)
        {
            RecordingSearchSession session =
                SearchSessionManager.Instance.GetSession(SearchToken) as RecordingSearchSession;

            if (session != null)
            {
                IList <RecordingInformation> data = (IList <RecordingInformation>)session.Data;

                // all data received
                if (data.Count == 0)
                {
                    CommonUtils.ReturnFault(new string[] { "Sender", "InvalidArgVal", "InvalidToken" });
                    return(null);
                }

                FindRecordingResultList list = new FindRecordingResultList();

                Random rnd = new Random();
                int    cnt = Math.Min(rnd.Next(1, 4), data.Count);

                rnd = new Random();
                int sleep = rnd.Next(1, 3);
                System.Threading.Thread.Sleep(400 * sleep + 450);

                list.RecordingInformation = new RecordingInformation[cnt];
                for (int i = 0; i < cnt; i++)
                {
                    list.RecordingInformation[i] = data[0];
                    data.RemoveAt(0);
                }
                session.ResultsSent = session.ResultsSent + cnt;
                list.SearchState    = data.Count > 0 ? SearchState.Searching : SearchState.Completed;

                if (data.Count == 0)
                {
                    SearchSessionManager.Instance.Sessions.Remove(session);
                }
                return(list);
            }
            else
            {
                CommonUtils.ReturnFault(new string[] { "Sender", "InvalidArgVal", "InvalidToken" });
                return(null);
            }
        }
Exemplo n.º 2
0
        protected FindRecordingResultList GetRecordingSearchResults(string searchToken, int?minResults, int?maxResults, string waitTime, string stepName)
        {
            FindRecordingResultList response = null;

            GetRecordingSearchResults request = new GetRecordingSearchResults();

            request.SearchToken         = searchToken;
            request.WaitTime            = waitTime;
            request.MaxResultsSpecified = maxResults.HasValue;
            request.MaxResults          = maxResults.GetValueOrDefault();
            request.MinResultsSpecified = minResults.HasValue;
            request.MinResults          = minResults.GetValueOrDefault();
            RunStep(() => { response = Client.GetRecordingSearchResults(request).ResultList; }, stepName);
            DoRequestDelay();
            return(response);
        }
Exemplo n.º 3
0
        protected List <RecordingInformation> GetAllRecordingsSearchResults(string searchToken, int?minResults, int?maxResults, string waitTime, out SearchState state)
        {
            DateTime requestSent      = DateTime.MinValue;
            DateTime responseReceived = DateTime.MinValue;

            Action <string> logRequest  = new Action <string>((s) => { requestSent = DateTime.Now; });
            Action <string> logResponse = new Action <string>((s) => { responseReceived = DateTime.Now; });

            _trafficListener.RequestSent      += logRequest;
            _trafficListener.ResponseReceived += logResponse;

            TimeSpan ts = new TimeSpan(0);

            if (!string.IsNullOrEmpty(waitTime))
            {
                ts = XmlConvert.ToTimeSpan(waitTime);
                ts = ts.Add(new TimeSpan(0, 0, 1));
            }

            try
            {
                List <RecordingInformation> recordingsList = new List <RecordingInformation>();

                FindRecordingResultList   response = null;
                GetRecordingSearchResults request  = new GetRecordingSearchResults();
                request.SearchToken         = searchToken;
                request.WaitTime            = waitTime;
                request.MaxResultsSpecified = maxResults.HasValue;
                request.MaxResults          = maxResults.GetValueOrDefault();
                request.MinResultsSpecified = minResults.HasValue;
                request.MinResults          = minResults.GetValueOrDefault();

                DateTime started      = DateTime.Now;
                DateTime dueTo        = started.AddSeconds(_searchTimeout);
                DateTime lastResponse = DateTime.Now;

                bool completed = true;

                LogTestEvent(string.Format("All results should be received by {0}{1}",
                                           dueTo.StdTimeToString(), Environment.NewLine));

                do
                {
                    RunStep(
                        () =>
                    {
                        response = Client.GetRecordingSearchResults(request).ResultList;
                    }, "Get Recording Search results");
                    lastResponse = DateTime.Now;
                    // no request delay here!
                    if (response.RecordingInformation != null)
                    {
                        recordingsList.AddRange(response.RecordingInformation);
                    }

                    if (lastResponse > dueTo)
                    {
                        completed = false;
                        break;
                    }

                    if (maxResults.HasValue)
                    {
                        int count = 0;
                        if (response.RecordingInformation != null)
                        {
                            count = response.RecordingInformation.Length;
                        }
                        state = response.SearchState;
                        Assert(count <= maxResults.Value, string.Format("Number of recordings received ({0}) is more than maxResults ({1})", count, maxResults.Value), "Check that maxResults parameter is not exceeded");
                    }

                    if (!string.IsNullOrEmpty(waitTime))
                    {
                        TimeSpan duration = responseReceived - requestSent;
                        Assert(duration < ts,
                               string.Format("Response received {0}.{1} seconds after request is sent (waitTime is {2})", duration.Seconds, duration.Milliseconds.ToString("000"), waitTime),
                               "Check that waitTime is taken into account");
                    }
                } while (response.SearchState != SearchState.Completed);

                state = response.SearchState;

                Assert(completed, string.Format("Completed state has not been achieved (last response received at {0}, State: {1})", lastResponse.StdTimeToString(), response.SearchState), "Check that search has been completed in due time");

                return(recordingsList);
            }
            finally
            {
                _trafficListener.RequestSent      -= logRequest;
                _trafficListener.ResponseReceived -= logResponse;
            }
        }
Exemplo n.º 4
0
        internal StepType GetRecordingSearchResultsTest(out FindRecordingResultList target, out SoapException ex, out int Timeout, string SearchToken, int MinResults, bool MinResultsSpecified, int MaxResults, bool MaxResultsSpecified, string WaitTime)
        {
            StepType res = StepType.None;

            Timeout = 0;
            ex      = null;
            target  = null;
            bool   passed     = true;
            string logMessage = "";

            string tmpCommandName   = "GetRecordingSearchResults";
            int    tmpCommandNumber = GetRecordingSearchResults;

            //Get step list for command
            XmlNodeList m_testList = TestCommon.GetStepsForCommand(ServiceName + "." + tmpCommandName);

            if (m_testList.Count != 0)
            {
                //Get current step
                XmlNode test = m_testList[CommandCount[tmpCommandNumber]];

                #region Analyze request

                //SearchToken
                CommonCompare.StringCompare("RequestParameters/SearchToken", "SearchToken", SearchToken, ref logMessage, ref passed, test);

                //MinResults
                if (CommonCompare.Exist2("RequestParameters/MinResults", "MinResults", MinResultsSpecified, ref logMessage, ref passed, test))
                {
                    CommonCompare.IntCompare("RequestParameters/MinResults", "MinResults", MinResults, ref logMessage, ref passed, test);
                }

                //MaxResults
                if (CommonCompare.Exist2("RequestParameters/MaxResults", "MaxResults", MaxResultsSpecified, ref logMessage, ref passed, test))
                {
                    CommonCompare.IntCompare("RequestParameters/MaxResults", "MaxResults", MaxResults, ref logMessage, ref passed, test);
                }

                //WaitTime
                CommonCompare.StringCompare("RequestParameters/WaitTime", "WaitTime", WaitTime, ref logMessage, ref passed, test);

                #endregion //Analyze request

                //Generate response
                int    useTimeOut = 0;
                object targetObj;
                res    = TestCommon.GenerateResponseStepTypeNotVoidSpecial(test, out targetObj, out ex, out Timeout, typeof(FindRecordingResultList), out useTimeOut);
                target = (FindRecordingResultList)targetObj;

                switch (useTimeOut)
                {
                case 1:
                {
                    System.Threading.Thread.Sleep(1000);
                    break;
                }

                case 2:
                {
                    System.Threading.Thread.Sleep(10000);
                    break;
                }
                }

                //Log message
                TestCommon.writeToLog(test, logMessage, passed);

                Increment(m_testList.Count, tmpCommandNumber);
            }
            else
            {
                throw new SoapException("NO " + ServiceName + "." + tmpCommandName + " COMMAND IN SCRIPT", SoapException.ServerFaultCode);
            }
            return(res);
        }