本文整理汇总了C#中KeyValuePair.Count方法的典型用法代码示例。如果您正苦于以下问题:C# KeyValuePair.Count方法的具体用法?C# KeyValuePair.Count怎么用?C# KeyValuePair.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyValuePair
的用法示例。
在下文中一共展示了KeyValuePair.Count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawPieChart
/// <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;
}
示例2: UT_CacheDictionaryObject
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);
}
示例3: GetTransactionsForSearchCriterias
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());
}