|
|
|
|
@@ -19,100 +19,100 @@ namespace Untappd.Net.UnitTests.Request
|
|
|
|
|
[Test]
|
|
|
|
|
public void ConfirmRequestWorks()
|
|
|
|
|
{
|
|
|
|
|
// var mockCreds = new Mock<IUnAuthenticatedUntappdCredentials>();
|
|
|
|
|
// mockCreds.Setup(a => a.AuthenticationData).Returns(new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
|
|
|
|
// {
|
|
|
|
|
// {"client_id", "id"},
|
|
|
|
|
// {"client_secret", "secret"}
|
|
|
|
|
// }));
|
|
|
|
|
// var bodyParam = new Dictionary<string, object> { { "key", "value" } };
|
|
|
|
|
// var client = new Mock<IRestClient>();
|
|
|
|
|
// var request = new Mock<IRestRequest>();
|
|
|
|
|
// request.Setup(a => a.AddParameter(It.IsAny<string>(), It.IsAny<string>()));
|
|
|
|
|
// request.Setup(a => a.AddParameter(It.IsAny<string>(), It.IsAny<string>()));
|
|
|
|
|
var mockCreds = new Mock<IUnAuthenticatedUntappdCredentials>();
|
|
|
|
|
mockCreds.Setup(a => a.AuthenticationData).Returns(new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
|
|
|
|
{
|
|
|
|
|
{"client_id", "id"},
|
|
|
|
|
{"client_secret", "secret"}
|
|
|
|
|
}));
|
|
|
|
|
var bodyParam = new Dictionary<string, object> { { "key", "value" } };
|
|
|
|
|
var client = new Mock<IRestClient>();
|
|
|
|
|
var request = new Mock<IRestRequest>();
|
|
|
|
|
request.Setup(a => a.AddParameter(It.IsAny<string>(), It.IsAny<string>()));
|
|
|
|
|
request.Setup(a => a.AddParameter(It.IsAny<string>(), It.IsAny<string>()));
|
|
|
|
|
|
|
|
|
|
// var response = new Mock<IRestResponse>();
|
|
|
|
|
// response.Setup(a => a.Content).Returns(File.ReadAllText("../../Responses/Json/BeerInfo.json"));
|
|
|
|
|
// client.Setup(a => a.Execute(It.IsAny<IRestRequest>())).Callback(() =>
|
|
|
|
|
// {
|
|
|
|
|
// }).Returns(response.Object);
|
|
|
|
|
// client.Setup(a => a.ExecuteTaskAsync(It.IsAny<IRestRequest>())).Callback(() =>
|
|
|
|
|
// {
|
|
|
|
|
// }).Returns(Task.Run(() => response.Object));
|
|
|
|
|
// #pragma warning disable CS0618 // Type or member is obsolete Using as intended
|
|
|
|
|
// var repository = new Repository(client.Object, request.Object);
|
|
|
|
|
// #pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
|
var response = new Mock<IRestResponse>();
|
|
|
|
|
response.Setup(a => a.Content).Returns(File.ReadAllText("../../Responses/Json/BeerInfo.json"));
|
|
|
|
|
client.Setup(a => a.Execute(It.IsAny<IRestRequest>())).Callback(() =>
|
|
|
|
|
{
|
|
|
|
|
}).Returns(response.Object);
|
|
|
|
|
client.Setup(a => a.ExecuteTaskAsync(It.IsAny<IRestRequest>())).Callback(() =>
|
|
|
|
|
{
|
|
|
|
|
}).Returns(Task.Run(() => response.Object));
|
|
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete Using as intended
|
|
|
|
|
var repository = new Repository(client.Object, request.Object);
|
|
|
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
|
|
|
|
|
|
// repository.Get<BeerInfo>(mockCreds.Object, "awesome", bodyParam);
|
|
|
|
|
// request.Verify(a => a.AddParameter("client_id", mockCreds.Object.AuthenticationData["client_id"]));
|
|
|
|
|
// request.Verify(a => a.AddParameter("client_secret", mockCreds.Object.AuthenticationData["client_secret"]));
|
|
|
|
|
// request.Verify(a => a.AddParameter("key", "value"));
|
|
|
|
|
// repository.GetAsync<BeerInfo>(mockCreds.Object, "awesome", bodyParam).Wait();
|
|
|
|
|
// request.Verify(a => a.AddParameter("client_id", mockCreds.Object.AuthenticationData["client_id"]));
|
|
|
|
|
// request.Verify(a => a.AddParameter("client_secret", mockCreds.Object.AuthenticationData["client_secret"]));
|
|
|
|
|
// request.Verify(a => a.AddParameter("key", "value"));
|
|
|
|
|
repository.Get<BeerInfo>(mockCreds.Object, "awesome", bodyParam);
|
|
|
|
|
request.Verify(a => a.AddParameter("client_id", mockCreds.Object.AuthenticationData["client_id"]));
|
|
|
|
|
request.Verify(a => a.AddParameter("client_secret", mockCreds.Object.AuthenticationData["client_secret"]));
|
|
|
|
|
request.Verify(a => a.AddParameter("key", "value"));
|
|
|
|
|
repository.GetAsync<BeerInfo>(mockCreds.Object, "awesome", bodyParam).Wait();
|
|
|
|
|
request.Verify(a => a.AddParameter("client_id", mockCreds.Object.AuthenticationData["client_id"]));
|
|
|
|
|
request.Verify(a => a.AddParameter("client_secret", mockCreds.Object.AuthenticationData["client_secret"]));
|
|
|
|
|
request.Verify(a => a.AddParameter("key", "value"));
|
|
|
|
|
|
|
|
|
|
// var mockAuthCreds = new Mock<IAuthenticatedUntappdCredentials>();
|
|
|
|
|
// mockAuthCreds.Setup(a => a.AuthenticationData).Returns(new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
|
|
|
|
// {
|
|
|
|
|
// {"access_token", "accessToken"}
|
|
|
|
|
// }));
|
|
|
|
|
var mockAuthCreds = new Mock<IAuthenticatedUntappdCredentials>();
|
|
|
|
|
mockAuthCreds.Setup(a => a.AuthenticationData).Returns(new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
|
|
|
|
{
|
|
|
|
|
{"access_token", "accessToken"}
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// repository.Get<BeerInfo>(mockAuthCreds.Object, "awesome", bodyParam);
|
|
|
|
|
// request.Verify(a => a.AddParameter("key", "value"));
|
|
|
|
|
// request.Verify(a => a.AddParameter("access_token", "accessToken"));
|
|
|
|
|
// repository.GetAsync<BeerInfo>(mockAuthCreds.Object, "awesome", bodyParam).Wait();
|
|
|
|
|
// request.Verify(a => a.AddParameter("key", "value"));
|
|
|
|
|
// request.Verify(a => a.AddParameter("access_token", "accessToken"));
|
|
|
|
|
repository.Get<BeerInfo>(mockAuthCreds.Object, "awesome", bodyParam);
|
|
|
|
|
request.Verify(a => a.AddParameter("key", "value"));
|
|
|
|
|
request.Verify(a => a.AddParameter("access_token", "accessToken"));
|
|
|
|
|
repository.GetAsync<BeerInfo>(mockAuthCreds.Object, "awesome", bodyParam).Wait();
|
|
|
|
|
request.Verify(a => a.AddParameter("key", "value"));
|
|
|
|
|
request.Verify(a => a.AddParameter("access_token", "accessToken"));
|
|
|
|
|
|
|
|
|
|
// mockAuthCreds.Setup(a => a.AuthenticationData).Returns(new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
|
|
|
|
// {
|
|
|
|
|
// {"access_token", "PostaccessToken"}
|
|
|
|
|
// }));
|
|
|
|
|
// var checkin = new CheckIn("-5", "EST", 1044097) { Shout = "Awesome Brew", Rating = 4 };
|
|
|
|
|
// repository.FailFast = true;
|
|
|
|
|
// repository.OnExceptionThrown += (sender, e) =>
|
|
|
|
|
// {
|
|
|
|
|
// Assert.IsNotNull(sender);
|
|
|
|
|
// Assert.IsNotNull(e);
|
|
|
|
|
// };
|
|
|
|
|
// Assert.Throws<HttpErrorException>(() => repository.Post(mockAuthCreds.Object, checkin));
|
|
|
|
|
// repository.FailFast = false;
|
|
|
|
|
// repository.Post(mockAuthCreds.Object, checkin);
|
|
|
|
|
// request.Verify(a => a.AddParameter("access_token", "PostaccessToken"));
|
|
|
|
|
mockAuthCreds.Setup(a => a.AuthenticationData).Returns(new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
|
|
|
|
{
|
|
|
|
|
{"access_token", "PostaccessToken"}
|
|
|
|
|
}));
|
|
|
|
|
var checkin = new CheckIn("-5", "EST", 1044097) { Shout = "Awesome Brew", Rating = 4 };
|
|
|
|
|
repository.FailFast = true;
|
|
|
|
|
repository.OnExceptionThrown += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
Assert.IsNotNull(sender);
|
|
|
|
|
Assert.IsNotNull(e);
|
|
|
|
|
};
|
|
|
|
|
Assert.Throws<HttpErrorException>(() => repository.Post(mockAuthCreds.Object, checkin));
|
|
|
|
|
repository.FailFast = false;
|
|
|
|
|
repository.Post(mockAuthCreds.Object, checkin);
|
|
|
|
|
request.Verify(a => a.AddParameter("access_token", "PostaccessToken"));
|
|
|
|
|
|
|
|
|
|
// mockAuthCreds.Setup(a => a.AuthenticationData).Returns(new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
|
|
|
|
// {
|
|
|
|
|
// {"access_token", "PostAsyncaccessToken"}
|
|
|
|
|
// }));
|
|
|
|
|
// repository.PostAsync(mockAuthCreds.Object, checkin).Wait();
|
|
|
|
|
// request.Verify(a => a.AddParameter("access_token", "PostAsyncaccessToken"));
|
|
|
|
|
mockAuthCreds.Setup(a => a.AuthenticationData).Returns(new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
|
|
|
|
{
|
|
|
|
|
{"access_token", "PostAsyncaccessToken"}
|
|
|
|
|
}));
|
|
|
|
|
repository.PostAsync(mockAuthCreds.Object, checkin).Wait();
|
|
|
|
|
request.Verify(a => a.AddParameter("access_token", "PostAsyncaccessToken"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void ConfirmBasicConstructorWorks()
|
|
|
|
|
{
|
|
|
|
|
// var constructorTest = new Repository();
|
|
|
|
|
// Assert.IsTrue(constructorTest.Client != null);
|
|
|
|
|
// Assert.IsTrue(constructorTest.Request != null);
|
|
|
|
|
var constructorTest = new Repository();
|
|
|
|
|
Assert.IsTrue(constructorTest.Client != null);
|
|
|
|
|
Assert.IsTrue(constructorTest.Request != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TimeoutShouldGetPassedIn()
|
|
|
|
|
{
|
|
|
|
|
// var timeout = 100;
|
|
|
|
|
// var repo = new Repository(timeout: timeout);
|
|
|
|
|
// Assert.AreEqual(repo.Request.Timeout, timeout);
|
|
|
|
|
var timeout = 100;
|
|
|
|
|
var repo = new Repository(timeout: timeout);
|
|
|
|
|
Assert.AreEqual(repo.Request.Timeout, timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void ConfirmConfigureGetRequestClearsParams()
|
|
|
|
|
{
|
|
|
|
|
// var constructorTest = new Repository();
|
|
|
|
|
// constructorTest.Request.Parameters.Add(new Parameter { Name = "param" });
|
|
|
|
|
// Assert.IsTrue(constructorTest.Request.Parameters.Count > 0);
|
|
|
|
|
// constructorTest.ConfigureRequest("endpoint");
|
|
|
|
|
// Assert.IsTrue(constructorTest.Request.Parameters.Count == 0);
|
|
|
|
|
var constructorTest = new Repository();
|
|
|
|
|
constructorTest.Request.Parameters.Add(new Parameter { Name = "param" });
|
|
|
|
|
Assert.IsTrue(constructorTest.Request.Parameters.Count > 0);
|
|
|
|
|
constructorTest.ConfigureRequest("endpoint");
|
|
|
|
|
Assert.IsTrue(constructorTest.Request.Parameters.Count == 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|