/// <summary>
 /// Draw a piechart
 /// </summary>
 private static void DrawPieChart(ref Chart chart, KeyValuePair<string, double>[] dataSeries)
 {
     if(dataSeries == null || dataSeries.Count() == 0 || chart == null || chart.Series == null)
     {
         return;
     }
     if (chart.Series != null && chart.Series.Count == 0)
     {
         chart.Series.Add(new PieSeries());
     }
     ((PieSeries)chart.Series[0]).ItemsSource = dataSeries;
 }
 public void UT_CacheDictionaryObject(Context context)
 {
     string key1 = "UT_CacheDictionaryObject1";
     context.Cache.Remove(key1);
     var users = GetUsers();
     var rd = context.Collections.GetRedisDictionary<int, User>(key1);
     // Test AddMultiple
     var usersKv = users.Select(x => new KeyValuePair<int, User>(x.Id, x));
     rd.AddRange(usersKv);
     // Test GetEnumerator
     foreach (var item in rd)
     {
         Assert.IsTrue(users.Any(u => u.Id == item.Key));
     }
     // Test Count
     Assert.AreEqual(users.Count, rd.Count);
     // Test ContainsKey
     Assert.IsTrue(rd.ContainsKey(users[1].Id));
     // Test Contains
     Assert.IsTrue(rd.Contains(new KeyValuePair<int, User>(users.Last().Id, users.Last())));
     // Test Add
     rd.Add(0, new User() {Id = 0});
     Assert.AreEqual(users.Count + 1, rd.Count);
     Assert.AreEqual(0, rd[0].Id);
     // Test Remove
     rd.Remove(0);
     Assert.IsFalse(rd.ContainsKey(0));
     // Test Keys
     foreach (var k in rd.Keys)
     {
         Assert.IsTrue(users.Any(u => u.Id == k));
     }
     // Test Values
     foreach (var u in rd.Values)
     {
         Assert.IsTrue(users.Any(user => user.Id == u.Id));
     }
     // Test TryGetValue
     User userTest = new User();
     bool b = rd.TryGetValue(999, out userTest);
     Assert.IsFalse(b);
     Assert.IsNull(userTest);
     b = rd.TryGetValue(1, out userTest);
     Assert.IsTrue(b);
     Assert.AreEqual(1, userTest.Id);
     // Test CopyTo
     var array = new KeyValuePair<int, User>[50];
     rd.CopyTo(array, 10);
     Assert.AreEqual(users.Count, array.Count(x => x.Value != null));
     // Test Clear
     rd.Clear();
     Assert.AreEqual(0, rd.Count);
 }
        public void GetTransactionsForSearchCriterias(KeyValuePair<string, string>[] queryExpected,
                                                      ConsumerTransactionsTestSource.FunctionHolder getCall)
        {
            var httpClient = Substitute.For<IHttpClient>();
            var response = new HttpResponseMessage(HttpStatusCode.OK) {Content = new StringContent(@"{
                            receiptId : '134567',
                            type : 'Create',
                            judoId : '12456',
                            originalAmount : 20,
                            amount : 20,
                            netAmount : 20,
                            cardDetails :
                                {
                                    cardLastfour : '1345',
                                    endDate : '1214',
                                    cardToken : 'ASb345AE',
                                    cardType : 'VISA'
                                },
                            currency : 'GBP',
                            consumer :
                                {
                                    consumerToken : 'B245SEB',
                                    yourConsumerReference : 'Consumer1'
                                }
                            }")};

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var responseTask = new TaskCompletionSource<HttpResponseMessage>();
            responseTask.SetResult(response);

            httpClient.SendAsync(Arg.Any<HttpRequestMessage>()).Returns(responseTask.Task);

            var client = new Client(new Connection(httpClient,
                                                    DotNetLoggerFactory.Create,
                                                    "http://something.com"));

            var judo = new JudoPayApi(DotNetLoggerFactory.Create, client);

            getCall.Func(judo.Consumers);

            httpClient.Received().SendAsync(Arg.Any<HttpRequestMessage>());
            var calls = httpClient.ReceivedCalls();

            // ReSharper disable once PossibleNullReferenceException
            var request = calls.FirstOrDefault(call => call.GetMethodInfo().Name == "SendAsync").
                                    GetArguments().FirstOrDefault() as HttpRequestMessage;

            Assert.IsNotNull(request);

            var numberOfMatchingParameters = request.RequestUri.Query
                                    .Remove(0, 1)
                                    .Split('&').Select(kv =>
                                    {
                                        var keyValue = kv.Split('=');
                                        return new KeyValuePair<string, string>(keyValue[0], keyValue[1]);
                                    }).Intersect(queryExpected).Count();

            Assert.AreEqual(queryExpected.Count(), numberOfMatchingParameters);
            Assert.AreEqual("payments", request.RequestUri.AbsolutePath.Split('/').Last());
        }