Beispiel #1
0
        static void showTestContextData(TestContext db, string messag)
        {
            Console.WriteLine("{0} {1} {0}", new string('-', 10), messag);

            foreach (var test in db.Tests)
                Console.WriteLine("id: {0}, str: {1}", test.Id, test.TestString);

            Console.WriteLine();
        }
Beispiel #2
0
        static void prepareDbToTest()
        {
            using (var context = new TestContext())
            {
                context.Tests.RemoveRange(context.Tests);
                context.SaveChanges();

                context.Tests.Add(new Test { TestString = "0" });
                context.SaveChanges();
            }
        }
Beispiel #3
0
        static void task1()
        {
            using (var context1 = new TestContext())
            {
                showTestContextData(context1, "in context1 - 0");
                context1.Tests.Add(new Test { TestString = "1" });
                showTestContextData(context1, "in context1 - 1");

                //continue task 2 and wait when it will be done
                WaitHandleTask2.Set();
                WaitHandle.WaitAny(new WaitHandle[] { WaitHandleTask1 });

                showTestContextData(context1, "in context1 - 2");
                context1.SaveChanges();
                showTestContextData(context1, "in context1 - 3");
            }
        }
Beispiel #4
0
        static void oneThreadTest()
        {
            using (var context1 = new TestContext())
            {
                showTestContextData(context1, "in context1 - 0");
                context1.Tests.Add(new Test {TestString = "1"});
                showTestContextData(context1, "in context1 - 1");

                using (var context2 = new TestContext())
                {
                    context2.Tests.Add(new Test {TestString = "2"});
                    showTestContextData(context1, "in context2 - 0");

                    context2.SaveChanges();
                    showTestContextData(context1, "in context2 - 1");
                }

                showTestContextData(context1, "in context1 - 2");
                context1.SaveChanges();
                showTestContextData(context1, "in context1 - 3");
            }
        }
Beispiel #5
0
        private static void task2()
        {
            WaitHandle.WaitAny(new WaitHandle[] { WaitHandleTask2 });
            using (var context2 = new TestContext())
            {
                context2.Tests.Add(new Test { TestString = "2" });
                showTestContextData(context2, "in context2 - 0");

                context2.SaveChanges();
                showTestContextData(context2, "in context2 - 1");
            }
            //continue task 1
            WaitHandleTask1.Set();
        }