示例#1
0
        public List<Result> Query(Query query)
        {
            if (query == null)
                throw new ArgumentNullException("query", "query is null.");

            if (query.ActionParameters.Count < 3)
                return ShowUsage(query);

            _context.API.StartLoadingBar();

            BaseTranslateService service;
            switch (_settings.ApiName)
            {
                case SettingElements.K_API_MYMEMORY:
                    service = new MyMemoryTranslateService(_settings, _context);
                    break;
                case SettingElements.K_API_YANDEX:
                default:
                    service = new YandexTranslateService(_settings, _context);
                    break;
            }

            try
            {
                string queryString = service.GetQueryString(query.GetAllRemainingParameter());
                var response = service.GetResponse(queryString);
                return service.TransformResponseToResults(response);
            }
            finally
            {
                _context.API.StopLoadingBar();
            }
        }
        public void TestMethod2()
        {
            BaseTranslateService service = new MyMemoryTranslateService(new SettingElements(), new PluginInitContext());

            var response = service.GetQueryString("en fr Hello");

            Assert.AreEqual("?q=Hello&langpair=en|fr", response);
        }
        public void TestMethod1()
        {
            BaseTranslateService service = new MyMemoryTranslateService(new SettingElements(), new PluginInitContext());

            var response = service.GetResponse("http://api.mymemory.translated.net/get?q=Hello%20World!&langpair=en|fr");
            var result = service.TransformResponseToResults(response);

            Assert.AreEqual(response.Matches.Length, result.Count);
        }