A mock RequestGenerator that returns the given data
Inheritance: IRequestGenerator
        public void GetFrontFeaturedListingsTest()
        {
            EtsyContext etsyContext = new EtsyContext(Constants.DummyEtsyApiKey);
            MockFixedDataRequestGenerator requestGenerator = new MockFixedDataRequestGenerator(GetFrontFeaturedListingsRawResults);
            DataRetriever dataRetriever = new DataRetriever(new NullDataCache(), requestGenerator);
            IListingsService etsyListingsService = new ListingsService(etsyContext, dataRetriever);

            using (AutoResetEvent waitEvent = new AutoResetEvent(false))
            {
                ResultEventArgs<Listings> result = null;
                etsyListingsService.GetFrontFeaturedListingsCompleted += (s, e) =>
                {
                    result = e;
                    waitEvent.Set();
                };

                // ACT
                etsyListingsService.GetFrontFeaturedListings(0, 10, DetailLevel.Low);
                bool signalled = waitEvent.WaitOne(Constants.WaitTimeout);

                // ASSERT

                // check that the event was fired, did not time out
                Assert.IsTrue(signalled, "Not signalled");

                TestHelpers.CheckResultSuccess(result);
            }
        }
        public void GetTopCategoriesTest()
        {
            EtsyContext etsyContext = new EtsyContext(Constants.DummyEtsyApiKey);
            MockFixedDataRequestGenerator requestGenerator = new MockFixedDataRequestGenerator(GetTopCategoriesRawResults);
            DataRetriever dataRetriever = new DataRetriever(new NullDataCache(), requestGenerator);
            ITagCategoryService etsyTagCategoryService = new TagCategoryService(etsyContext, dataRetriever);

            using (AutoResetEvent waitEvent = new AutoResetEvent(false))
            {
                ResultEventArgs<StringResults> result = null;
                etsyTagCategoryService.GetTopCategoriesCompleted += (s, e) =>
                {
                    result = e;
                    waitEvent.Set();
                };

                // ACT
                etsyTagCategoryService.GetTopCategories();
                bool signalled = waitEvent.WaitOne(Constants.WaitTimeout);

                // ASSERT

                // check that the event was fired, did not time out
                Assert.IsTrue(signalled, "Not signalled");

                // check the data
                TestHelpers.CheckResultSuccess(result);
            }
        }
        public void DataRetrieverCreateWithParamsTest()
        {
            IDataCache dataCache = new NullDataCache();
            IRequestGenerator requestGenerator = new MockFixedDataRequestGenerator(string.Empty);

            DataRetriever dataRetriever = new DataRetriever(dataCache, requestGenerator);
            Assert.IsNotNull(dataRetriever);
        }
        public void CreateWithMockRequestTest()
        {
            EtsyContext etsyContext = new EtsyContext(string.Empty);
            IRequestGenerator requestGenerator = new MockFixedDataRequestGenerator(string.Empty);
            DataRetriever dataRetriever = new DataRetriever(new NullDataCache(), requestGenerator);
            IListingsService service = new ListingsService(etsyContext, dataRetriever);

            Assert.IsNotNull(service);
        }
        public void DataRetrieverRetrieveSuccessTest()
        {
            IDataCache dataCache = new NullDataCache();
            IRequestGenerator requestGenerator = new MockFixedDataRequestGenerator(CannedResponse);

            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), completedHandler);
                bool signalled = waitEvent.WaitOne(WaitTimeout);

                Assert.IsTrue(signalled);
            }

            Assert.IsNotNull(resultEventArgs);
            Assert.IsTrue(resultEventArgs.ResultStatus.Success);
        }