Exemplo n.º 1
0
 public void ShouldUnderscorify()
 {
     Assert.AreEqual("ben_the_benly_benis", ShopifyAPIContext.Underscoreify("BenTheBenlyBenis"));
     Assert.AreEqual("ben_the_benly_benis", ShopifyAPIContext.Underscoreify("benTheBenlyBenis"));
     Assert.AreEqual("browser_ip", ShopifyAPIContext.Underscoreify("BrowserIP"));
     Assert.AreEqual("total_price_usd", ShopifyAPIContext.Underscoreify("TotalPriceUSD"));
 }
Exemplo n.º 2
0
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     base.OnActionExecuting(filterContext);
     ShopifyAuthorizationState authState = ShopifyAuthorize.GetAuthorizationState(this.HttpContext);
     if (authState != null)
     {
         _shopify = new ShopifyAPIContext(authState, new JsonDataTranslator());
     }
 }
Exemplo n.º 3
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            ShopifyAuthorizationState authState = ShopifyAuthorize.GetAuthorizationState(this.HttpContext);

            if (authState != null)
            {
                _shopify = new ShopifyAPIContext(authState, new JsonDataTranslator());
            }
        }
Exemplo n.º 4
0
        public void ShouldCreateProductUri()
        {
            var authState = new ShopifyAuthorizationState()
            {
                AccessToken = "beep boop", ShopName = "chucks-chili-dogs"
            };
            var sapi = new ShopifyAPIContext(authState);

            Assert.AreEqual("/admin/products/67", sapi.ProductPath("67"));
        }
Exemplo n.º 5
0
 public void ShouldPluralize()
 {
     Assert.AreEqual("sandwiches", ShopifyAPIContext.Pluralize("sandwich"));
     Assert.AreEqual("kitties", ShopifyAPIContext.Pluralize("kitty"));
     Assert.AreEqual("bricks", ShopifyAPIContext.Pluralize("brick"));
     Assert.AreEqual("addresses", ShopifyAPIContext.Pluralize("address"));
     Assert.AreEqual("addresses", ShopifyAPIContext.Pluralize("ADDRESS"));
     Assert.AreEqual("apples", ShopifyAPIContext.Pluralize("apple"));
     Assert.AreEqual("theses", ShopifyAPIContext.Pluralize("thesis"));
     Assert.AreEqual("bacteria", ShopifyAPIContext.Pluralize("bacterium"));
     Assert.AreEqual("fungi", ShopifyAPIContext.Pluralize("fungus"));
     Assert.AreEqual("viruses", ShopifyAPIContext.Pluralize("virus"));
 }
Exemplo n.º 6
0
        public void BeforeFixture()
        {
            try {
                // because it's so expensive on requests, get our authorization key once for the entire integration test suite

                // this Task will become ready once Shopify redirects our browser back to us with the test shop's consent (in the form of the access token)
                var redirectReplyPromise = ListenForIncomingShopTokenFromRedirect(5409);

                Console.WriteLine("Attempting to authorize against store " + TestStoreName);
                var sa      = new Sharpify.ShopifyAPIAuthorizer(TestStoreName, ConfigurationManager.AppSettings ["Shopify.TestAppKey"], ConfigurationManager.AppSettings ["Shopify.TestAppSecret"]);
                var authUrl = sa.GetAuthorizationURL(new string[] { "write_content", "write_themes", "write_products", "write_customers", "write_script_tags", "write_orders" }, ConfigurationManager.AppSettings ["Shopify.TestHttpServerUri"]);
                Console.WriteLine(authUrl);

                // pop a web browser with the authorization UI:
                Process.Start(authUrl);

                Console.WriteLine("Waiting for Shopify to answer...");
                redirectReplyPromise.Wait();
                var shopCode = redirectReplyPromise.Result;
                Assert.NotNull(shopCode);
                Console.WriteLine("Got code: " + shopCode);

                var authTask = sa.AuthorizeClient(shopCode);
                authTask.Wait();

                // acquire our authorization token for actual API requests
                AuthorizationState = authTask.Result;

                ShopifyClient = new ShopifyAPIContext(AuthorizationState, new JsonDataTranslator());
            } catch (Exception e) {
                using (var fd = new StreamWriter("sharpify_test_before_fixture_error.txt")) {
                    fd.Write(e.ToString());
                }
                throw new Exception("Rethrowing exception emitted during BeforeFixture()", e);
            }
        }
        public void BeforeFixture()
        {
            try {
                // because it's so expensive on requests, get our authorization key once for the entire integration test suite

                // this Task will become ready once Shopify redirects our browser back to us with the test shop's consent (in the form of the access token)
                var redirectReplyPromise = ListenForIncomingShopTokenFromRedirect (5409);

                Console.WriteLine ("Attempting to authorize against store " + TestStoreName);
                var sa = new Sharpify.ShopifyAPIAuthorizer (TestStoreName, ConfigurationManager.AppSettings ["Shopify.TestAppKey"], ConfigurationManager.AppSettings ["Shopify.TestAppSecret"]);
                var authUrl = sa.GetAuthorizationURL (new string[] { "write_content", "write_themes", "write_products", "write_customers", "write_script_tags", "write_orders" }, ConfigurationManager.AppSettings ["Shopify.TestHttpServerUri"]);
                Console.WriteLine (authUrl);

                // pop a web browser with the authorization UI:
                Process.Start (authUrl);

                Console.WriteLine ("Waiting for Shopify to answer...");
                redirectReplyPromise.Wait ();
                var shopCode = redirectReplyPromise.Result;
                Assert.NotNull (shopCode);
                Console.WriteLine ("Got code: " + shopCode);

                var authTask = sa.AuthorizeClient (shopCode);
                authTask.Wait ();

                // acquire our authorization token for actual API requests
                AuthorizationState = authTask.Result;

                ShopifyClient = new ShopifyAPIContext (AuthorizationState, new JsonDataTranslator ());
            } catch (Exception e) {
                using (var fd = new StreamWriter("sharpify_test_before_fixture_error.txt")) {
                    fd.Write (e.ToString ());
                }
                throw new Exception ("Rethrowing exception emitted during BeforeFixture()", e);
            }
        }
Exemplo n.º 8
0
 public void ShouldCreateProductUri()
 {
     var authState = new ShopifyAuthorizationState() {AccessToken = "beep boop", ShopName = "chucks-chili-dogs"};
     var sapi = new ShopifyAPIContext(authState);
     Assert.AreEqual("/admin/products/67", sapi.ProductPath("67"));
 }