public Me Get() { const string tictailJsonReponse = "{" + "\"description\": \"Sells something<br>\"," + "}"; var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_abcdefhiljklmnopqrstuvxuz"); var clientTest = new TictailClientTest(endpointDummy); clientTest.Content = tictailJsonReponse; var repository = new TictailRepository(clientTest); return repository.Me.Get(); }
public void GetStoreNotFound_Theme() { const string tictailJsonReponse = "{" + "\"status\": 404," + "\"message\": \"Not Found. You have requested this URI [/v1/stores/aaa/theme] but did you mean /v1/stores/<id:store_id>/theme or /v1/stores/<id:store_id>/orders or /v1/stores/<id:store_id>/customers ?\", " + "\"params\": {}, " + "\"support_email\": \"[email protected]\"" + "}"; var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_abcdefhiljklmnopqrstuvxuz"); var clientTest = new TictailClientTest(endpointDummy); clientTest.Content = tictailJsonReponse; clientTest.StatusCode = HttpStatusCode.NotFound; var repository = new TictailRepository(clientTest); var ex = Assert.Throws<TictailException>(delegate { repository.Stores.Get("someWrongId"); }); Assert.Equal("Not Found. You have requested this URI [/v1/stores/aaa/theme] but did you mean /v1/stores/<id:store_id>/theme or /v1/stores/<id:store_id>/orders or /v1/stores/<id:store_id>/customers ?", ex.Message); }
public Theme Get() { const string tictailStoreJsonReponse = "{" + "\"id\": \"myStore\"," + "}"; const string tictailThemeJsonReponse = "{" + "\"id\": \"myTheme\"," + "}"; var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_abcdefhiljklmnopqrstuvxuz"); var clientTest = new TictailClientTest(endpointDummy); clientTest.Content = tictailStoreJsonReponse; var repository = new TictailRepository(clientTest); var store = repository.Stores["somestore"]; clientTest.Content = tictailThemeJsonReponse; return store.Theme.Get(); }
public void WrongAccessToken() { const string tictailJsonReponse = "{" + "\"status\": 403, " + "\"message\": \"Forbidden\", " + "\"params\": {}, " + "\"support_email\": \"[email protected]\"" + "}"; var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_a"); var clientTest = new TictailClientTest(endpointDummy); IRestRequest request = new RestRequest("v1/me", Method.GET); clientTest.Content = tictailJsonReponse; clientTest.StatusCode = HttpStatusCode.Forbidden; var tictailException = Assert.Throws<TictailException>(delegate { clientTest.ExecuteRequest(request, HttpStatusCode.OK); }); Assert.Equal("Forbidden access, check the API key", tictailException.CustomMessage); Assert.Equal("Forbidden", tictailException.Message); Assert.Equal(403, tictailException.Status); Assert.Equal("*****@*****.**", tictailException.SupportEmail); }
public void WrongAccessCode() { const string tictailJsonReponse = "{" + "\"status\": 400, " + "\"message\": \"Invalid authorization code given\"," + "\"params\": {}, " + "\"support_email\": \"[email protected]\"" + "}"; var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com")); var clientTest = new TictailClientTest(endpointDummy); IRestRequest request = new RestRequest("oauth/token", Method.POST); clientTest.Content = tictailJsonReponse; clientTest.StatusCode = HttpStatusCode.BadRequest; var tictailException = Assert.Throws<TictailException>(delegate { clientTest.ExecuteRequest(request, HttpStatusCode.OK); }); Assert.Equal("No access, check your authcode, has it allready been used?", tictailException.CustomMessage); Assert.Equal("Invalid authorization code given", tictailException.Message); Assert.Equal(400, tictailException.Status); Assert.Equal("*****@*****.**", tictailException.SupportEmail); }
public void RessouceNotFound() { const string tictailJsonReponse = "{" + "\"status\": 404, " + "\"message\": \"Not Found. You have requested this URI [/v1/stores/AAA] but did you mean /v1/stores/<id:store_id> or /v1/stores or /v1/stores/<id:store_id>/theme ?\"," + "\"params\": {}, " + "\"support_email\": \"[email protected]\"" + "}"; var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com")); var clientTest = new TictailClientTest(endpointDummy); IRestRequest request = new RestRequest("v1/stores/AAA", Method.GET); clientTest.Content = tictailJsonReponse; clientTest.StatusCode = HttpStatusCode.NotFound; var tictailException = Assert.Throws<TictailException>(delegate { clientTest.ExecuteRequest(request, HttpStatusCode.OK); }); Assert.Equal("Does the ressouce exist?", tictailException.CustomMessage); Assert.Equal("Not Found. You have requested this URI [/v1/stores/AAA] but did you mean /v1/stores/<id:store_id> or /v1/stores or /v1/stores/<id:store_id>/theme ?", tictailException.Message); Assert.Equal(404, tictailException.Status); Assert.Equal("*****@*****.**", tictailException.SupportEmail); }
public void WrongUrl() { var endpointDummy = new TictailEndpoint(new Uri("https://wrongdomain.com"), "accesstoken_a"); var clientTest = new TictailClientTest(endpointDummy); clientTest.ResponseStatus = ResponseStatus.Error; clientTest.StatusCode = HttpStatusCode.Unauthorized; IRestRequest request = new RestRequest("v1/me", Method.GET); var ex = Assert.Throws<Exception>(delegate { clientTest.ExecuteRequest(request, HttpStatusCode.OK); }); Assert.Equal("Unknown status, ResponseStatus: Error", ex.Message); }
/// <summary> /// All is OK : used by Post_ValidAuthCode_AccessToken /// </summary> /// <param name="oauth">The oauth data going in</param> /// <returns>A token</returns> public Token Post(Oauth oauth) { const string tictailJsonReponse = "{" + "\"access_token\": \"accesstoken_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"," + "\"token_type\": \"Bearer\"," + "\"expires_in\": 3155760000," + "\"store\": {" + "\"id\": \"ab1\"," + "\"name\": \"Some example store\"," + "\"language\": \"en\"," + "\"url\": \"http://example.tictail.com\"," + "\"storekeeper_email\": \"[email protected]\"," + "\"created_at\": \"1999-02-12T20:10:20\"," + "\"modified_at\": null" + "}" + "}"; var testClient = new TictailClientTest { Content = tictailJsonReponse, ResponseStatus = ResponseStatus.Completed, StatusCode = HttpStatusCode.OK }; var sut = new OauthResource(testClient); return sut.Post(oauth); }
public void Post_UnvalidAuthCode_TictailException() { var oauth = new Oauth { AuthCode = "authcode_BAD", ClientId = "clientid_ABCDEFGHIJKLM9876543", ClientSecret = "clientsecret_123456789abcdefghij" }; const string tictailJsonReponse = "{" + "\"status\": 400, " + "\"message\": \"Invalid authorization code given\"," + "\"params\": {}, " + "\"support_email\": \"[email protected]\"" + "}"; var testClient = new TictailClientTest { Content = tictailJsonReponse, ResponseStatus = ResponseStatus.Completed, StatusCode = HttpStatusCode.BadRequest }; var sut = new OauthResource(testClient); var tictailException = Assert.Throws<TictailException>(() => sut.Post(oauth)); Assert.Equal(400, tictailException.Status); Assert.Equal("Invalid authorization code given", tictailException.Message); Assert.Equal("*****@*****.**", tictailException.SupportEmail); }
public Store Patch(string resourceId, PatchStore resource) { const string tictailJsonReponse = "{" + "\"description\": \"A new description\"," + "}"; var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_abcdefhiljklmnopqrstuvxuz"); var clientTest = new TictailClientTest(endpointDummy); clientTest.Content = tictailJsonReponse; var repository = new TictailRepository(clientTest); return repository.Stores.Patch(resourceId, resource); }