Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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());
        }
Exemplo n.º 6
0
        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));
        }
        public bool Delete(Follower value)
        {
            var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_abcdefhiljklmnopqrstuvxuz");
            var clientTest    = new TictailClientTest(endpointDummy);

            // Prepare store content
            clientTest.Content = "{" +
                                 "\"id\": \"myStore\"," +
                                 "}";

            var repository = new TictailRepository(clientTest);
            var store      = repository.Stores["somestore"];

            clientTest.StatusCode = HttpStatusCode.NoContent;

            return(store.Followers.Delete(value));
        }
        public Order Get(string idOrHref)
        {
            var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_abcdefhiljklmnopqrstuvxuz");
            var clientTest    = new TictailClientTest(endpointDummy);

            // Prepare store content
            clientTest.Content = "{" +
                                 "\"id\": \"myStore\"," +
                                 "}";

            var repository = new TictailRepository(clientTest);
            var store      = repository.Stores["somestore"];

            // Prepare product content
            clientTest.Content = "{" +
                                 "\"id\": \"" + idOrHref + "\"" +
                                 "}";
            return(store.Orders.Get(idOrHref));
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        public string Post(Follower value)
        {
            var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_abcdefhiljklmnopqrstuvxuz");
            var clientTest    = new TictailClientTest(endpointDummy);

            // Prepare store content
            clientTest.Content = "{" +
                                 "\"id\": \"myStore\"," +
                                 "}";

            var repository = new TictailRepository(clientTest);
            var store      = repository.Stores["somestore"];

            clientTest.StatusCode      = HttpStatusCode.Created;
            clientTest.Content         = string.Empty;
            clientTest.ResponseHeaders = new Dictionary <string, string>();
            clientTest.ResponseHeaders.Add("Location", "http://some.tictail/url/" + value.Email.Replace("@", "").Replace(".", ""));

            return(store.Followers.Post(value));
        }
Exemplo n.º 11
0
        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());
        }
Exemplo n.º 12
0
        public IEnumerator <Follower> GetRange()
        {
            var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_abcdefhiljklmnopqrstuvxuz");
            var clientTest    = new TictailClientTest(endpointDummy);

            // Prepare store content
            clientTest.Content = "{" +
                                 "\"id\": \"myStore\"," +
                                 "}";

            var repository = new TictailRepository(clientTest);
            var store      = repository.Stores["somestore"];

            // Prepare followers content
            clientTest.Content = "[{" +
                                 "\"id\": \"prod1\"" +
                                 "},{" +
                                 "\"id\": \"prod2\"" +
                                 "}]";
            return(store.Followers.GetRange());
        }
Exemplo n.º 13
0
        public IEnumerator <Category> Get()
        {
            var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_abcdefhiljklmnopqrstuvxuz");
            var clientTest    = new TictailClientTest(endpointDummy);

            // Prepare store content
            clientTest.Content = "{" +
                                 "\"id\": \"myStore\"," +
                                 "}";

            var repository = new TictailRepository(clientTest);
            var store      = repository.Stores["somestore"];

            // Prepare category content
            clientTest.Content = "[" +
                                 "{" +
                                 "\"id\": \"1234\"" +
                                 "}" +
                                 "]";
            return(store.Categories.GetRange());
        }
Exemplo n.º 14
0
        public Product Post(PostProduct resource)
        {
            const string tictailJsonReponse = "{" +
                                              "\"status\": \"published\", " +
                                              "\"store_url\": \"http://somedomain.tictail.com\", " +
                                              "\"description\": \"A new product\", " +
                                              "\"store_name\": \"Somestore\", " +
                                              "\"store_id\": \"acb\"," +
                                              "\"unlimited\": true, " +
                                              "\"created_at\": \"2013-07-08T20:01:02.123456\", " +
                                              "\"title\": \"My new product\", " +
                                              "\"modified_at\": \"2014-08-08T10:19:14.876543\", " +
                                              "\"slug\": \"prod1\", " +
                                              "\"price\": 132456, " +
                                              "\"currency\": \"SEK\", " +
                                              "\"store_subdomain\": 	\"somedomain\", "+
                                              "\"likes\": 0, " +
                                              "\"id\": \"1324a\"," +
                                              "\"variations\": [{\"title\": \"Variation 1\", \"modified_at\": \"2015-01-02T12:13:14.01345\", \"created_at\": \"2015-01-01T14:16:17.123456\", \"unlimited\": false, \"id\": \"CDEF\", \"quantity\": 12}]" +
                                              "}";
            //"images": [],
            //"categories": [],

            var endpointDummy = new TictailEndpoint(new Uri("https://api.somewhere.com"), "accesstoken_abcdefhiljklmnopqrstuvxuz");
            var clientTest    = new TictailClientTest(endpointDummy);

            // Prepare store content
            clientTest.Content = "{" +
                                 "\"id\": \"acb\"," +
                                 "}";
            var repository = new TictailRepository(clientTest);
            var store      = repository.Stores["acb"];

            // Prepare product content
            clientTest.Content    = tictailJsonReponse;
            clientTest.StatusCode = HttpStatusCode.Created;
            return(store.Products.Post(resource));
        }
Exemplo n.º 15
0
 public TictailClientTest(TictailEndpoint endpoint)
     : base(endpoint)
 {
     StatusCode     = HttpStatusCode.OK;
     ResponseStatus = ResponseStatus.Completed;
 }