コード例 #1
0
        public void TestLongRequest_SimplePoll()
        {
            Logger          logger          = new Logger();
            ServerConnector serverConnector = new ServerConnector(logger);

            serverConnector.ServerUrl = new Uri(CommonData.DefaultServerUrl);
            MockHttpRestClientFactory mockHttpRestClientFactory = new MockHttpRestClientFactory(
                logger,
                new int?[] { 2, null, 3 },
                new string[] { CommonData.DefaultServerUrl + "url1", null, CommonData.DefaultServerUrl + "url2" });

            serverConnector.HttpRestClientFactory = mockHttpRestClientFactory;
            serverConnector.ApiKey = "testKey";

            SessionStartInfo startInfo = GetStartInfo();
            RunningSession   result    = serverConnector.StartSession(startInfo);

            var             requestCreator = mockHttpRestClientFactory.Provider.Handler;
            List <string>   requests       = requestCreator.RequestUrls;
            List <TimeSpan> timings        = requestCreator.Timings;

            Assert.AreEqual(6, requests.Count);
            Assert.AreEqual(6, timings.Count);
            StringAssert.StartsWith(CommonData.DefaultServerUrl + "api/sessions/running", requests[0]);
            StringAssert.StartsWith(CommonData.DefaultServerUrl + BASE_LOCATION + "status", requests[1]);

            StringAssert.StartsWith(CommonData.DefaultServerUrl + "url1", requests[2]);
            Assert.Greater(timings[2], TimeSpan.FromSeconds(2));

            StringAssert.StartsWith(CommonData.DefaultServerUrl + "url1", requests[3]);
            Assert.Greater(timings[3], TimeSpan.FromSeconds(0.5));

            StringAssert.StartsWith(CommonData.DefaultServerUrl + "url2", requests[4]);
            Assert.Greater(timings[4], TimeSpan.FromSeconds(3));
        }
コード例 #2
0
        /// <summary>
        /// Gets the text of the specified language appearing in the input image region
        /// </summary>
        public string[] GetTextInRunningSessionImage(
            RunningSession session,
            string imageId,
            IList <Rectangle> regions,
            string language = null)
        {
            ArgumentGuard.NotNull(session, nameof(session));
            ArgumentGuard.NotNull(imageId, nameof(imageId));
            ArgumentGuard.NotNull(regions, nameof(regions));

            var getText = new GetText_()
            {
                Regions  = new List <Region>(regions.Select(r => new Region(r))),
                Language = language,
            };

            using (var response = httpClient_.PostJson(
                       $"api/sessions/running/images/{imageId}/text",
                       getText))
            {
                if (response == null)
                {
                    throw new NullReferenceException("response is null");
                }
                return(response.DeserializeBody <string[]>(true));
            }
        }
コード例 #3
0
        protected EyesBase(IServerConnectorFactory serverConnectorFactory)
        {
            ServerConnectorFactory = serverConnectorFactory;

            Logger = new Logger();

            //EnsureConfiguration_();

            ServerConnector = ServerConnectorFactory.CreateNewServerConnector(Logger);
            runningSession_ = null;
            UserInputs      = new List <Trigger>();

            properties_ = new PropertiesCollection();

            setScaleProvider_ = provider => { scaleProvider_ = provider; };
            scaleProvider_    = NullScaleProvider.Instance;
            cutProvider_      = NullCutProvider.Instance;

            StackTrace stackTrace = new StackTrace();

            StackFrame[] stackFrames = stackTrace.GetFrames();
            foreach (StackFrame stackFrame in stackFrames)
            {
                Type callingType = stackFrame.GetMethod().DeclaringType;
                if (callingType.IsAbstract)
                {
                    continue;
                }
                actualAssembly_ = callingType.Assembly;
                break;
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates a new <see cref="MatchWindowData"/> instance.
        /// </summary>
        /// <param name="appOutput">The appOutput for the current matchWindow call.</param>
        /// <param name="tag">The step name to use.</param>
        /// <param name="agentSetup">The test setup parameters used.</param>
        public MatchWindowData(RunningSession runningSession, AppOutput appOutput, string tag, object agentSetup = null)
        {
            ArgumentGuard.NotNull(appOutput, nameof(appOutput));

            RunningSession = runningSession;
            AppOutput      = appOutput;
            Tag            = tag;
            AgentSetup     = agentSetup;
        }
コード例 #5
0
        public RunningSession Open(string testId, SessionStartInfo sessionStartInfo)
        {
            SyncTaskListener <RunningSession> listener = new SyncTaskListener <RunningSession>(logger: Logger, testIds: testId);

            openService_.Operate(testId, sessionStartInfo, listener);
            RunningSession result = listener.Get();

            if (result == null)
            {
                throw new EyesException("Failed starting session with the server", listener.Exception);
            }
            return(result);
        }
コード例 #6
0
        public void TestStartSession_LongRequest_IsNewField(bool isNew)
        {
            Logger          logger          = new Logger();
            ServerConnector serverConnector = new ServerConnector(logger);

            serverConnector.ServerUrl             = new Uri(CommonData.DefaultServerUrl);
            serverConnector.HttpRestClientFactory = new MockHttpRestClientFactory(isNew: isNew);
            serverConnector.ApiKey = "testKey";
            SessionStartInfo startInfo = GetStartInfo();
            RunningSession   result    = serverConnector.StartSession(startInfo);

            Assert.AreEqual(isNew, result.IsNewSession);
        }
コード例 #7
0
        public void TestDataStructure()
        {
            RunningSession rs = new RunningSession();

            Assert.IsNull(rs.isNewSession_);
            Assert.IsNull(rs.Id);
            Assert.IsNull(rs.Url);
            rs.isNewSession_ = true;
            rs.Url           = "dummy url";
            rs.Id            = "dummy id";
            Assert.AreEqual(true, rs.IsNewSession);
            Assert.AreEqual("dummy url", rs.Url);
            Assert.AreEqual("dummy id", rs.Id);
        }
コード例 #8
0
        public MatchWindowTask(Logger logger, IServerConnector serverConnector,
                               RunningSession runningSession, TimeSpan retryTimeout,
                               EyesBase eyes)
        {
            ArgumentGuard.NotNull(logger, nameof(logger));
            ArgumentGuard.NotNull(serverConnector, nameof(serverConnector));
            ArgumentGuard.NotNull(runningSession, nameof(runningSession));

            Logger_              = logger;
            serverConnector_     = serverConnector;
            runningSession_      = runningSession;
            defaultRetryTimeout_ = (int)retryTimeout.TotalMilliseconds;
            getAppOutput_        = null;
            eyes_ = eyes;
        }
コード例 #9
0
        public void TestStartSession_LongRequest_StatusCode(HttpStatusCode statusCode)
        {
            Logger          logger          = new Logger();
            ServerConnector serverConnector = new ServerConnector(logger);

            serverConnector.ServerUrl             = new Uri(CommonData.DefaultServerUrl);
            serverConnector.HttpRestClientFactory = new MockHttpRestClientFactory(statusCode: statusCode);
            serverConnector.ApiKey = "testKey";
            SessionStartInfo startInfo = GetStartInfo();
            RunningSession   result    = serverConnector.StartSession(startInfo);

            bool isNew = statusCode == HttpStatusCode.Created;

            Assert.AreEqual(isNew, result.IsNewSession);
        }
コード例 #10
0
        public void TestCtor()
        {
            RunningSession     runningSession = new RunningSession();
            MatchWindowData    mwd            = new MatchWindowData(runningSession, appOut_, "mytag");
            ImageMatchSettings ims            = new ImageMatchSettings();

            mwd.Options            = new ImageMatchOptions(ims);
            mwd.Options.UserInputs = new Trigger[] { trigger_ };
            Assert.AreEqual(appOut_, mwd.AppOutput);
            Assert.AreEqual(new Trigger[] { trigger_ }, mwd.Options.UserInputs);
            Assert.AreEqual("mytag", mwd.Tag);
            new MatchWindowData(runningSession, appOut_, "tag");
            Assert.Throws <ArgumentNullException>(() => new MatchWindowData(runningSession, null, "tag"));
            var ok = new MatchWindowData(runningSession, appOut_, null);
        }
コード例 #11
0
        protected virtual void StartSessionInternal(TaskListener <RunningSession> taskListener, SessionStartInfo startInfo)
        {
            ArgumentGuard.NotNull(startInfo, nameof(startInfo));

            var body = new
            {
                StartInfo = startInfo
            };

            try
            {
                EnsureHttpClient_();
                httpClient_.PostJson(
                    new TaskListener <HttpResponseMessage>(
                        response =>
                {
                    if (response == null)
                    {
                        throw new NullReferenceException("response is null");
                    }
                    // response.DeserializeBody disposes the response object's stream,
                    // rendering all of its properties unusable, including StatusCode.
                    HttpStatusCode responseStatusCode = response.StatusCode;
                    RunningSession runningSession;
                    if (responseStatusCode == HttpStatusCode.ServiceUnavailable)
                    {
                        runningSession = new RunningSession();
                        runningSession.ConcurrencyFull = true;
                    }
                    else
                    {
                        runningSession = response.DeserializeBody <RunningSession>(
                            true, serializer_, HttpStatusCode.OK, HttpStatusCode.Created);
                        if (runningSession.isNewSession_ == null)
                        {
                            runningSession.isNewSession_ = responseStatusCode == HttpStatusCode.Created;
                        }
                        runningSession.ConcurrencyFull = false;
                    }
                    taskListener.OnComplete(runningSession);
                }, ex => taskListener.OnFail(ex))
                    , "api/sessions/running", body);
            }
            catch (Exception ex)
            {
                throw new EyesException($"StartSession failed: {ex.Message}", ex);
            }
        }
コード例 #12
0
        private void Init_(ClassicRunner runner, Logger logger)
        {
            runner_ = runner ?? new ClassicRunner();
            Logger  = logger ?? new Logger();

            runner_.SetEyes(this);

            //EnsureConfiguration_();

            UpdateActualAssembly_();
            runningSession_ = null;
            UserInputs      = new List <Trigger>();
            properties_     = new PropertiesCollection();

            setScaleProvider_ = provider => { scaleProvider_ = provider; };
            scaleProvider_    = NullScaleProvider.Instance;
            cutProvider_      = NullCutProvider.Instance;
        }
コード例 #13
0
                public MockWebRequestCreator(bool?isNew, HttpStatusCode?statusCode)
                {
                    RunningSession runningSession = new RunningSession()
                    {
                        Id            = "MDAwMDAyNTE4MTU1OTk5NDE2NjQ~;MDAwMDAyNTE4MTU1OTk5NDExNDE~",
                        SessionId     = "00000251815599941141",
                        BatchId       = "00000251815599941664",
                        BaselineId    = "16c7e248-7732-4ed3-b380-47889492ccc4.5d9e472a-8b3b-4e3d-ae86-72efcf77e19e.l_j7LZkpj6_rUc9bgnXRbyyZPvlLi00PX_7ZsJbd7ls_.",
                        isNewSession_ = isNew,
                        Url           = "https://eyes.applitools.com/app/batches/00000251815599941664/00000251815599941141?accountId=m9QzkQCbDkyTxwMrJ4fKkQ~~"
                    };

                    statusCode_ = statusCode;
                    string responseObjJson = JsonConvert.SerializeObject(runningSession);

                    byte[] byteArray = Encoding.UTF8.GetBytes(responseObjJson);
                    responseStream_ = new MemoryStream(byteArray);
                }
コード例 #14
0
                    public MockMessageProcessingHandler(bool?isNew, HttpStatusCode?statusCode, int?[] retryAfter, string[] pollingUrls)
                    {
                        RunningSession runningSession = new RunningSession()
                        {
                            Id            = "MDAwMDAyNTE4MTU1OTk5NDE2NjQ~;MDAwMDAyNTE4MTU1OTk5NDExNDE~",
                            SessionId     = "00000251815599941141",
                            BatchId       = "00000251815599941664",
                            BaselineId    = "16c7e248-7732-4ed3-b380-47889492ccc4.5d9e472a-8b3b-4e3d-ae86-72efcf77e19e.l_j7LZkpj6_rUc9bgnXRbyyZPvlLi00PX_7ZsJbd7ls_.",
                            isNewSession_ = isNew,
                            Url           = "https://eyes.applitools.com/app/batches/00000251815599941664/00000251815599941141?accountId=m9QzkQCbDkyTxwMrJ4fKkQ~~"
                        };

                        statusCode_  = statusCode;
                        pollingUrls_ = pollingUrls;
                        retryAfter_  = retryAfter;
                        iterations_  = pollingUrls?.Length ?? retryAfter?.Length ?? 0;
                        string responseObjJson = JsonConvert.SerializeObject(runningSession);

                        responseBytes_ = Encoding.UTF8.GetBytes(responseObjJson);
                    }
コード例 #15
0
        // Used only by IN-REGION

        /// <summary>
        /// Adds the input image to the running session and returns its id.
        /// </summary>
        public string AddRunningSessionImage(RunningSession session, byte[] image)
        {
            ArgumentGuard.NotNull(session, nameof(session));
            ArgumentGuard.NotNull(image, nameof(image));

            try
            {
                using (var response = httpClient_.Post(
                           "api/sessions/running/" + session.Id + "/images",
                           new MemoryStream(image),
                           "application/octet-stream",
                           "application/json"))
                {
                    Uri locationUri = response.Headers.Location;
                    return(locationUri.Segments.Last());
                }
            }
            catch (Exception ex)
            {
                throw new EyesException($"AddRunningSessionImage failed: {ex.Message}", ex);
            }
        }
コード例 #16
0
 protected internal override void OpenCompleted(RunningSession result)
 {
     inOpenProcess_ = false;
     base.OpenCompleted(result);
 }
コード例 #17
0
 public SessionStopInfo(RunningSession runningSession, bool isAborted, bool shouldSave)
 {
     RunningSession = runningSession;
     Aborted        = isAborted;
     UpdateBaseline = shouldSave;
 }