Ejemplo n.º 1
0
        public async Task AuthenticateWithToken(TestShippingAuthCredential authCredential)
        {
            var authRequest = new ShippingAuthRequest
            {
                Name      = authCredential.Name,
                Password  = authCredential.Password,
                PublicKey = authCredential.PublicKey
            };

            var response = await Client.Token.Authenticate(authRequest);

            if (!response.Success)
            {
                throw new Exception($"Shipping auth request responded with: {response.StatusCode} code");
            }

            //reasign client dependency
            string essUrl = ApiUrlHelper.GetRequesterFormatUrl(_essApiUrl);

            Client = new ShippingServiceClient(essUrl, _tenantExtId, response.Result, ApiUrlHelper.UrlContainsHttps(_essApiUrl));

            //if response is null, then auth is not success
            var testResponse = await Client.ShippingConfigurations.GetSingle("string");

            if (testResponse == null)
            {
                throw new Exception("Endpoints are not authenticated");
            }
        }
Ejemplo n.º 2
0
        public async Task <HttpEssResponse <string> > Authenticate(ShippingAuthRequest request)
        {
            string stringPayload = await Task.Run(() => JsonConvert.SerializeObject(request));

            var response = await Post(stringPayload);

            return(response);
        }
Ejemplo n.º 3
0
        public async Task POST_AuthToken()
        {
            int expectedCode = 200;
            var authRequest  = new ShippingAuthRequest
            {
                Name      = "aceventura",
                Password  = "******",
                PublicKey = "1cf463c2-3d38-27c2-a47e-cdfdb6f88e84"
            };

            var authResponse = await Client.Token.Authenticate(authRequest);

            Assert.IsNotNull(authResponse, $"{nameof(authResponse)} is null");
            Assert.IsNotNull(authResponse.Result, $"{nameof(authResponse.Result)} is null");
            Assert.AreEqual(expectedCode, authResponse.StatusCode);
        }