public void GetListingDetailApiKeyInvalidTest() { // ARRANGE using (AutoResetEvent waitEvent = new AutoResetEvent(false)) { ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext("InvalidKey")); listingsService.GetListingDetailsCompleted += (s, e) => { result = e; waitEvent.Set(); }; // ACT listingsService.GetListingDetails(this.testListingId, DetailLevel.Low); bool signalled = waitEvent.WaitOne(NetsyData.WaitTimeout); // ASSERT // check that the event was fired, did not time out Assert.IsTrue(signalled, "Not signalled"); // check the data Assert.IsNotNull(result); // check the data - should fail Assert.IsNotNull(result); Assert.IsNotNull(result.ResultStatus); Assert.IsFalse(result.ResultStatus.Success); Assert.AreEqual(WebExceptionStatus.ProtocolError, result.ResultStatus.WebStatus); } }
public void GetListingsByTagsApiKeyInvalidTest() { // ARRANGE using (AutoResetEvent waitEvent = new AutoResetEvent(false)) { ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext("InvalidKey")); listingsService.GetListingsByTagsCompleted += (s, e) => { result = e; waitEvent.Set(); }; List<string> tags = new List<string> { "bag" }; // ACT listingsService.GetListingsByTags(tags, SortField.Created, SortOrder.Up, 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"); // check the data Assert.IsNotNull(result); // check the data - should fail Assert.IsNotNull(result); Assert.IsNotNull(result.ResultStatus); Assert.IsFalse(result.ResultStatus.Success); Assert.AreEqual(WebExceptionStatus.ProtocolError, result.ResultStatus.WebStatus); } }
public void GetListingsByColorAndKeywordsApiKeyInvalidTest() { // ARRANGE using (AutoResetEvent waitEvent = new AutoResetEvent(false)) { ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext("InvalidKey")); listingsService.GetListingsByColorAndKeywordsCompleted += (s, e) => { result = e; waitEvent.Set(); }; RgbColor testColor = new RgbColor("76B3DF"); // ACT listingsService.GetListingsByColorAndKeywords(TestKeywords(), testColor, DefaultWiggle, 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"); // check the data Assert.IsNotNull(result); // check the data - should fail Assert.IsNotNull(result); Assert.IsNotNull(result.ResultStatus); Assert.IsFalse(result.ResultStatus.Success); Assert.AreEqual(WebExceptionStatus.ProtocolError, result.ResultStatus.WebStatus); } }
/// <summary> /// Get a valid listing id for use in tests. /// Any one will do so get one off the front features listing /// </summary> /// <returns>a valid listing id</returns> public static int RetrieveTestListingId() { if (cachedListingId > 0) { return cachedListingId; } int result = 0; using (AutoResetEvent waitEvent = new AutoResetEvent(false)) { IListingsService listingsService = new ListingsService(new EtsyContext(NetsyData.EtsyApiKey)); listingsService.GetFrontFeaturedListingsCompleted += (s, e) => { result = e.ResultValue.Results[0].ListingId; waitEvent.Set(); }; listingsService.GetFrontFeaturedListings(0, 1, DetailLevel.Low); waitEvent.WaitOne(Constants.WaitTimeout); } cachedListingId = result; return result; }
public void GetFrontFeaturedListingsCallTest() { // ARRANGE using (AutoResetEvent waitEvent = new AutoResetEvent(false)) { ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(NetsyData.EtsyApiKey)); listingsService.GetFrontFeaturedListingsCompleted += (s, e) => { result = e; waitEvent.Set(); }; // ACT listingsService.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"); // check the data Assert.IsNotNull(result); TestHelpers.CheckResultSuccess(result); Assert.IsTrue(result.ResultValue.Count > 1); Assert.AreEqual(10, result.ResultValue.Results.Length); Assert.IsNotNull(result.ResultValue.Params); } }
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 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 GetListingsByCategoryApiKeyMissingTest() { // ARRANGE ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(string.Empty)); listingsService.GetListingsByCategoryCompleted += (s, e) => result = e; // ACT listingsService.GetListingsByCategory(NetsyData.TestCategory, SortField.Created, SortOrder.Down, 0, 10, DetailLevel.Low); // check the data TestHelpers.CheckResultFailure(result); }
public void GetFrontFeaturedListingsApiKeyMissingTest() { // ARRANGE ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(string.Empty)); listingsService.GetFrontFeaturedListingsCompleted += (s, e) => result = e; // ACT listingsService.GetFrontFeaturedListings(0, 10, DetailLevel.Low); // check the data TestHelpers.CheckResultFailure(result); }
public void GetListingsByColorApiKeyMissingTest() { // ARRANGE ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(string.Empty)); listingsService.GetListingsByColorCompleted += (s, e) => result = e; RgbColor testColor = new RgbColor("76B3DF"); // ACT listingsService.GetListingsByColor(testColor, 10, 0, 10, DetailLevel.Low); // check the data TestHelpers.CheckResultFailure(result); }
public void GetListingsByTagsApiKeyMissingTest() { // ARRANGE ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(string.Empty)); listingsService.GetListingsByTagsCompleted += (s, e) => result = e; List<string> tags = new List<string>(); // ACT listingsService.GetListingsByTags(tags, SortField.Created, SortOrder.Up, 0, 10, DetailLevel.Low); // check the data TestHelpers.CheckResultFailure(result); }
/// <summary> /// Test retrieving listing details at the given detail level /// </summary> /// <param name="detailLevel">the given detail level</param> private static void TestGetListings(DetailLevel detailLevel) { TestHelpers.WaitABit(); // ARRANGE using (AutoResetEvent waitEvent = new AutoResetEvent(false)) { ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(NetsyData.EtsyApiKey)); listingsService.GetListingsByColorAndKeywordsCompleted += (s, e) => { result = e; waitEvent.Set(); }; RgbColor testColor = new RgbColor("76B3DF"); // ACT listingsService.GetListingsByColorAndKeywords(TestKeywords(), testColor, DefaultWiggle, 0, 10, detailLevel); bool signalled = waitEvent.WaitOne(NetsyData.WaitTimeout); // ASSERT // check that the event was fired, did not time out Assert.IsTrue(signalled, "Not signalled"); // check the data Assert.IsNotNull(result); TestHelpers.CheckResultSuccess(result); Assert.IsTrue(result.ResultValue.Count > 0, "No listings found"); Assert.IsNotNull(result.ResultValue.Params); } }
public void GetListingsByKeywordInvalidPriceRangeTest() { // ARRANGE ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(NetsyData.EtsyApiKey)); listingsService.GetListingsByKeywordCompleted += (s, e) => result = e; List<string> searchTerms = new List<string>(); // ACT listingsService.GetListingsByKeyword(searchTerms, SortField.Created, SortOrder.Up, 100, 10, false, 0, 10, DetailLevel.Low); // check the data TestHelpers.CheckResultFailure(result); }
/// <summary> /// Test retrieving listing details at the given detail level /// </summary> /// <param name="detailLevel">the given detail level</param> private void TestGetListingDetails(DetailLevel detailLevel) { // ARRANGE using (AutoResetEvent waitEvent = new AutoResetEvent(false)) { ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(NetsyData.EtsyApiKey)); listingsService.GetListingDetailsCompleted += (s, e) => { result = e; waitEvent.Set(); }; // ACT listingsService.GetListingDetails(this.testListingId, detailLevel); bool signalled = waitEvent.WaitOne(NetsyData.WaitTimeout); // ASSERT // check that the event was fired, did not time out Assert.IsTrue(signalled, "Not signalled"); // check the data Assert.IsNotNull(result); TestHelpers.CheckResultSuccess(result); Assert.AreEqual(1, result.ResultValue.Count); Assert.AreEqual(1, result.ResultValue.Results.Length); Assert.IsNotNull(result.ResultValue.Params); } }
public void GetListingsByKeywordSortOnScoreTest() { // ARRANGE using (AutoResetEvent waitEvent = new AutoResetEvent(false)) { ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(NetsyData.EtsyApiKey)); listingsService.GetListingsByKeywordCompleted += (s, e) => { result = e; waitEvent.Set(); }; List<string> searchTerms = new List<string> { "bags" }; // ACT listingsService.GetListingsByKeyword(searchTerms, SortField.Score, SortOrder.Up, null, null, false, 0, 10, DetailLevel.Low); bool signalled = waitEvent.WaitOne(NetsyData.WaitTimeout); // ASSERT // check that the event was fired, did not time out Assert.IsTrue(signalled, "Not signalled"); // check the data Assert.IsNotNull(result); TestHelpers.CheckResultSuccess(result); Assert.IsTrue(result.ResultValue.Count > 1); Assert.AreEqual(10, result.ResultValue.Results.Length); Assert.IsNotNull(result.ResultValue.Params); } }
/// <summary> /// Test getting listings by tags at the appropriate detail level /// </summary> /// <param name="detailLevel">he detail level</param> private static void TestGetListingsByTags(DetailLevel detailLevel) { TestHelpers.WaitABit(); // ARRANGE using (AutoResetEvent waitEvent = new AutoResetEvent(false)) { ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(NetsyData.EtsyApiKey)); listingsService.GetListingsByTagsCompleted += (s, e) => { result = e; waitEvent.Set(); }; List<string> tags = new List<string> { "bag" }; // ACT listingsService.GetListingsByTags(tags, SortField.Created, SortOrder.Up, 0, 10, detailLevel); 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 Assert.IsNotNull(result); TestHelpers.CheckResultSuccess(result); Assert.IsTrue(result.ResultValue.Count > 1); Assert.AreEqual(10, result.ResultValue.Results.Length); Assert.IsNotNull(result.ResultValue.Params); } }
public void GetListingsByCategoryEmptyCategoryTest() { // ARRANGE using (AutoResetEvent waitEvent = new AutoResetEvent(false)) { ResultEventArgs<Listings> result = null; IListingsService listingsService = new ListingsService(new EtsyContext(NetsyData.EtsyApiKey)); listingsService.GetListingsByCategoryCompleted += (s, e) => { result = e; waitEvent.Set(); }; // ACT listingsService.GetListingsByCategory(NetsyData.TestBadCategory, SortField.Price, SortOrder.Up, 0, 10, DetailLevel.Low); bool signalled = waitEvent.WaitOne(NetsyData.WaitTimeout); // ASSERT // check that the event was fired, did not time out Assert.IsTrue(signalled, "Not signalled"); // check the data Assert.IsNotNull(result); TestHelpers.CheckResultSuccess(result); Assert.AreEqual(0, result.ResultValue.Count, "Results found"); Assert.AreEqual(0, result.ResultValue.Results.Length); Assert.IsNotNull(result.ResultValue.Params); } }