Example #1
0
        public void UpdateLockedDataReference()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = new Common.DomRepository(executionContext);
                Guid[] guids = new Guid[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
                var s1 = new TestLockItems.Simple { ID = guids[0], Name = "s1", Count = -1 };
                var s2 = new TestLockItems.Simple { ID = guids[1], Name = "s2", Count = 1 };

                var t1 = new TestLockItems.Simple2 { ID = guids[2], Name = "t1", TestReference = s1, Count = -1 };
                var t2 = new TestLockItems.Simple2 { ID = guids[3], Name = "t2", TestReference = s1, Count = 1 };

                repository.TestLockItems.Simple.Insert(new[] { s1, s2 });
                AssertData("s1, s2", repository);
                repository.TestLockItems.Simple2.Insert(new[] { t1, t2 });
                AssertDataSimple2("t1, t2", repository);

                foreach (var e in new[] { t1, t2 })
                    e.TestReference = s1;
                repository.TestLockItems.Simple2.Update(new[] { t1 });

                AssertDataSimple2("t1, t2", repository);
                foreach (var e in new[] { t1, t2 })
                    e.TestReference = s2;

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t1 }), "TestReference is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t2, t1 }), "TestReference is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t1, t2 }), "TestReference is locked if count negative.");
                AssertDataSimple2("t1, t2", repository);

                repository.TestLockItems.Simple2.Update(new[] { t2 });
                AssertDataSimple2("t1, t2", repository);
            }
        }
Example #2
0
        public void UpdateLockedDataReference()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var    repository = container.Resolve <Common.DomRepository>();
                Guid[] guids      = new Guid[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
                var    s1         = new TestLockItems.Simple {
                    ID = guids[0], Name = "s1", Count = -1
                };
                var s2 = new TestLockItems.Simple {
                    ID = guids[1], Name = "s2", Count = 1
                };

                var t1 = new TestLockItems.Simple2 {
                    ID = guids[2], Name = "t1", TestReferenceID = s1.ID, Count = -1
                };
                var t2 = new TestLockItems.Simple2 {
                    ID = guids[3], Name = "t2", TestReferenceID = s1.ID, Count = 1
                };

                repository.TestLockItems.Simple.Insert(new[] { s1, s2 });
                AssertData("s1, s2", repository);
                repository.TestLockItems.Simple2.Insert(new[] { t1, t2 });
                AssertDataSimple2("t1, t2", repository);

                foreach (var e in new[] { t1, t2 })
                {
                    e.TestReferenceID = s1.ID;
                }
                repository.TestLockItems.Simple2.Update(new[] { t1 });

                AssertDataSimple2("t1, t2", repository);
                foreach (var e in new[] { t1, t2 })
                {
                    e.TestReferenceID = s2.ID;
                }

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t1 }), "TestReference is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t2, t1 }), "TestReference is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t1, t2 }), "TestReference is locked if count negative.");
                AssertDataSimple2("t1, t2", repository);

                repository.TestLockItems.Simple2.Update(new[] { t2 });
                AssertDataSimple2("t1, t2", repository);
            }
        }
Example #3
0
        public void UpdateLockedExceptProperty(Action <TestLockItems.Simple2> update, bool updateShouldPass)
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] {
                    "DELETE FROM TestLockItems.Simple2",
                    "DELETE FROM TestLockItems.Simple"
                });

                var simpleRepos  = container.Resolve <GenericRepository <TestLockItems.Simple> >();
                var simple2Repos = container.Resolve <GenericRepository <TestLockItems.Simple2> >();

                var s1a = new TestLockItems.Simple {
                    Name = "a"
                };
                var s1b = new TestLockItems.Simple {
                    Name = "b"
                };
                simpleRepos.Insert(s1a, s1b);

                var s2a = new TestLockItems.Simple2 {
                    Name = "aa", Count = 100, TestReferenceID = s1a.ID
                };
                var s2b = new TestLockItems.Simple2 {
                    Name = "LockExceptName", Count = 200, TestReferenceID = s1b.ID
                };
                simple2Repos.Insert(s2a, s2b);

                s2a.Name += "X";
                s2a.Count++;
                update(s2b);

                if (updateShouldPass)
                {
                    simple2Repos.Update(s2a, s2b);
                    TestUtility.DumpSorted(simple2Repos.Load(), item => item.Name + " " + item.Count);
                    Assert.AreEqual(s2b.Name, simple2Repos.Load(new[] { s2b.ID }).Single().Name);
                }
                else
                {
                    TestUtility.ShouldFail(() => simple2Repos.Update(s2a, s2b),
                                           "The record is locked except the Name property", s2b.ID.ToString());
                }
            }
        }
Example #4
0
        public void UpdateLockedExceptProperty(Action<TestLockItems.Simple2> update, bool updateShouldPass)
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] {
                    "DELETE FROM TestLockItems.Simple2",
                    "DELETE FROM TestLockItems.Simple" });

                var simpleRepos = container.Resolve<GenericRepository<TestLockItems.Simple>>();
                var simple2Repos = container.Resolve<GenericRepository<TestLockItems.Simple2>>();

                var s1a = new TestLockItems.Simple { Name = "a" };
                var s1b = new TestLockItems.Simple { Name = "b" };
                var s2a = new TestLockItems.Simple2 { Name = "aa", Count = 100, TestReference = s1a };
                var s2b = new TestLockItems.Simple2 { Name = "LockExceptName", Count = 200, TestReference = s1b };

                simpleRepos.Insert(s1a, s1b);
                simple2Repos.Insert(s2a, s2b);

                s2a.Name += "X";
                s2a.Count++;
                update(s2b);

                if (updateShouldPass)
                {
                    simple2Repos.Update(s2a, s2b);
                    TestUtility.DumpSorted(simple2Repos.Read(), item => item.Name + " " + item.Count);
                    Assert.AreEqual(s2b.Name, simple2Repos.Read(new[] { s2b.ID }).Single().Name);
                }
                else
                    TestUtility.ShouldFail(() => simple2Repos.Update(s2a, s2b),
                        "The record is locked except the Name property", s2b.ID.ToString());
            }
        }
Example #5
0
        public void UpdateLockedDataReference()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();
                Guid[] guids = new Guid[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
                var s1 = new TestLockItems.Simple { ID = guids[0], Name = "s1", Count = -1 };
                var s2 = new TestLockItems.Simple { ID = guids[1], Name = "s2", Count = 1 };

                var t1 = new TestLockItems.Simple2 { ID = guids[2], Name = "t1", TestReferenceID = s1.ID, Count = -1 };
                var t2 = new TestLockItems.Simple2 { ID = guids[3], Name = "t2", TestReferenceID = s1.ID, Count = 1 };

                repository.TestLockItems.Simple.Insert(new[] { s1, s2 });
                AssertData("s1, s2", repository);
                repository.TestLockItems.Simple2.Insert(new[] { t1, t2 });
                AssertDataSimple2("t1, t2", repository);

                foreach (var e in new[] { t1, t2 })
                    e.TestReferenceID = s1.ID;
                repository.TestLockItems.Simple2.Update(new[] { t1 });

                AssertDataSimple2("t1, t2", repository);
                foreach (var e in new[] { t1, t2 })
                    e.TestReferenceID = s2.ID;

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t1 }), "TestReference is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t2, t1 }), "TestReference is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t1, t2 }), "TestReference is locked if count negative.");
                AssertDataSimple2("t1, t2", repository);

                repository.TestLockItems.Simple2.Update(new[] { t2 });
                AssertDataSimple2("t1, t2", repository);
            }
        }