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

            Assert.IsNotNull(ohtapi);

            var result = ohtapi.GetResource("rsc-560e7ea4650793-27822858", 0, "");

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

            ohtapi = new Ohtapi("", "", true);
            result = ohtapi.GetResource("rsc-560e7ea4650793-27822858", 0, "");

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

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

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

            result = ohtapi.GetResource(string.Empty);

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

            provider.Get(string.Empty, null, string.Empty, string.Empty, string.Empty).ReturnsForAnyArgs(ExpectedJsonResultErr);
            result = ohtapi.GetResource(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).ReturnsForAnyArgs(string.Empty);
            result = ohtapi.GetResource(string.Empty);

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

            var r = _api.GetResource(textResources.Text);

            textFileName.Text = r.Result.FileName;

            if (textFileName.Text == "")
            {
                textFileName.Text = String.Format("oht_{0}.txt", textResources.Text);
            }
            MessageBox.Show(r.ToString());
        }