Example #1
0
        public void SaveInvalidRecord_SystemUpdate()
        {
            using (var container = new RhetosTestContainer())
            {
                var repos = container.Resolve <Common.DomRepository>().TestEntity.Principal;

                var item1 = new TestEntity.Principal {
                    Name = "1", ID = Guid.NewGuid()
                };
                var item2 = new TestEntity.Principal {
                    Name = "2", ID = Guid.NewGuid()
                };
                var item3 = new TestEntity.Principal {
                    Name = "3", ID = Guid.NewGuid()
                };
                var item4 = new TestEntity.Principal {
                    Name = "4", ID = Guid.NewGuid()
                };

                repos.Insert(item1, item4);

                var error = TestUtility.ShouldFail <Rhetos.FrameworkException>(
                    () => repos.Save(null, new[] { item1, item2, item3, item4 }, null, checkUserPermissions: false),
                    "Updating a record that does not exist in database.");

                Assert.IsTrue(error.ToString().Contains(item2.ID.ToString()) || error.ToString().Contains(item3.ID.ToString()));
            }
        }
Example #2
0
        public void SaveInvalidRecord_Update()
        {
            using (var container = new RhetosTestContainer())
            {
                var repos = container.Resolve <Common.DomRepository>().TestEntity.Principal;

                var item1 = new TestEntity.Principal {
                    Name = "1", ID = Guid.NewGuid()
                };
                var item2 = new TestEntity.Principal {
                    Name = "2", ID = Guid.NewGuid()
                };
                var item3 = new TestEntity.Principal {
                    Name = "3", ID = Guid.NewGuid()
                };
                var item4 = new TestEntity.Principal {
                    Name = "4", ID = Guid.NewGuid()
                };

                repos.Insert(item1, item4);

                TestUtility.ShouldFail <Rhetos.ClientException>(
                    () => repos.Save(null, new[] { item1, item2, item3, item4 }, null, checkUserPermissions: true),
                    "Updating a record that does not exist in database.");
            }
        }
Example #3
0
        public void SaveInvalidRecord_SystemUpdate()
        {
            using (var scope = TestScope.Create())
            {
                var repos = scope.Resolve <Common.DomRepository>().TestEntity.Principal;

                var item1 = new TestEntity.Principal {
                    Name = "1", ID = Guid.NewGuid()
                };
                var item2 = new TestEntity.Principal {
                    Name = "2", ID = Guid.NewGuid()
                };
                var item3 = new TestEntity.Principal {
                    Name = "3", ID = Guid.NewGuid()
                };
                var item4 = new TestEntity.Principal {
                    Name = "4", ID = Guid.NewGuid()
                };

                repos.Insert(item1, item4);

                TestUtility.ShouldFail <Rhetos.FrameworkException>(
                    () => repos.Save(null, new[] { item1, item2, item3, item4 }, null, checkUserPermissions: false),
                    "Updating a record that does not exist in database.");
            }
        }
Example #4
0
        public void SaveInvalidRecord_Delete()
        {
            using (var container = new RhetosTestContainer())
            {
                var repos = container.Resolve <Common.DomRepository>().TestEntity.Principal;

                var item = new TestEntity.Principal {
                    Name = "a", ID = Guid.NewGuid()
                };
                TestUtility.ShouldFail <Rhetos.ClientException>(() => repos.Save(null, null, new[] { item }, checkUserPermissions: true),
                                                                "Deleting a record that does not exist in database.", item.ID.ToString());
            }
        }
Example #5
0
        public void SaveInvalidRecordMultiple_Insert()
        {
            using (var container = new RhetosTestContainer())
            {
                var repos = container.Resolve <Common.DomRepository>().TestEntity.Principal;

                var item1 = new TestEntity.Principal {
                    Name = "a", ID = Guid.NewGuid()
                };
                var item2 = new TestEntity.Principal {
                    Name = "b", ID = item1.ID
                };
                TestUtility.ShouldFail <Rhetos.ClientException>(() => repos.Save(new[] { item1, item2 }, null, null, checkUserPermissions: true),
                                                                "Inserting a record that already exists in database.", item2.ID.ToString());
            }
        }
Example #6
0
        public void SaveInvalidRecord_UpdateKnownId()
        {
            using (var scope = TestScope.Create())
            {
                var repos = scope.Resolve <Common.DomRepository>().TestEntity.Principal;

                var item1 = new TestEntity.Principal {
                    Name = "1", ID = Guid.NewGuid()
                };

                var error = TestUtility.ShouldFail <Rhetos.ClientException>(
                    () => repos.Save(null, new[] { item1 }, null, checkUserPermissions: true),
                    "Updating a record that does not exist in database.");

                Assert.IsTrue(error.Message.Contains(item1.ID.ToString()));
            }
        }
Example #7
0
        public void SaveInvalidRecord_SystemInsert()
        {
            using (var container = new RhetosTestContainer())
            {
                var repos = container.Resolve <Common.DomRepository>().TestEntity.Principal;

                var item1 = new TestEntity.Principal {
                    Name = "a", ID = Guid.NewGuid()
                };
                repos.Insert(item1);

                var item2 = new TestEntity.Principal {
                    Name = "b", ID = item1.ID
                };
                var error = TestUtility.ShouldFail <Rhetos.FrameworkException>(() => repos.Save(new[] { item2 }, null, null, checkUserPermissions: false));
                TestUtility.AssertContains(error.ToString(), new[] { "Inserting a record that already exists in database.", item2.ID.ToString(), "PK_Principal" });
            }
        }
Example #8
0
        public void SaveDuplicate()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestEntity.Principal" });
                var r = container.Resolve <Common.DomRepository>().TestEntity.Principal;

                var i1 = new TestEntity.Principal {
                    Name = "a", ID = Guid.NewGuid()
                };
                var i2 = new TestEntity.Principal {
                    Name = "b", ID = i1.ID
                };

                r.Insert(new[] { i1 });
                TestUtility.ShouldFail(() => r.Insert(new[] { i2 }), "Inserting a record that already exists");
            }
        }
Example #9
0
        public void SaveInvalidRecordMultiple_InsertDelete()
        {
            using (var container = new RhetosTestContainer())
            {
                var repos = container.Resolve <Common.DomRepository>().TestEntity.Principal;

                var item1 = new TestEntity.Principal {
                    Name = "a", ID = Guid.NewGuid()
                };
                repos.Insert(item1);
                Assert.AreEqual("a", repos.Query(new[] { item1.ID }).Single().Name);

                var item2 = new TestEntity.Principal {
                    Name = "b", ID = item1.ID
                };
                repos.Save(new[] { item2 }, null, new[] { item1 }, checkUserPermissions: true);
                Assert.AreEqual("b", repos.Query(new[] { item1.ID }).Single().Name);
            }
        }
Example #10
0
        public void ShortStringPropertyBasicRhetosTypeValidation()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql("DELETE FROM TestEntity.Principal");
                var repository = container.Resolve <Common.DomRepository>();

                TestEntity.Principal item = new TestEntity.Principal();
                item.Name = new string('x', 256);
                repository.TestEntity.Principal.Insert(item);

                TestUtility.ShouldFail(
                    () =>
                {
                    item.Name = new string('x', 257);
                    repository.TestEntity.Principal.Update(item);
                },
                    "Principal", "Name", "256");
            }
        }
Example #11
0
        public void ShortStringPropertyBasicRhetosTypeValidation()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestEntity.Principal" });
                var repository = container.Resolve<Common.DomRepository>();

                TestEntity.Principal item = new TestEntity.Principal();
                item.Name = new string('x', 256);
                repository.TestEntity.Principal.Insert(new[] { item });

                TestUtility.ShouldFail(
                    () =>
                    {
                        item.Name = new string('x', 257);
                        repository.TestEntity.Principal.Update(new[] { item });
                    },
                    "Principal", "Name", "256");
            }
        }
Example #12
0
        public void SaveDuplicate()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestEntity.Principal" });
                var r = container.Resolve<Common.DomRepository>().TestEntity.Principal;

                var i1 = new TestEntity.Principal { Name = "a", ID = Guid.NewGuid() };
                var i2 = new TestEntity.Principal { Name = "b", ID = i1.ID };

                r.Insert(new[] { i1 });
                TestUtility.ShouldFail(() => r.Insert(new[] { i2 }), "Inserting a record that already exists");
            }
        }
Example #13
0
        public void ShortStringPropertyBasicRhetosTypeValidation()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestEntity.Principal" });
                var repository = new Common.DomRepository(executionContext);

                TestEntity.Principal item = new TestEntity.Principal();
                item.Name = new string('x', 256);
                repository.TestEntity.Principal.Insert(new[] { item });

                TestUtility.ShouldFail(
                    () =>
                    {
                        item.Name = new string('x', 257);
                        repository.TestEntity.Principal.Update(new[] { item });
                    },
                    "Principal", "Name", "256");
            }
        }