Пример #1
0
        public void AutomaticallyDeleteExtensionWithBusinessLogic()
        {
            using (var container = new RhetosTestContainer())
            {
                var log = new List <string>();
                container.AddLogMonitor(log);
                var repository = container.Resolve <Common.DomRepository>();

                var baseItem = new TestDataStructure.SaveTesterBase {
                    Name = "b1"
                };
                repository.TestDataStructure.SaveTesterBase.Insert(baseItem);

                var extensionItem = new TestDataStructure.SaveTester {
                    ID = baseItem.ID, Name = "e1"
                };
                repository.TestDataStructure.SaveTester.Insert(extensionItem);

                Assert.AreEqual(1, repository.TestDataStructure.SaveTester.Query(new[] { extensionItem.ID }).Count()); // Just checking the test is not false positive.

                log.Clear();
                repository.TestDataStructure.SaveTesterBase.Delete(baseItem);

                Console.WriteLine("LOG BEGIN\r\n" + string.Join("\r\n", log) + "\r\nLOG END");

                Assert.AreEqual(0, repository.TestDataStructure.SaveTester.Query(new[] { extensionItem.ID }).Count()); // Just checking the test is not false positive.

                Assert.IsTrue(log.Any(entry => entry.Contains("SaveTester.Deletions: e1.")), "Deleting the base entity should result with deletion of the extension through the object model (not just deleted in database by cascade delete).");
            }
        }
Пример #2
0
        public void SaveMethodOldDataLoaded()
        {
            using (var container = new RhetosTestContainer())
            {
                var context = container.Resolve <Common.ExecutionContext>();

                var baseItem = new TestDataStructure.SaveTesterBase {
                    Name = "456"
                };
                context.Repository.TestDataStructure.SaveTesterBase.Insert(baseItem);

                var testItem = new TestDataStructure.SaveTester {
                    ID = baseItem.ID
                };
                context.Repository.TestDataStructure.SaveTester.Insert(testItem);

                TestUtility.ShouldFail <Rhetos.UserException>(
                    () => context.Repository.TestDataStructure.SaveTester.Delete(testItem),
                    "Cannot change locked base name 456");
            }
        }
Пример #3
0
        public void SaveMethodInitialization()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestDataStructure.SaveTesterBase" });

                var context = container.Resolve <Common.ExecutionContext>();

                var baseRepos   = context.Repository.TestDataStructure.SaveTesterBase;
                var testerRepos = context.Repository.TestDataStructure.SaveTester;

                var baseItem = new TestDataStructure.SaveTesterBase {
                    ID = Guid.NewGuid(), Name = "b0"
                };
                var testerItem = new TestDataStructure.SaveTester {
                    ID = baseItem.ID, Name = "default", Code = 11
                };

                baseRepos.Insert(baseItem);
                testerRepos.Insert(testerItem);

                Assert.AreEqual("b0/initialized-11", TestUtility.DumpSorted(testerRepos.Query(), item => item.Base.Name + "/" + item.Name + "-" + item.Code));
            }
        }
Пример #4
0
        public void SaveMethodInitialization()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestDataStructure.SaveTesterBase" });

                var context = container.Resolve<Common.ExecutionContext>();

                var baseRepos = context.Repository.TestDataStructure.SaveTesterBase;
                var testerRepos = context.Repository.TestDataStructure.SaveTester;

                var baseItem = new TestDataStructure.SaveTesterBase { ID = Guid.NewGuid(), Name = "b0" };
                var testerItem = new TestDataStructure.SaveTester { ID = baseItem.ID, Name = "default", Code = 11 };

                baseRepos.Insert(baseItem);
                testerRepos.Insert(testerItem);

                Assert.AreEqual("b0/initialized-11", TestUtility.DumpSorted(testerRepos.Query(), item => item.Base.Name + "/" + item.Name + "-" + item.Code));
            }
        }