Esempio n. 1
0
        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();
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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 TictailClientTest(TictailEndpoint endpoint)
     : base(endpoint)
 {
     StatusCode = HttpStatusCode.OK;
     ResponseStatus = ResponseStatus.Completed;
 }
Esempio n. 8
0
        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);
        }
        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);
        }
Esempio n. 10
0
 /// <summary>
 /// Construct the repository with an endpoint
 /// </summary>
 /// <param name="endpoint">A Tictail endpoint</param>
 public TictailRepository(TictailEndpoint endpoint)
     : this(new TictailClient(endpoint))
 {
 }
Esempio n. 11
0
 /// <summary>
 /// Contructor
 /// </summary>
 /// <param name="endpoint">Endpoint of the api</param>
 public TictailClient(TictailEndpoint endpoint)
 {
     _endpoint = endpoint;
 }
Esempio n. 12
0
 /// <summary>
 /// Construct the repository with an endpoint
 /// </summary>
 /// <param name="endpoint">A Tictail endpoint</param>
 public TictailRepository(TictailEndpoint endpoint)
     : this(new TictailClient(endpoint))
 {
 }
Esempio n. 13
0
 /// <summary>
 /// Contructor
 /// </summary>
 /// <param name="endpoint">Endpoint of the api</param>
 public TictailClient(TictailEndpoint endpoint)
 {
     _endpoint = endpoint;
 }