Esempio n. 1
0
        public void ClonesSimpleBusinessLogic()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[]
                {
                    "DELETE FROM TestCloning.Source",
                    "DELETE FROM TestCloning.Parent",
                    "DELETE FROM TestCloning.Base"
                });
                var repository = container.Resolve <Common.DomRepository>();

                var b = new TestCloning.Base {
                    ID = Guid.NewGuid(), Name = "b"
                };
                var b2 = new TestCloning.Base {
                    ID = Guid.NewGuid(), Name = "b2"
                };
                var b3 = new TestCloning.Base {
                    ID = Guid.NewGuid(), Name = "b3"
                };
                var p = new TestCloning.Parent {
                    ID = Guid.NewGuid(), Name = "p"
                };
                var p2 = new TestCloning.Parent {
                    ID = Guid.NewGuid(), Name = "p2"
                };
                var p3 = new TestCloning.Parent {
                    ID = Guid.NewGuid(), Name = "p3"
                };
                var c = new TestCloning.Clone3 {
                    ID = b.ID, Name = "c", ParentID = p.ID
                };
                var c2 = new TestCloning.Clone3 {
                    ID = b2.ID, Name = "c2", ParentID = p2.ID
                };
                var c3 = new TestCloning.Clone3 {
                    ID = b3.ID, Name = "c3", ParentID = p3.ID
                };
                repository.TestCloning.Base.Insert(new[] { b, b2, b3 });
                repository.TestCloning.Parent.Insert(new[] { p, p2, p3 });
                repository.TestCloning.Clone3.Insert(new[] { c, c2, c3 });

                container.Resolve <Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
                Func <string> readClone3 = () => TestUtility.DumpSorted(repository.TestCloning.Clone3.Query()
                                                                        .Select(item => item.Name + " " + item.Base.Name + " " + item.Parent.Name));

                Assert.AreEqual("c b p, c2 b2 p2, c3 b3 p3", readClone3());

                repository.TestCloning.Base.Delete(new[] { b2 });
                repository.TestCloning.Parent.Delete(new[] { p3 });
                Assert.AreEqual("c b p", readClone3());

                c.Name = null;
                TestUtility.ShouldFail(() => repository.TestCloning.Clone3.Update(new[] { c }), "required", "Name");
            }
        }
Esempio n. 2
0
        public void ClonesSimpleBusinessLogic()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[]
                    {
                        "DELETE FROM TestCloning.Source",
                        "DELETE FROM TestCloning.Parent",
                        "DELETE FROM TestCloning.Base"
                    });
                var repository = container.Resolve<Common.DomRepository>();

                var b = new TestCloning.Base { ID = Guid.NewGuid(), Name = "b" };
                var b2 = new TestCloning.Base { ID = Guid.NewGuid(), Name = "b2" };
                var b3 = new TestCloning.Base { ID = Guid.NewGuid(), Name = "b3" };
                var p = new TestCloning.Parent { Name = "p" };
                var p2 = new TestCloning.Parent { Name = "p2" };
                var p3 = new TestCloning.Parent { Name = "p3" };
                var c = new TestCloning.Clone3 { ID = b.ID, Name = "c", Parent = p };
                var c2 = new TestCloning.Clone3 { ID = b2.ID, Name = "c2", Parent = p2 };
                var c3 = new TestCloning.Clone3 { ID = b3.ID, Name = "c3", Parent = p3 };
                repository.TestCloning.Base.Insert(new[] { b, b2, b3 });
                repository.TestCloning.Parent.Insert(new[] { p, p2, p3 });
                repository.TestCloning.Clone3.Insert(new[] { c, c2, c3 });

                container.Resolve<Common.ExecutionContext>().NHibernateSession.Clear();
                Func<string> readClone3 = () => TestUtility.DumpSorted(repository.TestCloning.Clone3.Query()
                        .Select(item => item.Name + " " + item.Base.Name + " " + item.Parent.Name));

                Assert.AreEqual("c b p, c2 b2 p2, c3 b3 p3", readClone3());

                repository.TestCloning.Base.Delete(new[] { b2 });
                repository.TestCloning.Parent.Delete(new[] { p3 });
                Assert.AreEqual("c b p", readClone3());

                c.Name = null;
                TestUtility.ShouldFail(() => repository.TestCloning.Clone3.Update(new[] { c }), "required", "Name");
            }
        }