Exemplo n.º 1
0
        public void JsonParse_NextCallerDocsPlatformStatisticsSampe_PlatformStatisticsSuccessfullyParsed()
        {
            //Arrange
            string json = Properties.Resources.JsonPlatformStatistics;

            //Action
            PlatformStatistics stats = JsonSerializer.Deserialize <PlatformStatistics>(json);

            //Assert
            Assert.IsNotNull(stats);

            Assert.IsNotNull(stats.TotalPlatformOperations);
            Assert.AreEqual(59, stats.TotalPlatformOperations["2015-07"]);

            Assert.IsNotNull(stats.BilledPlatformOperations);
            Assert.AreEqual(59, stats.BilledPlatformOperations["2015-07"]);

            Assert.IsNotNull(stats.PlatformAccounts);
            Assert.AreEqual(2, stats.PlatformAccounts.Length);

            Assert.AreEqual("test_platform_username1", stats.PlatformAccounts[0].Id);
            Assert.AreEqual("John", stats.PlatformAccounts[0].FirstName);
            Assert.AreEqual("Doe", stats.PlatformAccounts[0].LastName);
            Assert.AreEqual("NC*", stats.PlatformAccounts[0].CompanyName);
            Assert.AreEqual("*****@*****.**", stats.PlatformAccounts[0].Email);
            Assert.AreEqual("/api/v2.1/accounts/test_platform_username1/", stats.PlatformAccounts[0].ResourceUri);
            Assert.AreEqual(5, stats.PlatformAccounts[0].NumberOfOperations);

            Assert.IsNotNull(stats.PlatformAccounts[0].TotalOperations);
            Assert.AreEqual(5, stats.PlatformAccounts[0].TotalOperations["2015-07"]);

            Assert.IsNotNull(stats.PlatformAccounts[0].BilledOperations);
            Assert.AreEqual(5, stats.PlatformAccounts[0].BilledOperations["2015-07"]);

            Assert.AreEqual("me", stats.PlatformAccounts[1].Id);
            Assert.AreEqual("", stats.PlatformAccounts[1].FirstName);
            Assert.AreEqual("", stats.PlatformAccounts[1].LastName);
            Assert.AreEqual("", stats.PlatformAccounts[1].CompanyName);
            Assert.AreEqual("", stats.PlatformAccounts[1].Email);
            Assert.AreEqual("/api/v2.1/accounts/me/", stats.PlatformAccounts[1].ResourceUri);
            Assert.AreEqual(4, stats.PlatformAccounts[1].NumberOfOperations);

            Assert.IsNotNull(stats.PlatformAccounts[1].TotalOperations);
            Assert.AreEqual(4, stats.PlatformAccounts[1].TotalOperations["2015-07"]);

            Assert.IsNotNull(stats.PlatformAccounts[1].BilledOperations);
            Assert.AreEqual(4, stats.PlatformAccounts[1].BilledOperations["2015-07"]);
        }
Exemplo n.º 2
0
        public static void Run()
        {
            const string Username = "";
            const string Password = "";
            const int    page     = 1;
            const bool   Sandbox  = true;

            NextCallerPlatformClient client = new NextCallerPlatformClient(Username, Password, Sandbox);

            try
            {
                PlatformStatistics stats = client.GetPlatformStatistics(page);

                //stats.PlatformUsers = new []
                //{
                //	new PlatformUser
                //	{
                //		CreatedTime = "2014­04­16T13:42:00",
                //		NumberOfOperations = 24,
                //		ResourceUri = "/api/v2/platform_users/pl2_un1/",
                //		Username = "******",
                //		TotalCalls = new Dictionary<string, int>
                //		{
                //			{ "201403", 7 },
                //			{ "201404", 7 },
                //			{ "201405", 7 }
                //		},
                //		SuccessfulCalls = new Dictionary<string, int>
                //		{
                //			{ "201403", 7 },
                //			{ "201404", 7 },
                //			{ "201405", 7 }
                //		},
                //		BillableCalls = new Dictionary<string, int>
                //		{
                //			{ "201403", 7 },
                //			{ "201404", 7 },
                //			{ "201405", 7 }
                //		}
                //	}
                //};

                //stats.SuccessfulPlatformCalls = new Dictionary<string, int>
                //{
                //	{ "201403", 7 },
                //	{ "201404", 7 },
                //	{ "201405", 7 }
                //};

                //stats.TotalPlatformCalls = new Dictionary<string, int>
                //{
                //	{ "201403", 7 },
                //	{ "201404", 7 },
                //	{ "201405", 7 }
                //};

                //stats.BillablePlatformCalls = new Dictionary<string, int>
                //{
                //	{ "201403", 7 },
                //	{ "201404", 7 },
                //	{ "201405", 7 }
                //};
            }
            catch (FormatException formatException)
            {
                HttpWebRequest  request  = formatException.Request;
                HttpWebResponse response = formatException.Response;

                HttpStatusCode code = response.StatusCode;
                Console.WriteLine("Status code: {0}", code);

                string reasonPhrase = response.StatusDescription;
                Console.WriteLine("Reason Phrase: {0}", reasonPhrase);

                string responseContent = formatException.Content;
                Console.WriteLine("Content : {0}", responseContent);
            }
            catch (BadRequestException badRequestException)
            {
                HttpWebRequest  request  = badRequestException.Request;
                HttpWebResponse response = badRequestException.Response;

                Error parsedError = badRequestException.Error;

                string errorCode = parsedError.Code;
                string message   = parsedError.Message;
                string type      = parsedError.Type;

                Dictionary <string, string[]> description = parsedError.Description;

                Console.WriteLine(parsedError.ToString());
            }
        }