public async Task PerformMutableDataOptionsTestAsync() { try { var session = await Authentication.MockAuthenticationAsync(); Assert.IsNotNull(session); MutableDataOperations.InitialiseSession(session); var mdOperations = new MutableDataOperations(); await mdOperations.CreateMutableData(); await mdOperations.AddEntry(Helpers.GenerateRandomString(10), Helpers.GenerateRandomString(10)); var enteries = await mdOperations.GetEntries(); Assert.AreEqual(1, enteries.Count); var key = Helpers.GenerateRandomString(10); var value = Helpers.GenerateRandomString(10); await mdOperations.AddEntry(key, value); enteries = await mdOperations.GetEntries(); Assert.AreEqual(2, enteries.Count); var newValue = Helpers.GenerateRandomString(10); await mdOperations.UpdateEntry(key, newValue); enteries = await mdOperations.GetEntries(); Assert.AreEqual( newValue, enteries.Where(e => e.Key.Key.ToUtfString() == key).FirstOrDefault().Value.Content.ToUtfString()); await mdOperations.DeleteEntry(key); enteries = await mdOperations.GetEntries(); Assert.AreEqual(1, enteries.Count); } catch (Exception ex) { Assert.Fail(ex.Message); } }
private static async Task Main() { string[] args = Environment.GetCommandLineArgs(); Console.WriteLine("SafeNetwork Console Application"); try { if (IsApplicationFirstInstance()) { Console.Write("Press Y/y to use mock safe-browser for authentication otherwise a random mock account will be used : "); var input = Console.ReadLine(); if (input.Equals("Y") || input.Equals("y")) { // args[0] is always the path to the application // update system registery Helpers.RegisterAppProtocol(args[0]); // Request authentication from mock browser await Authentication.MockAuthenticationWithBrowserAsync(); // Start named pipe server and listen for message var authResponse = PipeComm.ReceiveNamedPipeServerMessage(); if (!string.IsNullOrEmpty(authResponse)) { // Create session from response await Authentication.ProcessAuthenticationResponse(authResponse); // Show user menu UserInput userInput = new UserInput(); await userInput.ShowUserOptions(); } } else { // Create session from mock authentication var session = await Authentication.MockAuthenticationAsync(); // Initialise session for Mutable Data operations MutableDataOperations.InitialiseSession(session); // Show user menu UserInput userInput = new UserInput(); await userInput.ShowUserOptions(); } } else { // We are not the first instance, send the named pipe message with our payload and stop loading if (args.Length >= 2) { var namedPipePayload = new NamedPipePayload { SignalQuit = false, Arguments = args[1] }; // Send the message PipeComm.SendNamedPipeClient(namedPipePayload); } // Close app return; } } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); } Console.ReadLine(); }
public UserInput() { _mdOperations = new MutableDataOperations(); }