Skip to content

Commit

Permalink
fixed the forever hang problem on GetBusiness call as the TCS wasn't …
Browse files Browse the repository at this point in the history
…set on error cases.
  • Loading branch information
tugberkugurlu committed Jan 1, 2014
1 parent ee5c0ee commit fe705d4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ TestResults/*
packages/
_ReSharper.YelpSharp/
Samples/packages
*.user
23 changes: 19 additions & 4 deletions YelpSharp/Yelp.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using System.Net;
using RestSharp;
using RestSharp.Authenticators;
using YelpSharp.Data;
Expand Down Expand Up @@ -127,9 +128,23 @@ protected Task<T> makeRequest<T>(string area, string id, Dictionary<string, stri

var tcs = new TaskCompletionSource<T>();
var handle = client.ExecuteAsync(request, response =>
{
var results = JsonConvert.DeserializeObject<T>(response.Content);
tcs.SetResult(results);
{
if(response.StatusCode == HttpStatusCode.NotFound)
{
tcs.SetResult(default(T));
}
else
{
try
{
T results = JsonConvert.DeserializeObject<T>(response.Content);
tcs.SetResult(results);
}
catch (Exception ex)
{
tcs.SetException(ex);
}
}
});

return tcs.Task;
Expand Down
18 changes: 14 additions & 4 deletions YelpSharpTests/ErrorTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Configuration;
using System.Configuration;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using YelpSharp;
using YelpSharp;
using YelpSharp.Data;
using YelpSharp.Data.Options;

namespace YelpSharpTests
Expand Down Expand Up @@ -121,7 +123,15 @@ public void ErrorTest_UNSPECIFIED_LOCATION()
Assert.IsTrue(results.error != null);
Assert.IsTrue(results.error.id == YelpSharp.Data.ErrorId.UNSPECIFIED_LOCATION);
Console.WriteLine(results);
}

}

[TestMethod]
public void ErrorTest_UNAVAILABLE_BUSINESS()
{
Yelp y = new Yelp(Config.Options);
Business business = y.GetBusiness("foo-bar").Result;

Assert.IsNull(business);
}
}
}
1 change: 0 additions & 1 deletion YelpSharpTests/LocationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,5 @@ public void ErrorTest_UNSPECIFIED_LOCATION()
Assert.IsTrue(results.error.id == YelpSharp.Data.ErrorId.UNSPECIFIED_LOCATION);
Console.WriteLine(results);
}

}
}

0 comments on commit fe705d4

Please sign in to comment.