public async Task TestWalletSearchWorksForQuery() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tags); await NonSecrets.AddRecordAsync(wallet, type, id2, value2, tags2); await NonSecrets.AddRecordAsync(wallet, type, id3, value2, tags3); var query = "{\"tagName1\":\"str2\"}"; using (var search = await NonSecrets.OpenSearchAsync(wallet, type, query, optionsEmpty)) { var searchRecordsJson = await search.NextAsync(wallet, 3); var searchRecords = JObject.Parse(searchRecordsJson); var records = (JArray)searchRecords["records"]; Assert.AreEqual(1, records.Count); var expected = JObject.FromObject(new { id = id2, type = (object)null, value = value2, tags = (object)null }); Assert.IsTrue(JValue.DeepEquals(expected, records[0])); } }
public static async Task Execute() { Console.Write("Executing non-secrets sample... "); var myWalletConfig = "{\"id\":\"my_wallet\"}"; var myWalletCredentials = "{\"key\":\"my_wallet_key\"}"; try { // Create and Open First Wallet await WalletUtils.CreateWalletAsync(myWalletConfig, myWalletCredentials); using (var myWallet = await Wallet.OpenWalletAsync(myWalletConfig, myWalletCredentials)) { var id = "myRecordId"; var value = "myRecordValue"; var type = "record_type"; var tagsJson = JsonConvert.SerializeObject(new { tagName = "tagValue", tagName2 = "tagValue2" }); var queryJson = JsonConvert.SerializeObject(new { tagName = "tagValue" }); // Add a new record to the wallet await NonSecrets.AddRecordAsync(myWallet, type, id, value, tagsJson); // Retrieve the record by type and id var recordJson = await NonSecrets.GetRecordAsync(myWallet, type, id, "{}"); var record = JObject.Parse(recordJson); Debug.Assert(record["id"].ToObject <string>() == id); Debug.Assert(record["value"].ToObject <string>() == value); // Open wallet search inside using statement to properly dispose and close the search handle using (var walletSearch = await NonSecrets.OpenSearchAsync(myWallet, type, queryJson, "{}")) { // Invoke fetch next records var searchJson = await walletSearch.NextAsync(myWallet, 5); var search = JObject.Parse(searchJson); // There should be one record returned Debug.Assert(search["records"].ToObject <JObject[]>().Length == 1); } // Close wallets await myWallet.CloseAsync(); } Console.WriteLine("OK", Color.Green); } catch (Exception e) { Console.WriteLine($"Error: {e.Message}", Color.Red); } finally { // Delete wallets await WalletUtils.DeleteWalletAsync(myWalletConfig, myWalletCredentials); } }
public async Task TestAddRecordWorksForDuplicate() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tagsEmpty); var ex = await Assert.ThrowsExceptionAsync <WalletItemAlreadyExistsException>(() => NonSecrets.AddRecordAsync(wallet, type, id, value, tagsEmpty) ); }
/// <inheritdoc /> public virtual Task AddAsync <T>(Wallet wallet, T record) where T : WalletRecord, new() { return(NonSecrets.AddRecordAsync(wallet, record.GetTypeName(), record.GetId(), record.ToJson(), record.Tags.ToJson())); }
public async Task TestDeleteRecordTagsWorksForDeleteAll() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tags); await CheckRecordFieldAsync(wallet, type, id, "tags", tags); await NonSecrets.DeleteRecordTagsAsync(wallet, type, id, "[\"tagName1\", \"tagName2\", \"tagName3\"]"); await CheckRecordFieldAsync(wallet, type, id, "tags", tagsEmpty); }
public async Task TestBuildAttribRequestWorksForRawData() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tagsEmpty); await CheckRecordFieldAsync(wallet, type, id, "tags", tagsEmpty); await NonSecrets.AddRecordTagsAsync(wallet, type, id, tags); await CheckRecordFieldAsync(wallet, type, id, "tags", tags); }
public async Task TestUpdateRecordValueWorks() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tagsEmpty); await CheckRecordFieldAsync(wallet, type, id, "value", value); await NonSecrets.UpdateRecordValueAsync(wallet, type, id, value2); await CheckRecordFieldAsync(wallet, type, id, "value", value2); }
public async Task TestUpdateRecordTagsWorks() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tagsEmpty); await CheckRecordFieldAsync(wallet, type, id, "tags", tagsEmpty); await NonSecrets.UpdateRecordTagsAsync(wallet, type, id, tags); await CheckRecordFieldAsync(wallet, type, id, "tags", tags); }
public async Task TestDeleteRecordWorksForTwice() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tags); await NonSecrets.DeleteRecordAsync(wallet, type, id); var ex = await Assert.ThrowsExceptionAsync <WalletItemNotFoundException>(() => NonSecrets.DeleteRecordAsync(wallet, type, id) ); }
/// <inheritdoc /> public virtual Task AddAsync <T>(Wallet wallet, T record) where T : RecordBase, new() { record.CreatedAtUtc = DateTime.UtcNow; return(NonSecrets.AddRecordAsync(wallet, record.TypeName, record.Id, record.ToJson(_jsonSettings), record.Tags.ToJson())); }
public async Task TestDeleteRecordTagsWorks() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tags); await CheckRecordFieldAsync(wallet, type, id, "tags", tags); await NonSecrets.DeleteRecordTagsAsync(wallet, type, id, "[\"tagName1\"]"); var expectedTags = "{\"tagName2\": \"5\", \"tagName3\": \"12\"}"; await CheckRecordFieldAsync(wallet, type, id, "tags", expectedTags); }
/// <inheritdoc /> public virtual Task AddAsync <T>(Wallet wallet, T record) where T : RecordBase, new() { Debug.WriteLine($"Adding record of type {record.TypeName} with Id {record.Id}"); record.CreatedAtUtc = DateTime.UtcNow; return(NonSecrets.AddRecordAsync(wallet, record.TypeName, record.Id, record.ToJson(_jsonSettings), record.Tags.ToJson())); }
/// <inheritdoc /> public virtual Task AddAsync <T>(Wallet wallet, T record) where T : RecordBase, new() { Debug.WriteLine($"Adding record of type {record.TypeName} with Id {record.Id}"); SetCreatedAtUtc(record); return(NonSecrets.AddRecordAsync(wallet, record.TypeName, record.Id, Base64Encode(record.ToJson(_jsonSettings)), GetTags(record).ToJson())); }
public async Task <string> addRecord(string type, string id, string value, string tagsJson) { try { await NonSecrets.AddRecordAsync( d_openWallet, type, id, value, tagsJson); return("succes!"); } catch (Exception e) { return($"Error: {e.Message}"); } }
public async Task TestGetRecordWorksForDefaultOptions() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tags); var recordJson = await NonSecrets.GetRecordAsync(wallet, type, id, optionsEmpty); var actual = JObject.Parse(recordJson); var expected = JObject.FromObject(new { id = id, type = (object)null, value = value, tags = (object)null }); Assert.IsTrue(JValue.DeepEquals(expected, actual)); }
public async Task TestAddRecordTagsWorksForTwice() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tagsEmpty); await CheckRecordFieldAsync(wallet, type, id, "tags", tagsEmpty); var tags1 = "{\"tagName1\": \"str1\"}"; await NonSecrets.AddRecordTagsAsync(wallet, type, id, tags1); await CheckRecordFieldAsync(wallet, type, id, "tags", tags1); var tags2 = "{\"tagName2\": \"str2\"}"; await NonSecrets.AddRecordTagsAsync(wallet, type, id, tags2); var expectedTags = "{\"tagName1\":\"str1\",\"tagName2\":\"str2\"}"; await CheckRecordFieldAsync(wallet, type, id, "tags", expectedTags); }
public async Task TestGetRecordWorksForFullData() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tags); var optionsJson = JsonConvert.SerializeObject( new { retrieveType = true, retrieveValue = true, retrieveTags = true } ); var recordJson = await NonSecrets.GetRecordAsync(wallet, type, id, optionsJson); var record = JObject.Parse(recordJson); Assert.AreEqual(id, record["id"]); Assert.AreEqual(type, record["type"]); Assert.AreEqual(value, record["value"]); Assert.IsTrue(JValue.DeepEquals(JObject.Parse(tags), JObject.Parse(record["tags"].ToString()))); }
public async Task TestWalletSearchWorksForOptions() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tags); var options = JsonConvert.SerializeObject( new { retrieveRecords = true, retrieveTotalCount = false, retrieveType = false, retrieveValue = false, retrieveTags = false } ); using (var search = await NonSecrets.OpenSearchAsync(wallet, type, queryEmpty, options)) { var searchRecordsJson = await search.NextAsync(wallet, 1); var searchRecords = JObject.Parse(searchRecordsJson); var records = (JArray)searchRecords["records"]; Assert.AreEqual(1, records.Count); var expected = JObject.FromObject( new { id = id, type = (object)null, value = (object)null, tags = (object)null } ); Assert.IsTrue(JValue.DeepEquals(expected, records[0])); } }
public async Task TestAddRecordWorksForDifferentIds() { await NonSecrets.AddRecordAsync(wallet, type, id, value, tagsEmpty); await NonSecrets.AddRecordAsync(wallet, type, id2, value, tagsEmpty); }