Beispiel #1
0
        public void KeyProperty()
        {
            using (var container = new RhetosTestContainer())
            {
                var deleteTables = new[] { "SyncByKeySource", "SyncByKeyTarget2" };
                container.Resolve<ISqlExecuter>().ExecuteSql(deleteTables.Select(t => "DELETE FROM TestComputedFrom." + t));
                var repository = container.Resolve<Common.DomRepository>();

                var s1a = new TestComputedFrom.SyncByKeySource { Name1 = 1, Name2 = "a", Data = "1a", ID = Guid.NewGuid() };
                var s1b = new TestComputedFrom.SyncByKeySource { Name1 = 1, Name2 = "b", Data = "1b", ID = Guid.NewGuid() };
                var s1c = new TestComputedFrom.SyncByKeySource { Name1 = 1, Name2 = "c", Data = "1c", ID = Guid.NewGuid() };
                var s1d = new TestComputedFrom.SyncByKeySource { Name1 = 1, Name2 = "d", Data = "1d", ID = Guid.NewGuid() };
                var s2a = new TestComputedFrom.SyncByKeySource { Name1 = 2, Name2 = "a", Data = "2a", ID = Guid.NewGuid() };
                repository.TestComputedFrom.SyncByKeySource.Insert(new[] { s1a, s1b, s1c, s1d, s2a });

                Assert.AreEqual("1a1a, 1b1b, 1c1c, 1d1d, 2a2a", TestUtility.DumpSorted(
                    repository.TestComputedFrom.SyncByKeyTarget2.All(),
                    item => item.Name1x + item.Name2x + item.Datax + item.Control));

                {
                    var targetItems = repository.TestComputedFrom.SyncByKeyTarget2.All();
                    foreach (var item in targetItems)
                        item.Control = "x";
                    repository.TestComputedFrom.SyncByKeyTarget2.Update(targetItems);
                }

                Assert.AreEqual("1a1ax, 1b1bx, 1c1cx, 1d1dx, 2a2ax", TestUtility.DumpSorted(
                    repository.TestComputedFrom.SyncByKeyTarget2.All(),
                    item => item.Name1x + item.Name2x + item.Datax + item.Control));

                var s2b = new TestComputedFrom.SyncByKeySource { Name1 = 2, Name2 = "b", Data = "2b", ID = Guid.NewGuid() };
                s1b.Name2 = "B"; // same key - expected for computed value to be updated
                s1c.Name2 = "cc"; // modified key - expected for computed value to delete 1c, insert 1cc (no control 'x')
                s2a.Data = "2aa";
                repository.TestComputedFrom.SyncByKeySource.Save(new[] { s2b }, new[] { s1b, s1c, s2a }, new[] { s1d });

                // expected: insert 2b, 1cc; delete 1c, 1d; update 1B, 2a.
                Assert.AreEqual("1a1ax, 1B1bx, 1cc1c, 2a2aax, 2b2b", TestUtility.DumpSorted(
                    repository.TestComputedFrom.SyncByKeyTarget2.All(),
                    item => item.Name1x + item.Name2x + item.Datax + item.Control));
            }
        }
Beispiel #2
0
        public void FastUpdate()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestHistory.Simple" });
                var repository = container.Resolve<Common.DomRepository>();
                var simpleRepos = repository.TestHistory.Simple;

                Assert.AreEqual("", DumpFull(simpleRepos.All()));

                var sw = Stopwatch.StartNew();
                var s1 = new TestHistory.Simple { Code = 1, Name = "a" };
                simpleRepos.Insert(new[] { s1 });
                Assert.AreEqual(1, simpleRepos.All().Single().Code);

                int lastCode = 1;
                var s1Array = new[] { s1 };
                const bool SlowTest = false;
                const int tests1 = 5 * (SlowTest ? 10 : 1);
                const int tests2 = 3 * (SlowTest ? 10 : 1);
                for (int i = 0; i < tests1; i++)
                {
                    for (int j = 0; j < tests2; j++)
                    {
                        s1.ActiveSince = null;
                        s1.Code = ++lastCode;
                        simpleRepos.Update(s1Array);
                    }
                    Assert.AreEqual(lastCode, simpleRepos.All().Single().Code);
                }
                sw.Stop();

                var h = repository.TestHistory.Simple_Changes.Query().OrderBy(item => item.ActiveSince).ToArray();
                Console.WriteLine(DumpFull(h));
                string msg = string.Format(
                    "Number of history records ({0}) is expected to be between the number of elapsed seconds ({1}) and the number of updates ({2}), depending on the DateTime precision.",
                    h.Count(), Math.Floor(sw.Elapsed.TotalSeconds), tests1 * tests2);
                Console.WriteLine(msg);
                Assert.IsTrue(Math.Floor(sw.Elapsed.TotalSeconds) <= h.Count() && h.Count() <= tests1 * tests2, msg);
            }
        }
Beispiel #3
0
        public void MultiSync_InsertBase()
        {
            using (var container = new RhetosTestContainer())
            {
                var deleteTables = new[] { "MultiSync", "Base1", "Base2" };
                container.Resolve<ISqlExecuter>().ExecuteSql(deleteTables.Select(t => "DELETE FROM TestComputedFrom." + t));
                var repository = container.Resolve<Common.DomRepository>();

                Assert.AreEqual("", TestUtility.DumpSorted(repository.TestComputedFrom.MultiSync.Query(), Dump));

                var b = new TestComputedFrom.Base1 { ID = Guid.NewGuid(), Name1 = "b1" };
                repository.TestComputedFrom.Base1.Insert(new[] { b });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
                Assert.AreEqual("b1 b1a b1b ", TestUtility.DumpSorted(repository.TestComputedFrom.MultiSync.Query().ToList(), Dump));

                var ms = repository.TestComputedFrom.MultiSync.All().Single();
                AssertIsRecently(ms.LastModifiedName1bx, SqlUtility.GetDatabaseTime(container.Resolve<ISqlExecuter>()));
                AssertIsRecently(ms.Start, SqlUtility.GetDatabaseTime(container.Resolve<ISqlExecuter>()));

                ms.Start = new DateTime(2001, 2, 3);
                ms.LastModifiedName1bx = new DateTime(2001, 2, 3);
                repository.TestComputedFrom.MultiSync.Update(new[] { ms });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
                ms = repository.TestComputedFrom.MultiSync.All().Single();
                AssertIsRecently(ms.Start, SqlUtility.GetDatabaseTime(container.Resolve<ISqlExecuter>()), false);
                AssertIsRecently(ms.LastModifiedName1bx, SqlUtility.GetDatabaseTime(container.Resolve<ISqlExecuter>()), false);

                b.Info = "xxx";
                repository.TestComputedFrom.Base1.Update(new[] { b });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
                ms = repository.TestComputedFrom.MultiSync.All().Single();
                AssertIsRecently(ms.Start, SqlUtility.GetDatabaseTime(container.Resolve<ISqlExecuter>()), false);
                AssertIsRecently(ms.LastModifiedName1bx, SqlUtility.GetDatabaseTime(container.Resolve<ISqlExecuter>()), false);

                b.Name1 = "b1new";
                repository.TestComputedFrom.Base1.Update(new[] { b });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
                Assert.AreEqual("b1new b1newa b1newb ", TestUtility.DumpSorted(repository.TestComputedFrom.MultiSync.Query().ToList(), Dump));
                ms = repository.TestComputedFrom.MultiSync.All().Single();
                AssertIsRecently(ms.Start, SqlUtility.GetDatabaseTime(container.Resolve<ISqlExecuter>()), false);
                AssertIsRecently(ms.LastModifiedName1bx, SqlUtility.GetDatabaseTime(container.Resolve<ISqlExecuter>()));
            }
        }