public void CancellationOutside() { var cts = new CancellationTokenSource(); var test = new ProcessDisplayTime(cts.Token); Assert.IsFalse(test.CancellationToken.IsCancellationRequested); cts.Cancel(); Assert.IsTrue(cts.IsCancellationRequested); Assert.IsTrue(test.CancellationToken.IsCancellationRequested); }
public void Properties() { var test = new ProcessDisplayTime(UnitTestInitializeCsv.Token) { Maximum = 5 }; Assert.AreEqual(5, test.Maximum); test.Maximum = 100; Assert.AreEqual(100, test.Maximum); test.Title = "Hello"; Assert.AreEqual("Hello", test.Title); test.Title = ""; Assert.AreEqual("", test.Title); }
public void MeasureTimeToCompletion() { var test = new ProcessDisplayTime(UnitTestInitializeCsv.Token) { Maximum = 100 }; for (long counter = 1; counter <= 20; counter++) { test.SetProcess(counter.ToString(), counter, true); Thread.Sleep(100); } Assert.AreEqual(20, test.TimeToCompletion.Percent); // 20 * 100ms = 2s for 100 we need 10s as 2s are passed it should be 8s var est = test.TimeToCompletion.EstimatedTimeRemaining.TotalSeconds; Assert.IsTrue(est > 7 && est < 12, $"{est}s {test.TimeToCompletion.EstimatedTimeRemainingDisplay}"); }
public void PgpDecryptTest() { using (var pdt = new ProcessDisplayTime(CancellationToken.None)) { using (var input = new MemoryStream(Encoding.UTF8.GetBytes("This is a test"))) { using (var output = new MemoryStream()) { m_PGPKeyStorage.PgpEncrypt(input, output, m_PGPKeyStorage.GetRecipientList().First(), pdt); output.Position = 0; using (var decrypted = m_PGPKeyStorage.PgpDecrypt(output, m_PGPKeyStorage.EncryptedPassphase.Decrypt().ToSecureString())) { var buffer = new byte[1024]; var count = decrypted.Read(buffer, 0, buffer.Length); Assert.AreEqual("This is a test", Encoding.UTF8.GetString(buffer, 0, count)); } } } } }
public void PgpEncryptTest() { using (var pdt = new ProcessDisplayTime(CancellationToken.None)) { using (var input = new MemoryStream(Encoding.UTF8.GetBytes("This is a test"))) { using (var output = new MemoryStream()) { m_PGPKeyStorage.PgpEncrypt(input, output, m_PGPKeyStorage.GetRecipientList().First(), pdt); } } } using (var pdt = new DummyProcessDisplay(CancellationToken.None)) { using (var input = new MemoryStream(Encoding.UTF8.GetBytes("This is a test"))) { using (var output = new MemoryStream()) { m_PGPKeyStorage.PgpEncrypt(input, output, m_PGPKeyStorage.GetRecipientList().First(), pdt); } } } }