Request data via a http web request
Наследование: IRequestGenerator
Пример #1
0
        public void DataRetrieverRetrieveFailTest()
        {
            IDataCache dataCache = new NullDataCache();
            IRequestGenerator requestGenerator = new WebRequestGenerator();

            ResultEventArgs<Listings> resultEventArgs = null;

            using (AutoResetEvent waitEvent = new AutoResetEvent(false))
            {
                DataRetriever dataRetriever = new DataRetriever(dataCache, requestGenerator);

                EventHandler<ResultEventArgs<Listings>> completedHandler = (sender, res) =>
                {
                    resultEventArgs = res;
                    waitEvent.Set();
                };

                dataRetriever.StartRetrieve(new Uri(TestUri + "bad"), completedHandler);
                bool signalled = waitEvent.WaitOne(Constants.WaitTimeout);

                Assert.IsTrue(signalled);
            }

            Assert.IsNotNull(resultEventArgs);
            Assert.IsFalse(resultEventArgs.ResultStatus.Success);
        }
        public void RequestGeneratorRetrieveTest()
        {
            IRequestGenerator requestGenerator = new WebRequestGenerator();
            const string TestUri = "http://beta-api.etsy.com/v1/listings/featured/front?offset=0&limit=10&detail_level=low&api_key=" +
                NetsyData.EtsyApiKey;

            string resultString = string.Empty;
            Exception ex = null;

            using (AutoResetEvent waitEvent = new AutoResetEvent(false))
            {
                Action<string> successAction = s =>
                     {
                        resultString = s;
                        waitEvent.Set();
                     };

                Action<Exception> errorAction = e =>
                    {
                        ex = e;
                        waitEvent.Set();
                    };

                requestGenerator.StartRequest(new Uri(TestUri), successAction, errorAction);
                bool signalled = waitEvent.WaitOne(Constants.WaitTimeout);

                Assert.IsTrue(signalled);
                Assert.IsFalse(string.IsNullOrEmpty(resultString));
                Assert.IsNull(ex);
            }
        }
Пример #3
0
        public void DataRetrieverCreateWithParamsTest()
        {
            IDataCache dataCache = new NullDataCache();
            IRequestGenerator requestGenerator = new WebRequestGenerator();

            DataRetriever dataRetriever = new DataRetriever(dataCache, requestGenerator);
            Assert.IsNotNull(dataRetriever);
        }
        public void RequestGeneratorCreateTest()
        {
            IRequestGenerator requestGenerator = new WebRequestGenerator();

            Assert.IsNotNull(requestGenerator);
        }