Esempio n. 1
0
        public void Test()
        {
            Ohtapi ohtapi = new Ohtapi(Tools.TestPublicKey, Tools.TestSecretKey, true);

            Assert.IsNotNull(ohtapi);

            var result = ohtapi.GetQuote("rsc-560e7ea4650793-27822858", "", "en-us", "ru-ru");

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Status.Code);

            ohtapi = new Ohtapi("", "", true);
            result = ohtapi.GetQuote("rsc-560e7ea4650793-27822858", "", "en-us", "ru-ru");

            Assert.IsNotNull(result);
            Assert.AreNotEqual(0, result.Status.Code);
            Assert.AreNotEqual(-1, result.Status.Code);

            var provider = Substitute.For <IGetQuoteProvider>();

            ohtapi.GetQuoteProvider = provider;
            provider.Get(string.Empty, null, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty).ReturnsForAnyArgs(ExpectedJsonResultOk);

            result = ohtapi.GetQuote(string.Empty, string.Empty, string.Empty, string.Empty);

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Status.Code);

            provider.Get(string.Empty, null, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty).ReturnsForAnyArgs(ExpectedJsonResultErr);
            result = ohtapi.GetQuote(string.Empty, string.Empty, string.Empty, string.Empty);

            Assert.IsNotNull(result);
            Assert.AreNotEqual(0, result.Status.Code);
            Assert.AreNotEqual(-1, result.Status.Code);

            provider.Get(string.Empty, null, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty).ReturnsForAnyArgs(string.Empty);
            result = ohtapi.GetQuote(string.Empty, string.Empty, string.Empty, string.Empty);

            Assert.IsNotNull(result);
            Assert.AreEqual(-1, result.Status.Code);
        }
Esempio n. 2
0
        private void butGetQuote_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(textGetQuoteResources.Text))
            {
                tools.SetMsg("enter", textGetQuoteResources);
                return;
            }

            if (!String.IsNullOrWhiteSpace(textWordcount.Text))
            {
                long num;
                if (!Int64.TryParse(textWordcount.Text, out num))
                {
                    textWordcount.Text = "";
                    tools.SetMsg("enter integer or empty", textGetQuoteResources);
                    return;
                }
            }


            if (String.IsNullOrWhiteSpace(combosource_language.Text))
            {
                tools.SetMsg("click", butSupportedLanguages);
                tools.SetMsg("enter", combosource_language);
                return;
            }
            if (String.IsNullOrWhiteSpace(combotarget_language.Text))
            {
                tools.SetMsg("click", butSupportedLanguages);
                tools.SetMsg("enter", combotarget_language);
                return;
            }


            var r = _api.GetQuote(textGetQuoteResources.Text, textWordcount.Text, combosource_language.Text, combotarget_language.Text, StringService.None, "", StringProofreading.None, StringCurrency.None);

            MessageBox.Show(r.ToString());
        }