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); } }
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); } } }
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); } } }
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); } }
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); } }
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); } }
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); } }
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); } } }
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); } }
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); } }
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()); } } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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()); } }
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)); } }
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); } }
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)); } }