Exemplo n.º 1
0
        private JObject TestGetAttributeSetInstance(string attrSetInstId)
        {
            var endpointUrl = ProxyTemplate.GetEndpointUrl();
            var client      = new HttpClient {
                BaseAddress = new Uri(endpointUrl)
            };
            string idStr = attrSetInstId;

            var url = "AttributeSetInstances/{id}";

            url = url.Replace("{id}", idStr);

            var req = new HttpRequestMessage(HttpMethod.Get, url);

            SetAuthenticationHeader(req);
            var response = client.SendAsync(req).GetAwaiter().GetResult();

            var respContent = response.Content.ReadAsAsync <JObject>().GetAwaiter().GetResult();

            Console.WriteLine(respContent);
            Console.WriteLine(response.Headers);
            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.ReasonPhrase);

            return(respContent);
        }
Exemplo n.º 2
0
        private void TestMergePatchAttributeSetInstance(string attrSetInstId)
        {
            var endpointUrl = ProxyTemplate.GetEndpointUrl();
            var client      = new HttpClient {
                BaseAddress = new Uri(endpointUrl)
            };
            //var attrSetInstId = Guid.NewGuid().ToString();

            var url = "AttributeSetInstances/{id}";

            url = url.Replace("{id}", attrSetInstId);

            var attrSetInst = new MergePatchAttributeSetInstanceDto();

            attrSetInst.AttributeSetId = _testColorAttributeSetId;//IdGenerator._lastAttributeSetId;
            attrSetInst.SerialNumber   = attrSetInstId;
            attrSetInst.Lot            = DateTime.Today.ToString();
            attrSetInst.Version        = 1;

            dynamic jObject = JObject.FromObject(attrSetInst);

            jObject.IsPropertyColorRemoved = true;

            var req = new HttpRequestMessage(new HttpMethod("PATCH"), url);

            SetAuthenticationHeader(req);
            req.Content = new ObjectContent(typeof(JObject), jObject, new JsonMediaTypeFormatter());
            var response = client.SendAsync(req).GetAwaiter().GetResult();

            Console.WriteLine(response.Content);
            Console.WriteLine(response.Headers);
            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.ReasonPhrase);
        }
Exemplo n.º 3
0
        private void TestGetValue1()
        {
            //var accessToken = GetJwtAccessToken("jyang", "jyang");
            //Console.WriteLine(accessToken);

            string endpointUrl = ProxyTemplate.GetEndpointUrl();

            var client = new HttpClient {
                BaseAddress = new Uri(endpointUrl)
            };
            string valId = "1";
            var    url   = "Values/{id}";

            url = url.Replace("{id}", valId);

            var req = new HttpRequestMessage(HttpMethod.Get, url);

            SetAuthenticationHeader(req);
            //req.Content = new ObjectContent(typeof(JObject), jObject, new JsonMediaTypeFormatter());
            var response = client.SendAsync(req).GetAwaiter().GetResult();

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            Console.WriteLine(response.Content);
            Console.WriteLine(response.Headers);
            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.ReasonPhrase);
        }
Exemplo n.º 4
0
        public void TestPostCreateAndPutPatchInOut()
        {
            var documentNumber = Guid.NewGuid().ToString();
            //var inOutApplicationService = _inOutApplicationServiceFactory.InOutApplicationService;

            var createInOut = new CreateOrMergePatchOrDeleteInOutDto();

            createInOut.DocumentNumber = documentNumber;
            createInOut.CommandId      = Guid.NewGuid().ToString();

            var endpointUrl = ProxyTemplate.GetEndpointUrl();
            var client      = new HttpClient {
                BaseAddress = new Uri(endpointUrl)
            };
            //var attrSetInstId = Guid.NewGuid().ToString();

            var postUrl = "InOuts";

            var postReq = new HttpRequestMessage(HttpMethod.Post, postUrl);

            SetAuthenticationHeader(postReq);
            postReq.Content = new ObjectContent <CreateOrMergePatchOrDeleteInOutDto>(createInOut, new JsonMediaTypeFormatter());
            var postRsp = client.SendAsync(postReq).GetAwaiter().GetResult();

            Console.WriteLine(postRsp.Content);
            Console.WriteLine(postRsp.Headers);
            Console.WriteLine(postRsp.StatusCode);
            Console.WriteLine(postRsp.ReasonPhrase);

            var inOutId = createInOut.DocumentNumber;
            var url     = "InOuts/{id}";

            url = url.Replace("{id}", inOutId);
            var updateInOut = new CreateOrMergePatchOrDeleteInOutDto();

            updateInOut.Version    = 1;
            updateInOut.InOutLines = new CreateOrMergePatchOrRemoveInOutLineDto[] {
                new CreateOrMergePatchOrRemoveInOutLineDto()
                {
                    LineNumber             = "1",
                    ProductId              = Guid.NewGuid().ToString(),
                    LocatorId              = "1-Test-1-1",
                    MovementQuantity       = 1,
                    AttributeSetInstanceId = "EMPTY"
                }
            };

            var req = new HttpRequestMessage(HttpMethod.Put, url);

            SetAuthenticationHeader(req);
            req.Content = new ObjectContent <CreateOrMergePatchOrDeleteInOutDto>(updateInOut, new JsonMediaTypeFormatter());
            var response = client.SendAsync(req).GetAwaiter().GetResult();

            Console.WriteLine(response.Content);
            Console.WriteLine(response.Headers);
            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.ReasonPhrase);
        }
Exemplo n.º 5
0
 public override object this[string name]
 {
     get
     {
         if (name.Equals("HttpClientProxyTemplate", StringComparison.InvariantCultureIgnoreCase))
         {
             var proxyTemplate = new ProxyTemplate(() => _endpointUrl);
             proxyTemplate.GetAuthenticationHeaderValue = () => (new Tuple <string, string>("Bearer", OAuthBearerToken));
             return(proxyTemplate);
         }
         throw new NotImplementedException();
     }
 }
Exemplo n.º 6
0
        private string CreateShipment_1(CreateProductDto prd_1)
        {
            var shipmentId = DateTime.Now.Ticks.ToString();
            var shipImport = new ShipmentCommandDtos.ImportRequestContent();

            shipImport.ShipmentId = shipmentId;

            var prdId = prd_1.ProductId;

            var rollId_1   = "H71051402A";
            var shipItem_1 = NewImportingShipmentItem(prdId, rollId_1);

            var rollId_2   = "H00000000A";
            var shipItem_2 = NewImportingShipmentItem(prdId, rollId_2);

            shipImport.ShipmentItems = new ImportingShipmentItem[] {
                shipItem_1,
                shipItem_2,
            };

            shipImport.ShipmentTypeId        = ShipmentTypeIds.IncomingShipment;
            shipImport.DestinationFacilityId = "TEST_1";

            // ////////////////////////////////
            //_shipmentApplicationServiceFactory.ShipmentApplicationService.When(shipImport.ToImport());

            var endpointUrl = ProxyTemplate.GetEndpointUrl();
            var client      = new HttpClient {
                BaseAddress = new Uri(endpointUrl)
            };
            //var attrSetInstId = Guid.NewGuid().ToString();

            var url = "Shipments/{id}/_commands/Import";

            url = url.Replace("{id}", shipmentId);

            var req = new  HttpRequestMessage(HttpMethod.Put, url);

            SetAuthenticationHeader(req);
            req.Content = new ObjectContent <ShipmentCommandDtos.ImportRequestContent>(shipImport, new JsonMediaTypeFormatter());
            var response = client.SendAsync(req).GetAwaiter().GetResult();

            Console.WriteLine(response.Content);
            Console.WriteLine(response.Headers);
            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.ReasonPhrase);

            // ////////////////////////////////

            return(shipmentId);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Generates the proxy script.
        /// </summary>
        /// <returns>
        /// The script content.
        /// </returns>
        public string GenerateProxyScript()
        {
            var controllers = _typesProvider.GetControllerTypes()
                              .Select(_factory.Create)
                              .ToList();

            var template = new ProxyTemplate();

            foreach (var item in controllers)
            {
                template.Definitions.Add(item);
            }

            return(template.TransformText());
        }
Exemplo n.º 8
0
        // ///////////////////////////

        private string _GetAccessToken(string loginId, string password)
        {
            //var loginData = {
            //    grant_type: 'password',
            //    username: self.loginEmail(),
            //    password: self.loginPassword()
            //};

            //$.ajax({
            //    type: 'POST',
            //    url: '/Token',
            //    data: loginData
            //}).done(function (data) {
            //    self.user(data.userName);
            //    // Cache the access token in session storage.
            //    sessionStorage.setItem(tokenKey, data.access_token);
            //}).fail(showError);

            string endpointUrl = ProxyTemplate.GetEndpointUrl();
            var    client      = new HttpClient {
                BaseAddress = new Uri(endpointUrl)
            };
            var url = "Token";

            var postContent = new Dictionary <string, string>();

            postContent["grant_type"] = "password";
            postContent["username"]   = loginId;
            postContent["password"]   = password;

            var req = new HttpRequestMessage(HttpMethod.Post, url);

            req.Content = new FormUrlEncodedContent(postContent);
            var response = client.SendAsync(req).GetAwaiter().GetResult();

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            dynamic result = response.Content.ReadAsAsync <JObject>(new MediaTypeFormatter[] { new JsonMediaTypeFormatter() }).GetAwaiter().GetResult();

            Console.WriteLine(result);
            Console.WriteLine(response.Headers);
            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.ReasonPhrase);

            return(result.access_token);
        }
Exemplo n.º 9
0
        public void TestUpdateStatusItem()
        {
            var appService = _statusItemApplicationServiceFactory.StatusItemApplicationService;
            var statusItem = appService.Get(TestStatusItemId);

            if (statusItem != null)
            {
                var itemDesc = "TESTED" + " " + DateTime.Now.Ticks;

                var endpointUrl = ProxyTemplate.GetEndpointUrl();
                var client      = new HttpClient {
                    BaseAddress = new Uri(endpointUrl)
                };
                //var attrSetInstId = Guid.NewGuid().ToString();

                var url = "StatusItems/{id}";
                url = url.Replace("{id}", TestStatusItemId);

                //var patch = new MergePatchStatusItemDto();
                ////patch.StatusId = TestStatusItemId;
                //patch.Description = itemDesc;
                //patch.Version = statusItem.Version;
                ////PrintAsJObject(patch, "StatusItem, Id: EXST_TESTED");
                //dynamic jObject = JObject.FromObject(patch);

                var version = statusItem.Version;

                var jsonRequstStr = String.Format(
                    "{{\"version\":{0},\"commandId\":\"{1}\",\"description\":\"{2}\"}}",
                    version, Guid.NewGuid().ToString(), itemDesc);
                DoPatch(client, url, jsonRequstStr);

                ////// ///////////////////////////
                //jsonRequstStr = String.Format(
                //    "{{\"version\":{0},\"commandId\":\"{1}\",\"description\":null}}",
                //    version + 1, Guid.NewGuid().ToString(), itemDesc);
                //DoPatch(client, url, jsonRequstStr);
            }
        }
Exemplo n.º 10
0
        public void TestPutThenPostAttributeSetInstance()
        {
            var endpointUrl = ProxyTemplate.GetEndpointUrl();
            var client      = new HttpClient {
                BaseAddress = new Uri(endpointUrl)
            };
            var attrSetInstId = Guid.NewGuid().ToString();

            var urlPut = "AttributeSetInstances/{id}";

            urlPut = urlPut.Replace("{id}", attrSetInstId);

            dynamic jObject = GetTestColorAttributeSetInstance(attrSetInstId, _testColorAttributeSetId);

            var req = new HttpRequestMessage(HttpMethod.Put, urlPut);

            req.Content = new ObjectContent(typeof(JObject), jObject, new JsonMediaTypeFormatter());
            SetAuthenticationHeader(req);
            var response = client.SendAsync(req).GetAwaiter().GetResult();

            Console.WriteLine(response.Content);
            Console.WriteLine(response.Headers);
            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.ReasonPhrase);

            dynamic resultObj = TestGetAttributeSetInstance(attrSetInstId);

            Assert.AreEqual("R", resultObj.Color.ToString());

            var urlPost = "AttributeSetInstances";

            TestPostAttributeSetInstance(client, jObject, urlPost);
            TestPostAttributeSetInstance(client, jObject, urlPost);

            TestGetAttributeSetInstance(attrSetInstId);

            //// 如果 AttributeSetInstance 是“可变的”,那么可以 Patch:
            //TestMergePatchAttributeSetInstance(attrSetInstId);
        }
Exemplo n.º 11
0
 public InOutApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
Exemplo n.º 12
0
 public ProductCategoryMemberApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
 public AttributeSetInstanceExtensionFieldGroupApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
 public AttributeAliasMvoApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
 public OrderItemShipGrpInvReservationApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
 public MovementConfirmationLineMvoApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
Exemplo n.º 17
0
 public DamageHandlingMethodApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
 public PhysicalInventoryLineMvoApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
 public InventoryItemRequirementEntryMvoApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
Exemplo n.º 20
0
        protected void SetAuthenticationHeader(HttpRequestMessage req)
        {
            var authHeader = ProxyTemplate.GetAuthenticationHeaderValue();

            req.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(authHeader.Item1, authHeader.Item2);
        }
Exemplo n.º 21
0
 public OrganizationStructureTypeApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
Exemplo n.º 22
0
 public ShipmentMethodTypeApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
 public SellableInventoryItemApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }
Exemplo n.º 24
0
 public ShipmentPackageContentMvoApplicationServiceProxy(ProxyTemplate proxyTemplate)
     : this(proxyTemplate.GetEndpointUrl())
 {
     _ramlClient.GetAuthenticationHeaderValue = proxyTemplate.GetAuthenticationHeaderValue;
 }