Exemplo n.º 1
0
        private void Backup()
        {
            try
            {
                using (var src = new SQLiteConnection(SrcZip))
                    using (var dst = new SQLiteConnection(DstZip))
                        using (DisposeWatch.Start(e => Console.WriteLine($"Backup Completed in {e.TotalMilliseconds} ms")))
                        {
                            src.Open();
                            dst.Open();

                            Console.WriteLine("Start Copy");
                            src.BackupDatabase(dst, "main", "main", -1, null, 0);
                            Console.WriteLine("End  Copy");
                        }
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Couldn't copy");
                Console.WriteLine(ex.Message);
            }
        }
        public void Dispose_ActionSupplied_InvokesAction()
        {
            // Assemble
            bool isCalled = false;
            var  watch    = DisposeWatch.Start(_ => isCalled = true);

            // Act
            watch.Dispose();

            // Assert
            Assert.IsTrue(isCalled);
        }
        public void Dispose_CalledSecondTime_DoesNotInvokeAction()
        {
            // Assemble
            int calledCount = 0;
            var watch       = DisposeWatch.Start(_ => calledCount++);

            // Act
            watch.Dispose();
            watch.Dispose();

            // Assert
            Assert.AreEqual(1, calledCount);
        }
Exemplo n.º 4
0
        public void Work()
        {
            var db = new Database(SqlData.SrcFilePath, SqlData.SimpleSrc);

            db.CreateDb();

            Console.Write($"Counting {_options.LoopCount} inserts");
            using (DisposeWatch.Start(span => Console.WriteLine($":  {span.TotalSeconds} seconds")))
            {
                for (int i = 0; i < _options.LoopCount; i++)
                {
                    db.ExecuteNonQuery();
                }
            }
        }
        public void Dispose_MessageSupplied_LogsOutMessage()
        {
            // Assemble
            string message = $"Hello World {StringUtils.GenerateRandom(5)}";
            var    traces  = new StringBuilder();

            using (var tw = new StringWriter(traces))
                using (TraceListener listener = new TextWriterTraceListener(tw))
                {
                    Debug.Listeners.Add(listener);
                    var watch = DisposeWatch.Start(message);

                    // Act
                    watch.Dispose();

                    // Assert
                    Debug.Listeners.Remove(listener);
                    StringAssert.Contains(message, traces.ToString());
                }
        }
Exemplo n.º 6
0
        public void Work()
        {
            CreateSourceDb();

            var s = new Signal {
                KeepGoing = true
            };
            var t1 = Task.Factory.StartNew(() => LotsOfSql(s, SQL_WRITE));
            var t2 = Task.Factory.StartNew(() => LotsOfSql(s, SQL_READ));

            Console.WriteLine("Wait for some reads and writes to start");
            Thread.Sleep(TimeSpan.FromSeconds(30.5));
            Backup();

            using (DisposeWatch.Start(e => Console.WriteLine($"Waited {e.TotalMilliseconds} ms")))
            {
                s.KeepGoing = false;

                Task.WaitAll(t1, t2);
            }

            CompareCounts();
        }
 public void Start_NullAction_Throws()
 {
     // Act/Assert
     Assert.Throws <ArgumentNullException>(() => DisposeWatch.Start((Action <TimeSpan>)null));
 }