public async Task CanAddUpdateAndDeleteEntries() { try { var session = await GetAuth().MockAuthenticationAsync(Credentials.Random); Assert.IsTrue(session.HasValue); Assert.IsNotNull(session.Value); var networkOperations = new Network.NetworkDataOps(session.Value); var md = await networkOperations.CreateEmptyMd(DataProtocol.DEFAULT_PROTOCOL); var mdOps = new Network.MdDataOps(session.Value, md); await mdOps.AddObjectAsync(AuthHelpers.GetRandomString(10), AuthHelpers.GetRandomString(10)); var entries = await mdOps.GetEntriesAsync(); Assert.AreEqual(1, entries.Count); var key = AuthHelpers.GetRandomString(10); await mdOps.AddObjectAsync(key, AuthHelpers.GetRandomString(10)); entries = await mdOps.GetEntriesAsync(); Assert.AreEqual(2, entries.Count); var newValue = AuthHelpers.GetRandomString(10); await mdOps.UpdateObjectAsync(key, newValue, 0); entries = await mdOps.GetEntriesAsync(); var fetchedValue = entries .Where(e => e.Key.Key.ToUtfString() == key) .FirstOrDefault().Value.Content .ToUtfString() .Parse <string>(); Assert.AreEqual( newValue, fetchedValue); await mdOps.DeleteObjectAsync(key, 1); entries = await mdOps.GetEntriesAsync(); Assert.AreEqual(1, entries.Count); } catch (Exception ex) { Assert.Fail(ex.Message); } }
async Task <(byte[], ulong)> MdLocator(Session session, bool pub = false) { var networkOps = new Network.NetworkDataOps(session); using (var permissionsHandle = await session.MDataPermissions.NewAsync()) { using (var appSignPkH = await session.Crypto.AppPubSignKeyAsync()) await session.MDataPermissions.InsertAsync(permissionsHandle, appSignPkH, networkOps.GetFullPermissions()); var md = pub ? await session.MDataInfoActions.RandomPublicAsync(16001) : await session.MDataInfoActions.RandomPrivateAsync(16001); await session.MData.PutAsync(md, permissionsHandle, NativeHandle.EmptyMDataEntries); // <---------------------------------------------- Commit ------------------------ return(md.Name, md.TypeTag); } }
public async Task TestInitialize() { _session = (await TestAppCreation.CreateTestApp()).Value; _networkOps = new Network.NetworkDataOps(_session); METADATA_KEY_BYTES = METADATA_KEY.ToUtfBytes(); }