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