public void ConstructArray() { var key = new SimpleKey("Test"); Assert.AreEqual("Test", key.FullKey); key = new SimpleKey("Test", "Any"); Assert.AreEqual("Test:Any", key.FullKey); }
public static void TestSimpleDictionaryKey() { var key = new SimpleKey(); var listingLevelNames = new Dictionary <SimpleKey, string>(); listingLevelNames.Add(key, "None"); Assert.AreEqual("{\"Newtonsoft.Json.Tests.Issues.Case74+SimpleKey\":\"None\"}", Serialize(listingLevelNames, false), "Simple dictionary serialized correctly."); }
private IDataKey GetKey(string key, IIndexKey indexes) { var repository = indexes.RepositoryKey; if (!string.IsNullOrEmpty(repository)) { return(SimpleKey.GenerateKey(repository, key)); } return(new ObjectKey(key)); }
public void KeyBase_column_sort_list_successfully_constructed() { var column1 = new _Int32(); var column2 = new _Int32(); var simpleKey = new SimpleKey(column1, column2); Assert.AreEqual(2, simpleKey.Count); Assert.AreEqual(column1, simpleKey[0].Column); Assert.AreEqual(column2, simpleKey[1].Column); Assert.AreEqual(SortDirection.Unspecified, simpleKey[0].Direction); Assert.AreEqual(SortDirection.Descending, simpleKey[1].Direction); }
static async Task Main(string[] args) { Console.WriteLine("## SimpleCache vs MemoryCache"); Console.WriteLine(); Console.WriteLine("Test Count | SimpleCache (ms) | MemoryCache (ms)"); Console.WriteLine("-----------|------------------|-----------------"); int maxTestCount = 2 << 16; for (int testCount = 2 << 10; testCount <= maxTestCount; testCount <<= 2) { int capacity = 128; var cacheOptions = new MemoryCacheOptions { SizeLimit = capacity }; var entryOptions = new MemoryCacheEntryOptions { Size = 1 }; var client = new HttpClient(); var requestUrl = "https://httpbin.org/cache"; var response = await client.GetAsync(requestUrl); SimpleKey key = null; var stopWatch = new Stopwatch(); stopWatch.Start(); var simpleCache = SimpleCache.Build().SpecifyCapacity(capacity); for (int i = 0; i < testCount; i++) { simpleCache.Get(key); key = new SimpleKey(); simpleCache.Set(key, response); Debug.Assert(simpleCache.Count <= capacity); } stopWatch.Stop(); var timeForSimpleCache = stopWatch.ElapsedMilliseconds; stopWatch.Reset(); stopWatch.Start(); var memoryCache = new MemoryCache(cacheOptions); for (int i = 0; i < testCount; i++) { memoryCache.Get(key); key = new SimpleKey(); memoryCache.Set(key, response, entryOptions); Debug.Assert(memoryCache.Count <= capacity); } stopWatch.Stop(); var timeForMemoryCache = stopWatch.ElapsedMilliseconds; Console.WriteLine($"{testCount} | {timeForSimpleCache} | {timeForMemoryCache}"); } }
public ActionResult <IEnumerable <Account> > MyAccounts([FromBody] SimpleKey key) { var result = new List <Account>(); try { string keyPair; if (!Enum.TryParse(key.CurveType, true, out KeyType curveType)) { return(BadRequest(new MicroCoinError(ErrorCode.InvalidPubKey, "Invalid key type", "Valid types are: secp256k1, secp384k1"))); } try { keyPair = client.EncodePubKey(Enum.Parse <KeyType>(key.CurveType, true), key.X.PadLeft(64, '0'), key.Y.PadLeft(64, '0')); } catch (MicroCoinRPCException e) { return(this.HandlerError(e)); } foreach (var account in client.FindMyAccounts(keyPair)) { result.Add(new Account { AccountNumber = account.AccountNumber, Balance = account.Balance, Name = account.Name, Price = account.Price / 10000M, Status = account.State.ToString(), Type = account.Type }); } return(result); } catch (MicroCoinRPCException e) { return(this.HandlerError(e)); } }
public void GenerateKey() { var result = SimpleKey.GenerateKey("Repo", "Test"); Assert.AreEqual("Repo:object:Test", result.FullKey); }
/// <summary> /// Check if a simple key may start at the current position and add it if /// needed. /// </summary> private void SaveSimpleKey() { // A simple key is required at the current position if the scanner is in // the block context and the current column coincides with the indentation // level. bool isRequired = (flowLevel == 0 && indent == cursor.LineOffset); // A simple key is required only when it is the first token in the current // line. Therefore it is always allowed. But we add a check anyway. Debug.Assert(simpleKeyAllowed || !isRequired, "Can't require a simple key and disallow it at the same time."); // Impossible. // If the current position may start a simple key, save it. if (simpleKeyAllowed) { var key = new SimpleKey(true, isRequired, tokensParsed + tokens.Count, cursor); RemoveSimpleKey(); simpleKeys.Pop(); simpleKeys.Push(key); } }