コード例 #1
0
ファイル: LockPropertyTest.cs プロジェクト: koav/Rhetos
        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);
            }
        }
コード例 #2
0
        public void DeleteModifiedPersistentObject()
        {
            using (var scope = TestScope.Create())
            {
                scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = scope.Resolve <Common.DomRepository>();

                {
                    var s3Lock = new TestLockItems.Simple {
                        ID = Guid.NewGuid(), Name = "s3_lock"
                    };
                    repository.TestLockItems.Simple.Insert(new[] { s3Lock });

                    AssertData("s3_lock", repository);
                    AssertData("s3_lock", repository);
                }

                {
                    var s3Persistent = repository.TestLockItems.Simple.Load().Single();
                    s3Persistent.Name = "abc";
                    TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Persistent }),
                                           "[Test] Name contains lock mark");

                    AssertData("s3_lock", repository);
                    AssertData("s3_lock", repository);
                }
            }
        }
コード例 #3
0
ファイル: LockItemsTest.cs プロジェクト: kmeze/Rhetos
        public void DeleteModifiedPersistentObject()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();

                {
                    var s3Lock = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s3_lock" };
                    repository.TestLockItems.Simple.Insert(new[] { s3Lock });

                    AssertData("s3_lock", repository);
                    container.Resolve<Common.ExecutionContext>().NHibernateSession.Clear();
                    AssertData("s3_lock", repository);
                }

                {
                    var s3Persistent = repository.TestLockItems.Simple.All().Single();
                    s3Persistent.Name = "abc";
                    TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Persistent }),
                        "Name contains lock mark");

                    AssertData("s3_lock", repository);
                    container.Resolve<Common.ExecutionContext>().NHibernateSession.Clear();
                    AssertData("s3_lock", repository);
                }
            }
        }
コード例 #4
0
ファイル: LockPropertyTest.cs プロジェクト: koav/Rhetos
        public void UpdateLockedData()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = new Common.DomRepository(executionContext);

                var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1", Count = -1 };
                var s2 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s2", Count = 1 };

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

                foreach (var e in new[] { s1, s2 })
                    e.Name = e.Name + "x";
                AssertData("s1, s2", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1 }), "Name is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s2, s1 }), "Name is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1, s2 }), "Name is locked if count negative.");
                AssertData("s1, s2", repository);

                repository.TestLockItems.Simple.Update(new[] { s2 });
                AssertData("s1, s2x", repository);
            }
        }
コード例 #5
0
ファイル: LockPropertyTest.cs プロジェクト: tjakopovic/Rhetos
        public void UpdateLockedData()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();

                var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1", Count = -1 };
                var s2 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s2", Count = 1 };

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

                foreach (var e in new[] { s1, s2 })
                    e.Name = e.Name + "x";
                AssertData("s1, s2", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1 }), "Name is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s2, s1 }), "Name is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1, s2 }), "Name is locked if count negative.");
                AssertData("s1, s2", repository);

                repository.TestLockItems.Simple.Update(new[] { s2 });
                AssertData("s1, s2x", repository);
            }
        }
コード例 #6
0
ファイル: LockItemsTest.cs プロジェクト: tjakopovic/Rhetos
        public void UpdateLockedData()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();

                var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1" };
                var s2 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s2" };
                var s3Lock = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s3_lock" };
                var s4 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s4" };
                repository.TestLockItems.Simple.Insert(new[] { s1, s2, s3Lock, s4 });
                AssertData("s1, s2, s3_lock, s4", repository);

                foreach (var e in new[] {s1, s2, s3Lock, s4})
                    e.Name = e.Name + "x";
                AssertData("s1, s2, s3_lock, s4", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock }), "Name contains lock mark.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1, s3Lock }), "Name contains lock mark.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock, s4 }), "Name contains lock mark.");
                AssertData("s1, s2, s3_lock, s4", repository);

                repository.TestLockItems.Simple.Update(new[] { s1 });
                AssertData("s1x, s2, s3_lock, s4", repository);
            }
        }
コード例 #7
0
        public void DeleteLockedData()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve <Common.DomRepository>();

                var s1 = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s1"
                };
                var s2 = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s2"
                };
                var s3Lock = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s3_lock"
                };
                var s4 = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s4"
                };
                repository.TestLockItems.Simple.Insert(new[] { s1, s2, s3Lock, s4 });
                AssertData("s1, s2, s3_lock, s4", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Lock }), "Name contains lock mark.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s1, s3Lock }), "Name contains lock mark.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Lock, s4 }), "Name contains lock mark.");
                AssertData("s1, s2, s3_lock, s4", repository);

                repository.TestLockItems.Simple.Delete(new[] { s1 });
                AssertData("s2, s3_lock, s4", repository);
            }
        }
コード例 #8
0
        public void DeleteModifiedPersistentObject()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve <Common.DomRepository>();

                {
                    var s3Lock = new TestLockItems.Simple {
                        ID = Guid.NewGuid(), Name = "s3_lock"
                    };
                    repository.TestLockItems.Simple.Insert(new[] { s3Lock });

                    AssertData("s3_lock", repository);
                    container.Resolve <Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
                    AssertData("s3_lock", repository);
                }

                {
                    var s3Persistent = repository.TestLockItems.Simple.All().Single();
                    s3Persistent.Name = "abc";
                    TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Persistent }),
                                           "Name contains lock mark");

                    AssertData("s3_lock", repository);
                    container.Resolve <Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
                    AssertData("s3_lock", repository);
                }
            }
        }
コード例 #9
0
        public void UpdateLockedData()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve <Common.DomRepository>();

                var s1 = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s1", Count = -1
                };
                var s2 = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s2", Count = 1
                };

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

                foreach (var e in new[] { s1, s2 })
                {
                    e.Name = e.Name + "x";
                }
                AssertData("s1, s2", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1 }), "Name is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s2, s1 }), "Name is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1, s2 }), "Name is locked if count negative.");
                AssertData("s1, s2", repository);

                repository.TestLockItems.Simple.Update(new[] { s2 });
                AssertData("s1, s2x", repository);
            }
        }
コード例 #10
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);
            }
        }
コード例 #11
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());
                }
            }
        }
コード例 #12
0
ファイル: LockPropertyTest.cs プロジェクト: tjakopovic/Rhetos
        public void UpdateTryRemoveLock()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();

                var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1", Count = -1 };
                repository.TestLockItems.Simple.Insert(new[] { s1 });
                AssertData("s1", repository);

                s1.Name = "abc";
                s1.Count = 1;
                AssertData("s1", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1 }), "Name is locked if count negative.");
                AssertData("s1", repository);
            }
        }
コード例 #13
0
        public void UpdateTryRemoveLock()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve <Common.DomRepository>();

                var s3Lock = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s3_lock"
                };
                repository.TestLockItems.Simple.Insert(new[] { s3Lock });
                AssertData("s3_lock", repository);

                s3Lock.Name = "abc";
                AssertData("s3_lock", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock }), "Name contains lock mark.");
                AssertData("s3_lock", repository);
            }
        }
コード例 #14
0
        public void UpdateTryRemoveLock()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve <Common.DomRepository>();

                var s1 = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s1", Count = -1
                };
                repository.TestLockItems.Simple.Insert(new[] { s1 });
                AssertData("s1", repository);

                s1.Name  = "abc";
                s1.Count = 1;
                AssertData("s1", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1 }), "Name is locked if count negative.");
                AssertData("s1", repository);
            }
        }
コード例 #15
0
        public void UpdateTrySetLock()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve <Common.DomRepository>();

                var s1 = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s1", Count = 1
                };
                repository.TestLockItems.Simple.Insert(new[] { s1 });
                AssertData("s1", repository);

                s1.Name  = "abc";
                s1.Count = -1;
                AssertData("s1", repository);

                repository.TestLockItems.Simple.Update(new[] { s1 });
                AssertData("abc", repository);
            }
        }
コード例 #16
0
ファイル: LockItemsTest.cs プロジェクト: koav/Rhetos
        public void DeleteLockedData()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = new Common.DomRepository(executionContext);

                var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1" };
                var s2 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s2" };
                var s3Lock = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s3_lock" };
                var s4 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s4" };
                repository.TestLockItems.Simple.Insert(new[] { s1, s2, s3Lock, s4 });
                AssertData("s1, s2, s3_lock, s4", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Lock }), "Name contains lock mark.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s1, s3Lock }), "Name contains lock mark.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Lock, s4 }), "Name contains lock mark.");
                AssertData("s1, s2, s3_lock, s4", repository);

                repository.TestLockItems.Simple.Delete(new[] { s1 });
                AssertData("s2, s3_lock, s4", repository);
            }
        }
コード例 #17
0
        public void UpdateLockedData()
        {
            using (var scope = TestScope.Create())
            {
                scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = scope.Resolve <Common.DomRepository>();

                var s1 = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s1"
                };
                var s2 = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s2"
                };
                var s3Lock = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s3_lock"
                };
                var s4 = new TestLockItems.Simple {
                    ID = Guid.NewGuid(), Name = "s4"
                };
                repository.TestLockItems.Simple.Insert(new[] { s1, s2, s3Lock, s4 });
                AssertData("s1, s2, s3_lock, s4", repository);

                foreach (var e in new[] { s1, s2, s3Lock, s4 })
                {
                    e.Name = e.Name + "x";
                }
                AssertData("s1, s2, s3_lock, s4", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock }), "[Test] Name contains lock mark.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1, s3Lock }), "[Test] Name contains lock mark.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock, s4 }), "[Test] Name contains lock mark.");
                AssertData("s1, s2, s3_lock, s4", repository);

                repository.TestLockItems.Simple.Update(new[] { s1 });
                AssertData("s1x, s2, s3_lock, s4", repository);
            }
        }
コード例 #18
0
ファイル: LockPropertyTest.cs プロジェクト: tjakopovic/Rhetos
        public void UpdateTrySetLock()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();

                var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1", Count = 1 };
                repository.TestLockItems.Simple.Insert(new[] { s1 });
                AssertData("s1", repository);

                s1.Name = "abc";
                s1.Count = -1;
                AssertData("s1", repository);

                repository.TestLockItems.Simple.Update(new[] { s1 });
                AssertData("abc", repository);
            }
        }
コード例 #19
0
ファイル: LockPropertyTest.cs プロジェクト: tjakopovic/Rhetos
        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);
            }
        }
コード例 #20
0
ファイル: LockPropertyTest.cs プロジェクト: koav/Rhetos
        public void UpdateTrySetLock()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = new Common.DomRepository(executionContext);

                var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1", Count = 1 };
                repository.TestLockItems.Simple.Insert(new[] { s1 });
                AssertData("s1", repository);

                s1.Name = "abc";
                s1.Count = -1;
                AssertData("s1", repository);

                repository.TestLockItems.Simple.Update(new[] { s1 });
                AssertData("abc", repository);
            }
        }
コード例 #21
0
ファイル: LockPropertyTest.cs プロジェクト: koav/Rhetos
        public void UpdateTryRemoveLock()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = new Common.DomRepository(executionContext);

                var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1", Count = -1 };
                repository.TestLockItems.Simple.Insert(new[] { s1 });
                AssertData("s1", repository);

                s1.Name = "abc";
                s1.Count = 1;
                AssertData("s1", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1 }), "Name is locked if count negative.");
                AssertData("s1", repository);
            }
        }
コード例 #22
0
ファイル: LockItemsTest.cs プロジェクト: kmeze/Rhetos
        public void UpdateTryRemoveLock()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();

                var s3Lock = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s3_lock" };
                repository.TestLockItems.Simple.Insert(new[] { s3Lock });
                AssertData("s3_lock", repository);

                s3Lock.Name = "abc";
                AssertData("s3_lock", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock }), "Name contains lock mark.");
                AssertData("s3_lock", repository);
            }
        }
コード例 #23
0
ファイル: LockItemsTest.cs プロジェクト: kmeze/Rhetos
        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());
            }
        }
コード例 #24
0
ファイル: LockItemsTest.cs プロジェクト: kmeze/Rhetos
        public void Spike_EvictContains()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();

                var s = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "abc" };
                repository.TestLockItems.Simple.Insert(new[] { s });
                AssertData("abc", repository);
                Assert.IsFalse(container.Resolve<Common.ExecutionContext>().NHibernateSession.Contains(s));

                var s2 = repository.TestLockItems.Simple.All().Single();
                Assert.IsTrue(container.Resolve<Common.ExecutionContext>().NHibernateSession.Contains(s2));

                container.Resolve<Common.ExecutionContext>().NHibernateSession.Evict(s2);
                Assert.IsFalse(container.Resolve<Common.ExecutionContext>().NHibernateSession.Contains(s2));
            }
        }
コード例 #25
0
ファイル: LockItemsTest.cs プロジェクト: koav/Rhetos
        public void UpdateTryRemoveLock()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = new Common.DomRepository(executionContext);

                var s3Lock = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s3_lock" };
                repository.TestLockItems.Simple.Insert(new[] { s3Lock });
                AssertData("s3_lock", repository);

                s3Lock.Name = "abc";
                AssertData("s3_lock", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock }), "Name contains lock mark.");
                AssertData("s3_lock", repository);
            }
        }
コード例 #26
0
ファイル: LockItemsTest.cs プロジェクト: koav/Rhetos
        public void Spike_EvictContains()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = new Common.DomRepository(executionContext);

                var s = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "abc" };
                repository.TestLockItems.Simple.Insert(new[] { s });
                AssertData("abc", repository);
                Assert.IsFalse(executionContext.NHibernateSession.Contains(s));

                var s2 = repository.TestLockItems.Simple.All().Single();
                Assert.IsTrue(executionContext.NHibernateSession.Contains(s2));

                executionContext.NHibernateSession.Evict(s2);
                Assert.IsFalse(executionContext.NHibernateSession.Contains(s2));
            }
        }