public void TestLowLevelAPIErrorCaseWrongClientContext()
        {
            List <Amazon.MobileAnalytics.Model.Event> listEvent = new List <Amazon.MobileAnalytics.Model.Event>();

            listEvent.Add(BuildCustomEvent());

            AutoResetEvent ars = new AutoResetEvent(false);
            Exception      responseException = new Exception();

            Client.PutEventsAsync(new PutEventsRequest()
            {
                Events                = listEvent,
                ClientContext         = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(BuildClientContext())),
                ClientContextEncoding = "base632"
            }, (response) =>
            {
                responseException = response.Exception;
                ars.Set();
            }, new AsyncOptions {
                ExecuteCallbackOnMainThread = false
            });
            ars.WaitOne();

            AmazonMobileAnalyticsException amae = null;

            while (responseException != null)
            {
                if (responseException is AmazonMobileAnalyticsException)
                {
                    amae = responseException as AmazonMobileAnalyticsException;
                    break;
                }
                else
                {
                    responseException = responseException.InnerException;
                }
            }

            Assert.IsNotNull(amae);
            // Ignoring this assertion as there seems to be some differences in the iOS
            // WWW implementation that gives us a status code 0.
            //Assert.AreEqual(HttpStatusCode.BadRequest, amae.StatusCode);
            Assert.AreEqual(amae.ErrorCode, "BadRequestException");
        }
Exemplo n.º 2
0
        public void TestLowLevelAPIErrorCaseWrongClientContext()
        {
            List <Amazon.MobileAnalytics.Model.Event> listEvent = new List <Amazon.MobileAnalytics.Model.Event>();

            listEvent.Add(BuildCustomEvent());

            PutEventsRequest putRequest = new PutEventsRequest();

            putRequest.Events = listEvent;
            string clientContext = BuildClientContext();

            Console.WriteLine("client context is {0}", clientContext);
            putRequest.ClientContext = Convert.ToBase64String(
                System.Text.Encoding.UTF8.GetBytes(clientContext));
            putRequest.ClientContextEncoding = "base32";
            PutEventsResponse PutResponse            = null;
            AmazonMobileAnalyticsException exception = null;

            try
            {
                PutResponse = Client.PutEventsAsync(putRequest).Result;
            }
            catch (AggregateException ae)
            {
                foreach (var e in ae.InnerExceptions)
                {
                    if (e is AmazonMobileAnalyticsException)
                    {
                        exception = e as AmazonMobileAnalyticsException;
                        break;
                    }
                }
            }
            Assert.IsNotNull(exception);
            Assert.AreEqual(exception.StatusCode, HttpStatusCode.BadRequest);
            Assert.AreEqual(exception.ErrorCode, "BadRequestException");
        }