public void Dependant_FKConstraintDeleteUniqueReferenced() { using (var container = new RhetosTestContainer()) { var repository = container.Resolve <Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { Name = "s1", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var d1 = new TestPolymorphic.DependantUniqueReference { Name = "d1", ID = s1.ID }; repository.TestPolymorphic.DependantUniqueReference.Insert(new[] { d1 }); Assert.AreEqual("s1-d1", TestUtility.DumpSorted( repository.TestPolymorphic.SimpleBase.Query(new[] { d1.ID }), item => item.Name + "-" + item.Extension_DependantUniqueReference.Name)); var ex = TestUtility.ShouldFail <Rhetos.UserException>( () => repository.TestPolymorphic.Simple1.Delete(new[] { s1 }), "It is not allowed to delete"); TestUtility.AssertContains(ex.ToString(), new[] { "DependantUniqueReference", "REFERENCE", "SimpleBase" }, "Expected inner SQL exception"); } }
public void CascadeDeleteExtension() { using (var container = new RhetosTestContainer()) { var repository = container.Resolve <Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { Name = "s1", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var d1 = new TestPolymorphic.DependantExtension { Name = "d1", ID = s1.ID }; repository.TestPolymorphic.DependantExtension.Insert(new[] { d1 }); Assert.AreEqual("s1-d1", TestUtility.DumpSorted( repository.TestPolymorphic.DependantExtension.Query(new[] { d1.ID }).ToList(), item => item.Base.Name + "-" + item.Name)); repository.TestPolymorphic.Simple1.Delete(new[] { s1 }); Assert.AreEqual("", TestUtility.DumpSorted( repository.TestPolymorphic.DependantExtension.Query(new[] { d1.ID }).ToList(), item => item.Base.Name + "-" + item.Name)); } }
public void Dependant_FKConstraintDelete() { using (var container = new RhetosTestContainer()) { var repository = container.Resolve <Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { ID = Guid.NewGuid(), Name = "a", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var dep = new TestPolymorphic.Dependant { ID = Guid.NewGuid(), Name = "dep", SimpleBaseID = s1.ID }; repository.TestPolymorphic.Dependant.Insert(new[] { dep }); Assert.AreEqual("dep-a", TestUtility.DumpSorted( repository.TestPolymorphic.DependantBrowse.Query(new[] { dep.ID }), item => item.Name + "-" + item.SimpleBaseName)); var ex = TestUtility.ShouldFail <Rhetos.UserException>( () => repository.TestPolymorphic.Simple1.Delete(new[] { s1 }), "It is not allowed to delete"); TestUtility.AssertContains(ex.ToString(), new[] { "Dependant", "REFERENCE", "SimpleBase" }, "Expected inner SQL exception"); } }
public void Dependant_FKConstraintInsert() { using (var container = new RhetosTestContainer()) { var repository = container.Resolve <Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { Name = "a", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var dep = new TestPolymorphic.Dependant { Name = "dep", SimpleBaseID = s1.ID }; repository.TestPolymorphic.Dependant.Insert(new[] { dep }); var depInvalidReference = new TestPolymorphic.Dependant { Name = "depInvalidReference", SimpleBaseID = Guid.NewGuid() }; var ex = TestUtility.ShouldFail <Rhetos.UserException>( () => repository.TestPolymorphic.Dependant.Insert(new[] { depInvalidReference }), "It is not allowed to enter the record."); TestUtility.AssertContains(ex.ToString(), new[] { "Dependant", "FOREIGN KEY", "SimpleBase" }, "Expected inner SQL exception"); } }
public void CascadeDeleteDetail() { using (var scope = TestScope.Create()) { var repository = scope.Resolve <Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { Name = "s1", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var d1 = new TestPolymorphic.DependantDetail { Name = "d1", SimpleBaseID = s1.ID }; repository.TestPolymorphic.DependantDetail.Insert(new[] { d1 }); Assert.AreEqual("s1-d1", TestUtility.DumpSorted( repository.TestPolymorphic.DependantDetail.Query(new[] { d1.ID }).ToList(), item => item.SimpleBase.Name + "-" + item.Name)); repository.TestPolymorphic.Simple1.Delete(new[] { s1 }); Assert.AreEqual("", TestUtility.DumpSorted( repository.TestPolymorphic.DependantDetail.Query(new[] { d1.ID }).ToList(), item => item.SimpleBase.Name + "-" + item.Name)); } }
public void Dependant_FKConstraintInsert() { using (var container = new RhetosTestContainer()) { var repository = container.Resolve<Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { ID = Guid.NewGuid(), Name = "a", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var dep = new TestPolymorphic.Dependant { ID = Guid.NewGuid(), Name = "dep", SimpleBaseID = s1.ID }; repository.TestPolymorphic.Dependant.Insert(new[] { dep }); var depInvalidReference = new TestPolymorphic.Dependant { ID = Guid.NewGuid(), Name = "depInvalidReference", SimpleBaseID = Guid.NewGuid() }; TestUtility.ShouldFail( () => repository.TestPolymorphic.Dependant.Insert(new[] { depInvalidReference }), "Dependant", "FOREIGN KEY", "SimpleBase"); } }
public void Dependant_FKConstraintDelete() { using (var container = new RhetosTestContainer()) { var repository = container.Resolve<Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { ID = Guid.NewGuid(), Name = "a", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var dep = new TestPolymorphic.Dependant { ID = Guid.NewGuid(), Name = "dep", SimpleBaseID = s1.ID }; repository.TestPolymorphic.Dependant.Insert(new[] { dep }); Assert.AreEqual("dep-a", TestUtility.DumpSorted( repository.TestPolymorphic.DependantBrowse.Filter(new[] { dep.ID }), item => item.Name + "-" + item.SimpleBaseName)); TestUtility.ShouldFail( () => repository.TestPolymorphic.Simple1.Delete(new[] { s1 }), "Dependant", "REFERENCE", "SimpleBase"); } }
public void Dependant_FKConstraintDelete() { using (var container = new RhetosTestContainer()) { var repository = container.Resolve<Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { ID = Guid.NewGuid(), Name = "a", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var dep = new TestPolymorphic.Dependant { ID = Guid.NewGuid(), Name = "dep", SimpleBaseID = s1.ID }; repository.TestPolymorphic.Dependant.Insert(new[] { dep }); Assert.AreEqual("dep-a", TestUtility.DumpSorted( repository.TestPolymorphic.DependantBrowse.Query(new[] { dep.ID }), item => item.Name + "-" + item.SimpleBaseName)); var ex = TestUtility.ShouldFail<Rhetos.UserException>( () => repository.TestPolymorphic.Simple1.Delete(new[] { s1 }), "It is not allowed to delete"); TestUtility.AssertContains(ex.ToString(), new[] { "Dependant", "REFERENCE", "SimpleBase" }, "Expected inner SQL exception"); } }
public void Dependant_FKConstraintUpdate() { using (var container = new RhetosTestContainer()) { var repository = container.Resolve <Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { ID = Guid.NewGuid(), Name = "a", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var dep = new TestPolymorphic.Dependant { ID = Guid.NewGuid(), Name = "dep", SimpleBaseID = s1.ID }; repository.TestPolymorphic.Dependant.Insert(new[] { dep }); dep.SimpleBaseID = Guid.NewGuid(); TestUtility.ShouldFail( () => repository.TestPolymorphic.Dependant.Update(new[] { dep }), "Dependant", "FOREIGN KEY", "SimpleBase"); } }
public void Dependant_FKConstraintDelete() { using (var container = new RhetosTestContainer()) { var repository = container.Resolve <Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { ID = Guid.NewGuid(), Name = "a", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var dep = new TestPolymorphic.Dependant { ID = Guid.NewGuid(), Name = "dep", SimpleBaseID = s1.ID }; repository.TestPolymorphic.Dependant.Insert(new[] { dep }); Assert.AreEqual("dep-a", TestUtility.DumpSorted( repository.TestPolymorphic.DependantBrowse.Filter(new[] { dep.ID }), item => item.Name + "-" + item.SimpleBaseName)); TestUtility.ShouldFail( () => repository.TestPolymorphic.Simple1.Delete(new[] { s1 }), "Dependant", "REFERENCE", "SimpleBase"); } }
public void Dependant_FKConstraintInsert() { using (var container = new RhetosTestContainer()) { var repository = container.Resolve<Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { ID = Guid.NewGuid(), Name = "a", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var dep = new TestPolymorphic.Dependant { ID = Guid.NewGuid(), Name = "dep", SimpleBaseID = s1.ID }; repository.TestPolymorphic.Dependant.Insert(new[] { dep }); var depInvalidReference = new TestPolymorphic.Dependant { ID = Guid.NewGuid(), Name = "depInvalidReference", SimpleBaseID = Guid.NewGuid() }; var ex = TestUtility.ShouldFail<Rhetos.UserException>( () => repository.TestPolymorphic.Dependant.Insert(new[] { depInvalidReference }), "It is not allowed to enter the record."); TestUtility.AssertContains(ex.ToString(), new[] { "Dependant", "FOREIGN KEY", "SimpleBase" }, "Expected inner SQL exception"); } }