예제 #1
0
        public void LoggingStateWriter_Errors()
        {
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using var w      = new MyWriter { Throw = true };
                using var writer = new LoggingStateWriter(w, sw);

                Assert.ThrowsException <NotImplementedException>(() => _ = writer.GetItemWriter("bar", "foo"));
                Assert.ThrowsException <NotImplementedException>(() => writer.DeleteItem("bar", "foo"));
                Assert.ThrowsException <NotImplementedException>(() => writer.Rollback());
                Assert.ThrowsException <NotImplementedException>(() => writer.CommitAsync().GetAwaiter().GetResult());
                Assert.ThrowsException <NotImplementedException>(() => writer.Dispose());

                w.Throw = false;
            }

            var log = sb.ToString();

            foreach (var entry in new[]
            {
                "GetItemWriter(bar, foo)/Start",
                "GetItemWriter(bar, foo)/Error",
                "GetItemWriter(bar, foo)/Stop",

                "DeleteItem(bar, foo)/Start",
                "DeleteItem(bar, foo)/Error",
                "DeleteItem(bar, foo)/Stop",

                "Rollback()/Start",
                "Rollback()/Error",
                "Rollback()/Stop",

                "CommitAsync()/Start",
                "CommitAsync()/Error",
                "CommitAsync()/Stop",

                "Dispose()/Start",
                "Dispose()/Error",
                "Dispose()/Stop",
            })
            {
                Assert.IsTrue(log.Contains(entry), "Not found: '" + entry + "'");
            }
        }
예제 #2
0
        public void LoggingStateWriter_Basics()
        {
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using var w      = new MyWriter();
                using var writer = new LoggingStateWriter(w, sw);

                Assert.AreEqual(CheckpointKind.Full, writer.CheckpointKind);

                var s = writer.GetItemWriter("bar", "foo");
                Assert.IsNotNull(s);

                writer.DeleteItem("bar", "foo");

                writer.Rollback();

                writer.CommitAsync().Wait();
            }

            var log = sb.ToString();

            foreach (var entry in new[]
            {
                "GetItemWriter(bar, foo)/Start",
                "GetItemWriter(bar, foo)/Stop",

                "DeleteItem(bar, foo)/Start",
                "DeleteItem(bar, foo)/Stop",

                "Rollback()/Start",
                "Rollback()/Stop",

                "CommitAsync()/Start",
                "CommitAsync()/Stop",

                "Dispose()/Start",
                "Dispose()/Stop",
            })
            {
                Assert.IsTrue(log.Contains(entry), "Not found: '" + entry + "'");
            }
        }