/// <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 OauthRepository(testClient);

            return(sut.Post(oauth));
        }
        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 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 OauthRepository(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 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 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 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 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());
        }
Exemple #8
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));
        }
        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 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));
        }
        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 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());
        }
        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());
        }
Exemple #16
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));
        }