public void TrueApiClientAuthenticates()
        {
            var client = new TrueApiClient(TrueApiClient.SandboxApiUrl, new Credentials
            {
                CertificateThumbprint = TestCertificateThumbprint,
            });

            // test tracing
            var trace = new StringBuilder();

            client.Tracer = (f, a) => trace.AppendFormat(f, a);

            try
            {
                // authenticates and requests a resource
                var s = client.Get("auth/key");
                Assert.NotNull(s);
                Assert.IsTrue(client.IsAuthenticated);

                if (client.Client.Authenticator is CredentialsAuthenticator auth)
                {
                    Assert.NotNull(auth.AuthToken);
                }
                else
                {
                    Assert.Fail("Authenticator is missing");
                }
            }
            finally
            {
                // logs out
                Assert.DoesNotThrow(() => client.Dispose());
                Assert.IsFalse(client.IsAuthenticated);
                if (client.Client.Authenticator is CredentialsAuthenticator auth)
                {
                    Assert.IsNull(auth.AuthToken);
                }
            }

            var traceText = trace.ToString();

            Assert.IsTrue(traceText.Length > 0, "TrueApiClient trace is empty");
            Assert.IsTrue(traceText.Contains("// Authenticate"));
            Assert.IsTrue(traceText.Contains("// GetToken"));
            Assert.IsTrue(traceText.Contains("-> GET"));
            Assert.IsTrue(traceText.Contains("<- OK 200 (OK)"));
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            Credentials = new TrueApiCredentials()
            {
                CertificateThumbprint = "bd7aa30aed4e856fc68b05eda8ae85d7888b2da6"
            };
            TrueApiClient = new TrueApiClient("https://int01.gismt.crpt.tech/api/v3/true-api/", Credentials);

            //var cises = TrueApiClient.GetCisesByOrderId("a1769132-796e-47cb-8bc5-1053c4d7d6c5");
            return;

            //var t = TrueApiClient.PostVoid("cises/list", , new[] { new Parameter("values","010463578558601021U6vlokgzAt0K!", ParameterType.RequestBody) });
            var t  = TrueApiClient.Get("elk/product-groups/balance/all");
            var tt = TrueApiClient.Get <ProductGroupBalance[]>("elk/product-groups/balance/all");
        }
Exemplo n.º 3
0
        private void AuthenticateTrueApiClient(AuthToken savedToken = null)
        {
            var client = new TrueApiClient(TrueApiClient.SandboxApiUrl, new TrueApiCredentials
            {
                CertificateThumbprint = TestCertificateThumbprint,
                SessionToken          = savedToken,
            });

            // test tracing
            var trace = new StringBuilder();

            client.Tracer = (f, a) =>
            {
                trace.AppendFormat(f, a);
                TestContext.Progress.WriteLine(f, a);
            };

            try
            {
                // authenticates and requests a resource
                var s = client.Get("auth/key");
                Assert.NotNull(s);
                Assert.IsTrue(client.Authenticator.IsAuthenticated);
                Assert.NotNull(client.Authenticator.AuthToken);

                // save the token for later reuse
                SaveTrueApiToken(client.Authenticator.AuthToken);
            }
            finally
            {
                // logs out
                Assert.DoesNotThrow(() => client.Dispose());
                Assert.IsFalse(client.Authenticator.IsAuthenticated);
                Assert.IsNull(client.Authenticator.AuthToken);
            }

            var traceText = trace.ToString();

            Assert.IsTrue(traceText.Length > 0, "TrueApiClient trace is empty");
            Assert.IsTrue(traceText.Contains("// "));
            Assert.IsTrue(traceText.Contains("-> GET"));
            Assert.IsTrue(traceText.Contains("<- OK 200 (OK)"));
        }