Пример #1
0
        public void CreatedIndexes()
        {
            using (var container = new RhetosTestContainer())
            {
                var sql = @"SELECT
                        i.name + '.' + c.name
                    FROM
                        sys.indexes i
                        INNER JOIN sys.index_columns ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
                        INNER JOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
                    WHERE
                        c.object_id IN (OBJECT_ID('TestCloning.Clone1'), OBJECT_ID('TestCloning.Clone2'), OBJECT_ID('TestCloning.Clone3'))
                    ORDER BY
                        i.name, ic.key_ordinal";

                string[] expected =
                    ("IX_Clone2_Parent.ParentID IX_Clone2_Start_Parent.Start IX_Clone2_Start_Parent.ParentID"
                    + " IX_Clone3_Code.Code IX_Clone3_Parent.ParentID IX_Clone3_Start_Parent.Start"
                    + " IX_Clone3_Start_Parent.ParentID PK_Clone1.ID PK_Clone2.ID PK_Clone3.ID").Split(' ');

                var actual = new List<string>();
                container.Resolve<ISqlExecuter>().ExecuteReader(sql, reader => actual.Add(reader.GetString(0)));

                Assert.AreEqual(TestUtility.DumpSorted(expected), TestUtility.DumpSorted(actual));
            }
        }
Пример #2
0
        public void ActivePropertyValueDoesNotHaveToBeDefinedOnUpdate()
        {
            using (var container = new RhetosTestContainer())
            {
                var id1 = Guid.NewGuid();
                var id2 = Guid.NewGuid();
                var id3 = Guid.NewGuid();
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] {
                    "DELETE FROM TestDeactivatable.BasicEnt",
                    "INSERT INTO TestDeactivatable.BasicEnt (ID, Name) VALUES (" + SqlUtility.QuoteGuid(id1) + ", 'a')",
                    "INSERT INTO TestDeactivatable.BasicEnt (ID, Name, Active) VALUES (" + SqlUtility.QuoteGuid(id2) + ", 'b', 0)",
                    "INSERT INTO TestDeactivatable.BasicEnt (ID, Name) VALUES (" + SqlUtility.QuoteGuid(id3) + ", 'c')"
                });
                var repository = container.Resolve<Common.DomRepository>();
                var e1 = new BasicEnt { ID = id1, Name = "a2", Active = false };
                var e2 = new BasicEnt { ID = id2, Name = "b2" };
                var e3 = new BasicEnt { ID = id3, Name = "c2" };
                repository.TestDeactivatable.BasicEnt.Update(new[] { e1, e2, e3});

                var afterUpdate = repository.TestDeactivatable.BasicEnt.All();
                Assert.AreEqual(
                    "a2 False, b2 False, c2 True",
                    TestUtility.DumpSorted(afterUpdate, item => item.Name + " " + item.Active));
            }
        }
Пример #3
0
        public void CreatedColumns()
        {
            using (var container = new RhetosTestContainer())
            {
                var sql = @"SELECT
                        OBJECT_NAME(object_id) + '.' + name
                    FROM
                        sys.columns
                    WHERE
                        object_id IN (OBJECT_ID('TestCloning.Clone1'), OBJECT_ID('TestCloning.Clone2'), OBJECT_ID('TestCloning.Clone3'))
                    ORDER BY
                        1";

                var expected =
@"Clone1.ID
Clone1.Start
Clone2.ID
Clone2.Name
Clone2.ParentID
Clone2.Start
Clone3.Code
Clone3.ID
Clone3.Name
Clone3.ParentID
Clone3.Start
";
                var actual = new StringBuilder();
                container.Resolve<ISqlExecuter>().ExecuteReader(sql, reader => actual.AppendLine(reader.GetString(0)));

                Assert.AreEqual(expected, actual.ToString());
            }
        }
Пример #4
0
        public void NonEditablePropertyUpdate()
        {
            using (var container = new RhetosTestContainer())
            {
                var simpleID = Guid.NewGuid();
                container.Resolve<ISqlExecuter>().ExecuteSql(new[]
                    {
                        "DELETE FROM TestDenyUserEdit.Simple",
                        "DELETE FROM TestDenyUserEdit.Parent",
                        "INSERT INTO TestDenyUserEdit.Simple (ID, Editable, NonEditable) VALUES (" + SqlUtility.QuoteGuid(simpleID) + ", 'a', 'x')"
                    });

                var repository = container.Resolve<Common.DomRepository>();

                Assert.AreEqual("a x null", DumpSimple(repository));

                var simple = new TestDenyUserEdit.Simple { ID = simpleID, Editable = "b", NonEditable = "x" };
                repository.TestDenyUserEdit.Simple.Save(null, new[] { simple }, null, true);
                Assert.AreEqual("b x null", DumpSimple(repository));

                simple.NonEditable = "y";
                TestUtility.ShouldFail(() => repository.TestDenyUserEdit.Simple.Save(null, new[] { simple }, null, true),
                    "Simple", "NonEditable", "not allowed");
            }
        }
Пример #5
0
        public void LazyLoadReferenceBaseExtensionLinkedItems()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve<Common.DomRepository>();
                repository.TestLazyLoad.Simple.Delete(repository.TestLazyLoad.Simple.Load());
                repository.TestLazyLoad.SimpleBase.Delete(repository.TestLazyLoad.SimpleBase.Load());
                repository.TestLazyLoad.Parent.Delete(repository.TestLazyLoad.Parent.Load());

                var p1 = new TestLazyLoad.Parent { ID = Guid.NewGuid(), Name = "p1" };
                repository.TestLazyLoad.Parent.Insert(p1);

                var sb1 = new TestLazyLoad.SimpleBase { ID = Guid.NewGuid(), Name = "sb1" };
                var sb2 = new TestLazyLoad.SimpleBase { ID = Guid.NewGuid(), Name = "sb2" };
                repository.TestLazyLoad.SimpleBase.Insert(sb1, sb2);

                var s1 = new TestLazyLoad.Simple { ID = sb1.ID, ParentID = p1.ID };
                var s2 = new TestLazyLoad.Simple { ID = sb2.ID, ParentID = p1.ID };
                repository.TestLazyLoad.Simple.Insert(s1, s2);

                container.Resolve<IPersistenceCache>().ClearCache();
                var loadedSimple = repository.TestLazyLoad.Simple.Query().ToList();
                Assert.AreEqual("p1/sb1, p1/sb2", TestUtility.DumpSorted(loadedSimple, item => item.Parent.Name + "/" + item.Base.Name));

                container.Resolve<IPersistenceCache>().ClearCache();
                var loadedBase = repository.TestLazyLoad.SimpleBase.Query().ToList();
                Assert.AreEqual("p1/sb1, p1/sb2", TestUtility.DumpSorted(loadedBase, item => item.Extension_Simple.Parent.Name + "/" + item.Name));

                container.Resolve<IPersistenceCache>().ClearCache();
                var loadedParent = repository.TestLazyLoad.Parent.Query().ToList().Single();
                Assert.AreEqual("p1/sb1, p1/sb2", TestUtility.DumpSorted(loadedParent.Children, item => item.Parent.Name + "/" + item.Base.Name));
            }
        }
Пример #6
0
        public void SqlObject()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[]
                {
                    "DELETE FROM TestSqlWorkarounds.E",
                    "INSERT INTO TestSqlWorkarounds.E (I) VALUES (100)"
                });

                string report = "";
                container.Resolve<ISqlExecuter>().ExecuteReader(
                    @"SELECT E.I, V1.I1, V2.I2
                        FROM TestSqlWorkarounds.E
                        INNER JOIN TestSqlWorkarounds.V1 ON V1.ID = E.ID
                        INNER JOIN TestSqlWorkarounds.V2 ON V2.ID = E.ID",
                    reader => report += reader.GetInt32(0) + ", " + reader.GetInt32(1) + ", " + reader.GetInt32(2) + ".");
                Assert.AreEqual("100, 101, 102.", report);

                report = "";
                container.Resolve<ISqlExecuter>().ExecuteReader(
                    @"SELECT X FROM TestSqlWorkarounds.V3 ORDER BY X",
                    reader => report += reader.GetInt32(0) + ".");
                Assert.AreEqual("101.102.", report);
            }
        }
Пример #7
0
        public void UpdateLockedData()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();

                var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1", Count = -1 };
                var s2 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s2", Count = 1 };

                repository.TestLockItems.Simple.Insert(new[] { s1, s2 });
                AssertData("s1, s2", repository);

                foreach (var e in new[] { s1, s2 })
                    e.Name = e.Name + "x";
                AssertData("s1, s2", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1 }), "Name is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s2, s1 }), "Name is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1, s2 }), "Name is locked if count negative.");
                AssertData("s1, s2", repository);

                repository.TestLockItems.Simple.Update(new[] { s2 });
                AssertData("s1, s2x", repository);
            }
        }
Пример #8
0
        public void NullReference()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve<Common.DomRepository>();

                Guid refID = Guid.NewGuid();
                container.Resolve<ISqlExecuter>().ExecuteSql(new[]
                    {
                        "DELETE FROM TestBrowse.Source;",
                        "DELETE FROM TestBrowse.Other;",
                        "INSERT INTO TestBrowse.Other (ID, Name) SELECT '" + refID + "', 'abc';",
                        "INSERT INTO TestBrowse.Source (RefID) SELECT NULL;"
                    });

                Assert.IsNull(repository.TestBrowse.Source.Query().ToArray().Select(item => item.Ref != null ? item.Ref.Name : null).Single(), "separated loading with null checking");
                Assert.IsNull(repository.TestBrowse.Source.Query().Select(item => item.Ref != null ? item.Ref.Name : null).Single(), "all in one query with null checking");

                Assert.IsNull(repository.TestBrowse.Source.Query().Select(item => item.Ref.Name).Single(), "all in one query");

                // TODO: "'Separated loading' fails because LINQ2NH will handle nullable properies and null values differently than a simple LINQ query over materialized instances (Linq2Objects). Try to implement browse in a such way that it behaves the same in both scenarios without degrading performance (maybe generating SqlView).
            
                Assert.IsNull(repository.TestBrowse.Source.Query().ToArray().Select(item => item.Ref.Name).Single(), "separated loading");
            }
        }
Пример #9
0
        public void LeavePredefinedUser()
        {
            using (var container = new RhetosTestContainer())
            {
                var genericRepositories = container.Resolve<GenericRepositories>();
                var repository = container.Resolve<Common.DomRepository>();

                string currentUserName = container.Resolve<IUserInfo>().UserName;
                Assert.IsTrue(!string.IsNullOrWhiteSpace(currentUserName));
                var currentPrincipal = new Common.Principal { Name = currentUserName };
                genericRepositories.InsertOrReadId(currentPrincipal, p => p.Name);

                string otherUserName = "******" + Guid.NewGuid();
                var otherPrincipal = new Common.Principal { Name = otherUserName };
                genericRepositories.InsertOrReadId(otherPrincipal, p => p.Name);

                var testItem1 = new TestCreatedBy.Simple { ID = Guid.NewGuid(), Name = "test1", AuthorID = otherPrincipal.ID };
                var testItem2 = new TestCreatedBy.Simple { ID = Guid.NewGuid(), Name = "test2" };
                repository.TestCreatedBy.Simple.Insert(testItem1, testItem2);

                Assert.AreEqual(
                    "test1 " + otherUserName + ", test2 " + currentUserName,
                    TestUtility.DumpSorted(repository.TestCreatedBy.Simple
                        .Query(new[] { testItem1.ID, testItem2.ID })
                        .Select(item => item.Name + " " + item.Author.Name)));
            }
        }
Пример #10
0
        public void QueryComplex()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve<Common.DomRepository>();

                container.Resolve<ISqlExecuter>().ExecuteSql(new[]
                    {
                        "DELETE FROM TestEntity.Permission",
                        "DELETE FROM TestEntity.Principal",
                        "DELETE FROM TestEntity.Claim",
                        "INSERT INTO TestEntity.Claim (ID, ClaimResource, ClaimRight) SELECT '4074B807-FA5A-4772-9631-198E89A302DE', 'res1', 'rig1'",
                        "INSERT INTO TestEntity.Claim (ID, ClaimResource, ClaimRight) SELECT 'A45F7194-7288-4B25-BC77-4FCC920A1479', 'res2', 'rig2'",
                        "INSERT INTO TestEntity.Principal (ID, Name) SELECT 'A45F7194-7288-4B25-BC77-4FCC920A1479', 'p1'",
                        "INSERT INTO TestEntity.Permission (ID, PrincipalID, ClaimID, IsAuthorized) SELECT '65D4B68E-B0E7-491C-9405-800F531866CA', 'A45F7194-7288-4B25-BC77-4FCC920A1479', '4074B807-FA5A-4772-9631-198E89A302DE', 0",
                        "INSERT INTO TestEntity.Permission (ID, PrincipalID, ClaimID, IsAuthorized) SELECT 'B7F19BA7-C70F-46ED-BFC7-29A44DFECA9B', 'A45F7194-7288-4B25-BC77-4FCC920A1479', 'A45F7194-7288-4B25-BC77-4FCC920A1479', 1"
                    });

                var q1 = repository.TestEntity.Principal.Query();
                var q2 = repository.TestEntity.Permission.Query();
                var loaded =
                    from principal in q1
                    from permission in q2
                    where principal.Name == "p1" && permission.Principal == principal && permission.IsAuthorized.Value
                    select permission.Claim.ClaimResource + "." + permission.Claim.ClaimRight;

                Assert.AreEqual("res2.rig2", loaded.Single());
            }
        }
Пример #11
0
        public void SearchOnIndexTable()
        {
            Assert.IsTrue(dataPrepared.Value);

            using (var container = new RhetosTestContainer(false))
            {
                var tests = new Dictionary<string, string>
                {
                    { "\"ab*\"", "ab, abc, cd ab" },
                    { "\"12*\"", "123, ab, xy" },
                    { "a'b", "" },
                    { "a'#'b", "" },
                };

                var repository = container.Resolve<Common.DomRepository>();

                foreach (var test in tests)
                {
                    Console.WriteLine("Searching '" + test.Key + "'");

                    var filtered = repository.TestFullTextSearch.Simple_Search.Query()
                        .Where(item => DatabaseExtensionFunctions.FullTextSearch(item.ID, test.Key, "TestFullTextSearch.Simple_Search", "*"))
                        .Select(item => item.Base.Name).ToList();
                    Assert.AreEqual(test.Value, TestUtility.DumpSorted(filtered), "Searching '" + test.Key + "'.");

                    filtered = repository.TestFullTextSearch.Simple_Search.Query()
                        .Where(item => DatabaseExtensionFunctions.FullTextSearch(item.ID, test.Key, "TestFullTextSearch.Simple_Search", "Text"))
                        .Select(item => item.Base.Name).ToList();
                    Assert.AreEqual(test.Value, TestUtility.DumpSorted(filtered), "Searching '" + test.Key + "'.");
                }
            }
        }
Пример #12
0
        public void PersistPartial()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestComputedFrom.PersistPartial" });
                var repository = container.Resolve<Common.DomRepository>();

                Assert.AreEqual("", TestUtility.DumpSorted(repository.TestComputedFrom.PersistPartial.All(), Dump));

                repository.TestComputedFrom.PersistPartial.RecomputeFromSource(new Rhetos.Dom.DefaultConcepts.FilterAll(), items => items.Where(item => item.Name == "aa"));
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
                Assert.AreEqual("aa", TestUtility.DumpSorted(repository.TestComputedFrom.PersistPartial.All(), Dump), "recompute all with SaveFilter to sync only Name aa ");

                repository.TestComputedFrom.PersistPartial.RecomputeFromSource();
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
                Assert.AreEqual("aa, bb", TestUtility.DumpSorted(repository.TestComputedFrom.PersistPartial.All(), Dump), "recompute all");

                repository.TestComputedFrom.PersistPartial.Delete(repository.TestComputedFrom.PersistPartial.All());
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                repository.TestComputedFrom.PersistPartial.RecomputeFromSource(new[] { repository.TestComputedFrom.Source.All().Where(item => item.Name == "bb").Single().ID });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
                Assert.AreEqual("bb", TestUtility.DumpSorted(repository.TestComputedFrom.PersistPartial.All(), Dump), "recompute by ID (name bb)");
            }
        }
Пример #13
0
        static string ReportLegacy2(RhetosTestContainer container, Common.DomRepository domRepository)
        {
            container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

            var loaded = domRepository.Test13.Legacy2.Query().Select(l2 => l2.Leg1.Name + " " + l2.NameNew + " " + l2.Same);
            return string.Join(", ", loaded.OrderBy(x => x));
        }
Пример #14
0
        public void AutoInherit()
        {
            using (var container = new RhetosTestContainer())
            {
                var names = new[] { "1", "1b", "2", "3", "4" };
                var itemsE4 = names.Select(name => new TestRowPermissions4.E4 { ID = Guid.NewGuid(), Name4 = name }).ToList();
                var itemsE3 = names.Select((name, x) => new TestRowPermissions3.E3 { ID = Guid.NewGuid(), Name3 = name, E4 = itemsE4[x] }).ToList();
                var itemsE2 = names.Select((name, x) => new TestRowPermissions2.E2 { ID = Guid.NewGuid(), Name2 = name, E3 = itemsE3[x] }).ToList();
                var itemsE1 = names.Select((name, x) => new TestRowPermissions1.E1 { ID = Guid.NewGuid(), Name1 = name, E2 = itemsE2[x] }).ToList();

                var reposE1 = container.Resolve<GenericRepository<TestRowPermissions1.E1>>();
                var reposE1Browse = container.Resolve<GenericRepository<TestRowPermissions1.E1Browse>>();
                var reposE1BrowseRP = container.Resolve<GenericRepository<TestRowPermissions1.E1BrowseRP>>();
                var reposE2 = container.Resolve<GenericRepository<TestRowPermissions2.E2>>();
                var reposE3 = container.Resolve<GenericRepository<TestRowPermissions3.E3>>();
                var reposE4 = container.Resolve<GenericRepository<TestRowPermissions4.E4>>();

                reposE4.Save(itemsE4, null, reposE4.Read());
                reposE3.Save(itemsE3, null, reposE3.Read());
                reposE2.Save(itemsE2, null, reposE2.Read());
                reposE1.Save(itemsE1, null, reposE1.Read());

                Assert.AreEqual("4", TestUtility.DumpSorted(reposE4.Read<Common.RowPermissionsReadItems>(), item => item.Name4));
                Assert.AreEqual("3->3", TestUtility.DumpSorted(reposE3.Read<Common.RowPermissionsReadItems>(), item => item.Name3 + "->" + item.E4.Name4));
                Assert.AreEqual("2, 3", TestUtility.DumpSorted(reposE2.Read<Common.RowPermissionsReadItems>(), item => item.Name2));
                Assert.AreEqual("1, 2, 3", TestUtility.DumpSorted(reposE1.Read<Common.RowPermissionsReadItems>(), item => item.Name1));
                Assert.AreEqual("1, 2, 3", TestUtility.DumpSorted(reposE1Browse.Read<Common.RowPermissionsReadItems>(), item => item.Name1Browse));
                Assert.AreEqual("1, 1b, 2, 3", TestUtility.DumpSorted(reposE1BrowseRP.Read<Common.RowPermissionsReadItems>(), item => item.Name1Browse));
            }
        }
Пример #15
0
 public void SqlFunction()
 {
     using (var container = new RhetosTestContainer())
     {
         Assert.AreEqual("11", ReportSqlQueryResult(container.Resolve<ISqlExecuter>(), "SELECT * FROM TestSqlWorkarounds.Fun2(10)"));
     }
 }
Пример #16
0
        public void DeleteModifiedPersistentObject()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();

                {
                    var s3Lock = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s3_lock" };
                    repository.TestLockItems.Simple.Insert(new[] { s3Lock });

                    AssertData("s3_lock", repository);
                    container.Resolve<Common.ExecutionContext>().NHibernateSession.Clear();
                    AssertData("s3_lock", repository);
                }

                {
                    var s3Persistent = repository.TestLockItems.Simple.All().Single();
                    s3Persistent.Name = "abc";
                    TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Persistent }),
                        "Name contains lock mark");

                    AssertData("s3_lock", repository);
                    container.Resolve<Common.ExecutionContext>().NHibernateSession.Clear();
                    AssertData("s3_lock", repository);
                }
            }
        }
Пример #17
0
        public void CascadeDelete()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve<Common.DomRepository>();

                var pid1 = Guid.NewGuid();
                var pid2 = Guid.NewGuid();
                var pid3 = Guid.NewGuid();
                var cid11 = Guid.NewGuid();
                var cid12 = Guid.NewGuid();
                var cid21 = Guid.NewGuid();
                var cid31 = Guid.NewGuid();

                container.Resolve<ISqlExecuter>().ExecuteSql(new[]
                {
                    "DELETE FROM TestEntity.Child",
                    "DELETE FROM TestEntity.BaseEntity",
                    "INSERT INTO TestEntity.BaseEntity (ID, Name) SELECT '" + pid1 + "', '1'",
                    "INSERT INTO TestEntity.BaseEntity (ID, Name) SELECT '" + pid2+ "', '2'",
                    "INSERT INTO TestEntity.BaseEntity (ID, Name) SELECT '" + pid3 + "', '3'",
                    "INSERT INTO TestEntity.Child (ID, Name, ParentID) SELECT '" + cid11 + "', '11', '" + pid1 + "'",
                    "INSERT INTO TestEntity.Child (ID, Name, ParentID) SELECT '" + cid12 + "', '12', '" + pid1 + "'",
                    "INSERT INTO TestEntity.Child (ID, Name, ParentID) SELECT '" + cid21 + "', '21', '" + pid2 + "'",
                    "INSERT INTO TestEntity.Child (ID, Name, ParentID) SELECT '" + cid31 + "', '31', '" + pid3 + "'",
                });

                Assert.AreEqual("11, 12, 21, 31", TestUtility.DumpSorted(repository.TestEntity.Child.All(), item => item.Name));

                repository.TestEntity.BaseEntity.Delete(new [] { new TestEntity.BaseEntity { ID = pid1 }, new TestEntity.BaseEntity { ID = pid2 } });

                Assert.AreEqual("31", TestUtility.DumpSorted(repository.TestEntity.Child.All(), item => item.Name));
            }
        }
Пример #18
0
        public void FilterNoPermissions()
        {
            using (var container = new RhetosTestContainer())
            {
                var repositories = container.Resolve<Common.DomRepository>();
                var itemsRepository = repositories.TestRowPermissions.RPRulesItem;
                var groupsRepository = repositories.TestRowPermissions.RPRulesGroup;
                itemsRepository.Delete(itemsRepository.All());
                groupsRepository.Delete(groupsRepository.All());

                var g1 = new RPRulesGroup { ID = Guid.NewGuid(), Name = "g1" };
                var g2 = new RPRulesGroup { ID = Guid.NewGuid(), Name = "g2" };
                var i1 = new RPRulesItem { ID = Guid.NewGuid(), Name = "i1", GroupID = g1.ID };
                var i2 = new RPRulesItem { ID = Guid.NewGuid(), Name = "i2", GroupID = g1.ID };
                var i3 = new RPRulesItem { ID = Guid.NewGuid(), Name = "i3", GroupID = g2.ID };
                var i4 = new RPRulesItem { ID = Guid.NewGuid(), Name = "i4", GroupID = g2.ID };

                groupsRepository.Insert(new[] { g1, g2 });
                itemsRepository.Insert(new[] { i1, i2, i3, i4 });

                var allowedItems = itemsRepository.Filter(itemsRepository.Query(), new Common.RowPermissionsReadItems());
                Console.WriteLine(itemsRepository.Query().Expression.ToString());
                Console.WriteLine(allowedItems.Expression.ToString());
                Assert.AreEqual("", TestUtility.DumpSorted(allowedItems, item => item.Name));
                Assert.AreEqual("Common.Queryable.TestRowPermissions_RPRulesItem[]", allowedItems.Expression.ToString(), "No need for query, an empty array should be returned.");
            }
        }
Пример #19
0
        public void UpdateLockedDataReference()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();
                Guid[] guids = new Guid[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
                var s1 = new TestLockItems.Simple { ID = guids[0], Name = "s1", Count = -1 };
                var s2 = new TestLockItems.Simple { ID = guids[1], Name = "s2", Count = 1 };

                var t1 = new TestLockItems.Simple2 { ID = guids[2], Name = "t1", TestReference = s1, Count = -1 };
                var t2 = new TestLockItems.Simple2 { ID = guids[3], Name = "t2", TestReference = s1, Count = 1 };

                repository.TestLockItems.Simple.Insert(new[] { s1, s2 });
                AssertData("s1, s2", repository);
                repository.TestLockItems.Simple2.Insert(new[] { t1, t2 });
                AssertDataSimple2("t1, t2", repository);

                foreach (var e in new[] { t1, t2 })
                    e.TestReference = s1;
                repository.TestLockItems.Simple2.Update(new[] { t1 });

                AssertDataSimple2("t1, t2", repository);
                foreach (var e in new[] { t1, t2 })
                    e.TestReference = s2;

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t1 }), "TestReference is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t2, t1 }), "TestReference is locked if count negative.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple2.Update(new[] { t1, t2 }), "TestReference is locked if count negative.");
                AssertDataSimple2("t1, t2", repository);

                repository.TestLockItems.Simple2.Update(new[] { t2 });
                AssertDataSimple2("t1, t2", repository);
            }
        }
Пример #20
0
        public void Simple()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve<Common.DomRepository>();

                var id1 = Guid.NewGuid();
                var id2 = Guid.NewGuid();
                container.Resolve<ISqlExecuter>().ExecuteSql(new[]
                    {
                        "DELETE FROM Test11.Source;",
                        "INSERT INTO Test11.Source (ID, Name) SELECT '" + id1 + "', 'a';",
                        "INSERT INTO Test11.Source (ID, Name) SELECT '" + id2 + "', 'b';"
                    });

                var all = repository.Test11.QE.Query().ToArray();
                Array.Sort(all, (a, b) => string.Compare(a.Info, b.Info));

                Assert.AreEqual(2, all.Length);

                Assert.AreEqual("ax", all[0].Info);
                Assert.AreEqual(id1, all[0].Base.ID);
                Assert.AreEqual("a", all[0].Base.Name);
                Assert.AreEqual(id1, all[0].ID);

                Assert.AreEqual("bx", all[1].Info);
                Assert.AreEqual(id2, all[1].Base.ID);
                Assert.AreEqual("b", all[1].Base.Name);
                Assert.AreEqual(id2, all[1].ID);
            }
        }
Пример #21
0
        public void UpdateLockedData()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = container.Resolve<Common.DomRepository>();

                var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1" };
                var s2 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s2" };
                var s3Lock = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s3_lock" };
                var s4 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s4" };
                repository.TestLockItems.Simple.Insert(new[] { s1, s2, s3Lock, s4 });
                AssertData("s1, s2, s3_lock, s4", repository);

                foreach (var e in new[] {s1, s2, s3Lock, s4})
                    e.Name = e.Name + "x";
                AssertData("s1, s2, s3_lock, s4", repository);

                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock }), "Name contains lock mark.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1, s3Lock }), "Name contains lock mark.");
                TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock, s4 }), "Name contains lock mark.");
                AssertData("s1, s2, s3_lock, s4", repository);

                repository.TestLockItems.Simple.Update(new[] { s1 });
                AssertData("s1x, s2, s3_lock, s4", repository);
            }
        }
Пример #22
0
        public void ComputeForNewBaseItems()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve<Common.DomRepository>();

                var d1ID = Guid.NewGuid();
                container.Resolve<ISqlExecuter>().ExecuteSql(new[]
                    {
                        "DELETE FROM Test9.Document;",
                        "DELETE FROM Test9.DocumentCreationInfo;",
                        "INSERT INTO Test9.Document (ID, Name) SELECT '" + d1ID + "', 'd1'"
                    });

                Assert.AreEqual("", ReportDocumentCreationInfo(repository), "initial");
                repository.Test9.DocumentCreationInfo.Recompute();
                Assert.AreEqual("d1:1", ReportDocumentCreationInfo(repository), "initial recalc");

                var documents = repository.Test9.Document;

                var d2ID = Guid.NewGuid();
                documents.Insert(new[] { new Test9.Document { ID = d2ID, Name = "d2" } });
                Assert.AreEqual("d1:1, d2:2", ReportDocumentCreationInfo(repository), "autorecompute after new");

                var d3ID = Guid.NewGuid();
                var d4ID = Guid.NewGuid();
                documents.Insert(new[] { new Test9.Document { ID = d3ID, Name = "d3" }, new Test9.Document { ID = d4ID, Name = "d4" } });
                Assert.AreEqual("d1:1, d2:2, d3:4, d4:4", ReportDocumentCreationInfo(repository), "autorecompute after new2");

                documents.Save(null, new[] { new Test9.Document { ID = d1ID, Name = "d1x" } }, new[] { new Test9.Document { ID = d3ID } });
                Assert.AreEqual("d1x:1, d2:2, d4:4", ReportDocumentCreationInfo(repository), "autorecompute after update&delete");
            }
        }
Пример #23
0
 public void DomRepositoryHasModuleRepositories()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         Assert.IsNotNull(repository.TestDataStructure);
     }
 }
Пример #24
0
 public void ShouldNotThrowUserExceptionOnInsert()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new SimpleRange { FromValue = (decimal)1.1, ToValue = (decimal)2.0 };
         repository.TestRange.SimpleRange.Insert(new[] { entity });
     }
 }
Пример #25
0
 public void NormallyInsertDecimal()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new SimpleDecimal { Value = (decimal)2.30 };
         repository.TestMaxValue.SimpleDecimal.Insert(new[] { entity });
     }
 }
Пример #26
0
 public void NormallyInsertInteger()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new SimpleInteger { Value = 1 };
         repository.TestMaxValue.SimpleInteger.Insert(new[] { entity });
     }
 }
Пример #27
0
 public void DeleteTestPermissions()
 {
     using (var container = new RhetosTestContainer(commitChanges: true))
     {
         var r = container.Resolve<Common.DomRepository>();
         r.Common.Principal.Delete(r.Common.Principal.Load(p => p.Name.StartsWith(UserPrefix)));
         r.Common.Role.Delete(r.Common.Role.Load(p => p.Name.StartsWith(RolePrefix)));
     }
 }
Пример #28
0
 public void ShouldThowUserExceptionOnUpdate()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new SimpleMinLength { StringMoreThan2Chars = "." };
         repository.TestLengthLimit.SimpleMinLength.Update(new[] { entity });
     }
 }
Пример #29
0
 public void EmptyValuesAreAllowed()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new Simple { StringFrom200To249 = null };
         repository.TestRegex.Simple.Insert(new[] { entity });
     }
 }
Пример #30
0
 public void NormallyInsertDateTime()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new SimpleDateTime { Value = new DateTime(2013, 7, 5, 12, 33, 1) };
         repository.TestMaxValue.SimpleDateTime.Insert(new[] { entity });
     }
 }
Пример #31
0
        public void EditableProperty()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[]
                {
                    "DELETE FROM TestDenyUserEdit.Simple",
                    "DELETE FROM TestDenyUserEdit.Parent"
                });
                var repository = container.Resolve <Common.DomRepository>();

                var simple = new TestDenyUserEdit.Simple {
                    Editable = "a"
                };
                repository.TestDenyUserEdit.Simple.Save(new[] { simple }, null, null, true);
                Assert.AreEqual("a null null", DumpSimple(repository));

                simple.Editable = "b";
                repository.TestDenyUserEdit.Simple.Save(null, new[] { simple }, null, true);
                Assert.AreEqual("b null null", DumpSimple(repository));
            }
        }
Пример #32
0
        public void Filter()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve <Common.DomRepository>();
                container.Resolve <ISqlExecuter>().ExecuteSql(new[]
                {
                    "DELETE FROM Test13.Old3;",
                    "INSERT INTO Test13.Old3 (Num, Text) SELECT 10, 'a'",
                    "INSERT INTO Test13.Old3 (Num, Text) SELECT 20, 'a'",
                    "INSERT INTO Test13.Old3 (Num, Text) SELECT 30, 'a'",
                    "INSERT INTO Test13.Old3 (Num, Text) SELECT 110, 'a2'",
                    "INSERT INTO Test13.Old3 (Num, Text) SELECT 120, 'a3'",
                    "INSERT INTO Test13.Old3 (Num, Text) SELECT 130, 'a4'"
                });

                var filtered = repository.Test13.Legacy3.Filter(new Test13.PatternFilter {
                    Pattern = "2"
                });
                Assert.AreEqual("110, 20", TestUtility.DumpSorted(filtered, item => item.NumNew.ToString()));
            }
        }
Пример #33
0
        public void SimpleWithPredefinedSuffixLength()
        {
            using (var container = new RhetosTestContainer())
            {
                DeleteOldData(container);
                var repository = container.Resolve <Common.DomRepository>();

                TestSimple(container, repository, "+", "1");
                TestSimple(container, repository, "+", "2");
                TestSimple(container, repository, "++++", "0003");
                TestSimple(container, repository, "+", "0004");
                TestSimple(container, repository, "++", "0005");
                TestSimple(container, repository, "AB+", "AB1");
                TestSimple(container, repository, "X", "X");
                TestSimple(container, repository, "X+", "X1");
                TestSimple(container, repository, "AB007", "AB007");
                TestSimple(container, repository, "AB+", "AB008");
                TestSimple(container, repository, "AB999", "AB999");
                TestSimple(container, repository, "AB+", "AB1000");
                TestSimple(container, repository, "AB++++++", "AB001001");
            }
        }
Пример #34
0
        public void Simple()
        {
            using (var container = new RhetosTestContainer())
            {
                DeleteOldData(container);
                var repository = container.Resolve <Common.DomRepository>();

                TestSimple(container, repository, "+", "1");
                TestSimple(container, repository, "+", "2");
                TestSimple(container, repository, "+", "3");
                TestSimple(container, repository, "9", "9");
                TestSimple(container, repository, "+", "10");
                TestSimple(container, repository, "+", "11");
                TestSimple(container, repository, "AB+", "AB1");
                TestSimple(container, repository, "X", "X");
                TestSimple(container, repository, "X+", "X1");
                TestSimple(container, repository, "AB007", "AB007");
                TestSimple(container, repository, "AB+", "AB008");
                TestSimple(container, repository, "AB999", "AB999");
                TestSimple(container, repository, "AB+", "AB1000");
            }
        }
Пример #35
0
        private void Execute2ParallelInserts(int testCount, Action <int, TestAutoCodeCached._Helper.Simple_Repository> action)
        {
            using (var container = new RhetosTestContainer(true))
            {
                DeleteOldData(container);
                CheckForParallelism(container.Resolve <ISqlExecuter>(), 2);
            }

            for (int test = 1; test <= testCount; test++)
            {
                Console.WriteLine("Test: " + test);

                var containers   = new[] { new RhetosTestContainer(true), new RhetosTestContainer(true) };
                var repositories = containers.Select(c => c.Resolve <Common.DomRepository>().TestAutoCodeCached.Simple).ToList();
                foreach (var r in repositories)
                {
                    Assert.IsTrue(r.Query().Count() >= 0); // Cold start.
                }
                try
                {
                    Parallel.For(0, 2, process =>
                    {
                        action(process, repositories[process]);
                        containers[process].Dispose();
                        containers[process] = null;
                    });
                }
                finally
                {
                    foreach (var c in containers)
                    {
                        if (c != null)
                        {
                            c.Dispose();
                        }
                    }
                }
            }
        }
Пример #36
0
        public void InsertPersistent()
        {
            using (var container = new RhetosTestContainer())
            {
                var context    = container.Resolve <Common.ExecutionContext>();
                var repository = container.Resolve <Common.DomRepository>();

                repository.TestEntity.Child.Delete(repository.TestEntity.Child.Load());
                repository.TestEntity.BaseEntity.Delete(repository.TestEntity.BaseEntity.Load());

                var b = new TestEntity.BaseEntity {
                    ID = Guid.NewGuid(), Name = "b"
                };
                var c = new TestEntity.Child {
                    Name = "c", ParentID = b.ID
                };
                repository.TestEntity.BaseEntity.Insert(b);
                repository.TestEntity.Child.Insert(c);

                var c2 = repository.TestEntity.Child.Query()
                         .Select(child => new TestEntity.Child {
                    ID = Guid.NewGuid(), Name = "c2", ParentID = child.ParentID
                })
                         .ToList();
                repository.TestEntity.Child.Insert(c2);

                context.EntityFrameworkContext.ClearCache();

                var ids = repository.TestEntity.Child.Query().Select(child => child.ID).ToList();
                Assert.AreEqual(2, ids.Count());
                Assert.AreNotEqual(default(Guid), ids[0]);
                Assert.AreNotEqual(default(Guid), ids[1]);
                Assert.AreNotEqual(ids[0], ids[1]);

                var report = repository.TestEntity.Child.Query()
                             .Select(item => item.Name + " " + item.Parent.Name);
                Assert.AreEqual("c b, c2 b", TestUtility.DumpSorted(report));
            }
        }
Пример #37
0
        public void FilterNoPermissions()
        {
            using (var container = new RhetosTestContainer())
            {
                var repositories     = container.Resolve <Common.DomRepository>();
                var itemsRepository  = repositories.TestRowPermissions.RPRulesItem;
                var groupsRepository = repositories.TestRowPermissions.RPRulesGroup;
                itemsRepository.Delete(itemsRepository.Query());
                groupsRepository.Delete(groupsRepository.Query());

                var g1 = new RPRulesGroup {
                    ID = Guid.NewGuid(), Name = "g1"
                };
                var g2 = new RPRulesGroup {
                    ID = Guid.NewGuid(), Name = "g2"
                };
                var i1 = new RPRulesItem {
                    ID = Guid.NewGuid(), Name = "i1", GroupID = g1.ID
                };
                var i2 = new RPRulesItem {
                    ID = Guid.NewGuid(), Name = "i2", GroupID = g1.ID
                };
                var i3 = new RPRulesItem {
                    ID = Guid.NewGuid(), Name = "i3", GroupID = g2.ID
                };
                var i4 = new RPRulesItem {
                    ID = Guid.NewGuid(), Name = "i4", GroupID = g2.ID
                };

                groupsRepository.Insert(new[] { g1, g2 });
                itemsRepository.Insert(new[] { i1, i2, i3, i4 });

                var allowedItems = itemsRepository.Filter(itemsRepository.Query(), new Common.RowPermissionsReadItems());
                Console.WriteLine(itemsRepository.Query().Expression.ToString());
                Console.WriteLine(allowedItems.Expression.ToString());
                Assert.AreEqual("", TestUtility.DumpSorted(allowedItems, item => item.Name));
                Assert.AreEqual("Common.Queryable.TestRowPermissions_RPRulesItem[]", allowedItems.Expression.ToString(), "No need for query, an empty array should be returned.");
            }
        }
Пример #38
0
        public void SimpleReference()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve <Common.DomRepository>();

                Guid refID = Guid.NewGuid();
                container.Resolve <ISqlExecuter>().ExecuteSql(new[]
                {
                    "DELETE FROM TestBrowse.Source;",
                    "DELETE FROM TestBrowse.Other;",
                    "INSERT INTO TestBrowse.Other (ID, Name) SELECT '" + refID + "', 'abc';",
                    "INSERT INTO TestBrowse.Source (RefID) SELECT '" + refID + "';",
                });

                Assert.AreEqual("abc", repository.TestBrowse.Source.Query().ToArray().Select(item => item.Ref != null ? item.Ref.Name : null).Single(), "separated loading with null checking");
                Assert.AreEqual("abc", repository.TestBrowse.Source.Query().Select(item => item.Ref != null ? item.Ref.Name : null).Single(), "all in one query with null checking");

                Assert.AreEqual("abc", repository.TestBrowse.Source.Query().Select(item => item.Ref.Name).Single(), "all in one query");
                Assert.AreEqual("abc", repository.TestBrowse.Source.Query().ToArray().Select(item => item.Ref.Name).Single(), "separated loading");
            }
        }
Пример #39
0
        public void Dependencies()
        {
            using (var container = new RhetosTestContainer())
            {
                int?   dependencies      = null;
                string checkDependencies =
                    @"SELECT
                        COUNT(*)
                    FROM
                        Rhetos.AppliedConceptDependsOn dependency
                        INNER JOIN Rhetos.AppliedConcept dependent ON dependent.ID = dependency.DependentID
                        INNER JOIN Rhetos.AppliedConcept dependsOn ON dependsOn.ID = dependency.DependsOnID
                    WHERE
                        dependent.CreateQuery LIKE '%VIEW TestPolymorphic.DependentQuery%'
                        AND dependsOn.CreateQuery LIKE '%VIEW TestPolymorphic.PolyWithDependencies%'";

                var sqlExecuter = container.Resolve <ISqlExecuter>();
                sqlExecuter.ExecuteReader(checkDependencies, reader => { dependencies = reader.GetInt32(0); });

                Assert.AreEqual(1, dependencies);
            }
        }
Пример #40
0
        public void UpdateInvalidDataWithValidInsertAndDelete()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestInvalidData.Simple;" });
                var repository = container.Resolve <Common.DomRepository>();

                var s1 = CreateSimple(1).Single();
                var s2 = CreateSimple(2).Single();
                var s3 = CreateSimple(3).Single();
                repository.TestInvalidData.Simple.Insert(new[] { s1, s2, s3 });
                s3.Name  = "s3b";
                s3.Count = 33;
                repository.TestInvalidData.Simple.Update(new[] { s3 });
                repository.TestInvalidData.Simple.Delete(new[] { s1 });

                AssertData(repository, "s2, s3b");
                s3.Name  = "s3d";
                s3.Count = 333;
                TestUtility.ShouldFail(() => repository.TestInvalidData.Simple.Save(CreateSimple(5), new[] { s3 }, new[] { s2 }), "larger than 100");
            }
        }
Пример #41
0
        public void LogCommandDescription()
        {
            using (var container = new RhetosTestContainer())
            {
                var log = new List <string>();
                container.AddLogMonitor(log);
                container.AddIgnoreClaims();

                var processingEngine = container.Resolve <IProcessingEngine>();
                var readPrincipals   = new ReadCommandInfo
                {
                    DataSource     = "Common.Principal",
                    ReadTotalCount = true,
                    Filters        = new[] { new FilterCriteria {
                                                 Filter = "System.Guid[]", Value = new[] { new Guid("546df18b-5df8-4ffa-9b08-8da909efe067") }
                                             } }
                };
                var processingEngineResult = processingEngine.Execute(new[] { readPrincipals });
                Assert.IsTrue(processingEngineResult.Success);

                var excected = new ListOfTuples <string, IEnumerable <string> >()
                {
                    { "request info", new[] { "ProcessingEngine Request", "ReadCommandInfo Common.Principal count, filters: System.Guid[] 546df18b-5df8-4ffa-9b08-8da909efe067" } },
                    { "command xml", new[] { "ProcessingEngine Commands", "Common.Principal</DataSource>", "true</ReadTotalCount>" } },
                };

                foreach (var test in excected)
                {
                    Assert.IsTrue(log.Any(line => test.Item2.All(pattern => line.Contains(pattern))), "Missing a log entry for test '" + test.Item1 + "'.");
                }

                var notExpected = new[] { "error info", "CommandsWithClientError", "CommandsWithClientError", "CommandsWithServerError", "CommandsWithServerError" };

                foreach (var test in notExpected)
                {
                    Assert.IsFalse(log.Any(line => line.Contains(test)), "Unexpected log entry for test '" + test + "'.");
                }
            }
        }
Пример #42
0
        public void DoubleAutoCode()
        {
            using (var container = new RhetosTestContainer())
            {
                DeleteOldData(container);
                var repository = container.Resolve <Common.DomRepository>();

                TestDoubleAutoCode(container, repository, "+", "+", "1,1");
                TestDoubleAutoCode(container, repository, "+", "4", "2,4");
                TestDoubleAutoCode(container, repository, "+", "+", "3,5");
                TestDoubleAutoCode(container, repository, "9", "+", "9,6");
                TestDoubleAutoCode(container, repository, "+", "11", "10,11");
                TestDoubleAutoCode(container, repository, "+", "+", "11,12");
                TestDoubleAutoCode(container, repository, "AB+", "+", "AB1,13");
                TestDoubleAutoCode(container, repository, "AB+", "X", "AB2,X");
                TestDoubleAutoCode(container, repository, "AB+", "X+", "AB3,X1");
                TestDoubleAutoCode(container, repository, "AB008", "X+", "AB008,X2");
                TestDoubleAutoCode(container, repository, "AB+", "+", "AB009,14");
                TestDoubleAutoCode(container, repository, "+", "AB9999", "12,AB9999");
                TestDoubleAutoCode(container, repository, "AB+", "AB+", "AB010,AB10000");
            }
        }
Пример #43
0
        public void AllowedNullValueInternally()
        {
            using (var container = new RhetosTestContainer())
            {
                DeleteOldData(container);

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

                var s1 = new TestAutoCodeCached.Simple {
                    ID = Guid.NewGuid(), Code = null
                };

                AutoCodeHelper.UpdateCodes(
                    context.SqlExecuter, "TestAutoCodeCached.Simple", "Code",
                    new[] { new Rhetos.Dom.DefaultConcepts.AutoCodeItem <TestAutoCodeCached.Simple> {
                                Item = s1, Code = s1.Code, Grouping = ""
                            } },
                    (item, newCode) => item.Code = newCode);

                Assert.IsNull(s1.Code);
            }
        }
Пример #44
0
        public void DeleteInsertSamePersisted()
        {
            using (var container = new RhetosTestContainer())
            {
                var context    = container.Resolve <Common.ExecutionContext>();
                var repository = context.Repository;
                repository.TestEntity.BaseEntity.Delete(repository.TestEntity.BaseEntity.Load());

                var b = new TestEntity.BaseEntity {
                    ID = Guid.NewGuid(), Name = "b"
                };
                repository.TestEntity.BaseEntity.Insert(b);

                Assert.AreEqual("b", TestUtility.DumpSorted(repository.TestEntity.BaseEntity.Query(), item => item.Name));

                var b2 = repository.TestEntity.BaseEntity.Query().Where(item => item.ID == b.ID).Single();
                b2.Name = "b2";
                repository.TestEntity.BaseEntity.Save(new[] { b2 }, null, new[] { b });

                Assert.AreEqual("b2", TestUtility.DumpSorted(repository.TestEntity.BaseEntity.Query(), item => item.Name));
            }
        }
Пример #45
0
        public void Disjunctive()
        {
            foreach (bool useDatabaseNullSemantics in new[] { false, true })
            {
                using (var container = new RhetosTestContainer())
                {
                    container.SetUseDatabaseNullSemantics(useDatabaseNullSemantics);
                    var repository = container.Resolve <Common.DomRepository>();

                    repository.TestPolymorphic.Disjunctive1.Delete(repository.TestPolymorphic.Disjunctive1.Load());
                    repository.TestPolymorphic.Disjunctive2.Delete(repository.TestPolymorphic.Disjunctive2.Load());
                    Assert.AreEqual(0, repository.TestPolymorphic.Disjunctive.Load().Count());

                    var d1 = new TestPolymorphic.Disjunctive1 {
                        ID = Guid.NewGuid(), Name = "abc"
                    };
                    repository.TestPolymorphic.Disjunctive1.Insert(new[] { d1 });

                    var d2 = new TestPolymorphic.Disjunctive2 {
                        ID = Guid.NewGuid(), Days = 123
                    };
                    repository.TestPolymorphic.Disjunctive2.Insert(new[] { d2 });

                    var all = repository.TestPolymorphic.Disjunctive.Query();
                    Assert.AreEqual(
                        TestUtility.DumpSorted(new[] { d1.ID, d2.ID }),
                        TestUtility.DumpSorted(all, item => item.ID));

                    var browseReport = repository.TestPolymorphic.DisjunctiveBrowse.Query()
                                       .AsEnumerable()
                                       .Select(item => item.Subtype + "-" + item.Disjunctive1?.Name + "-" + item.Disjunctive2Days)
                                       .ToList();
                    Assert.AreEqual(
                        "TestPolymorphic.Disjunctive1-abc-, TestPolymorphic.Disjunctive2--123",
                        TestUtility.DumpSorted(browseReport));
                }
            }
        }
Пример #46
0
        public void CascadeDelete()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve <Common.DomRepository>();

                var pid1  = Guid.NewGuid();
                var pid2  = Guid.NewGuid();
                var pid3  = Guid.NewGuid();
                var cid11 = Guid.NewGuid();
                var cid12 = Guid.NewGuid();
                var cid21 = Guid.NewGuid();
                var cid31 = Guid.NewGuid();

                container.Resolve <ISqlExecuter>().ExecuteSql(new[]
                {
                    "DELETE FROM TestEntity.Child",
                    "DELETE FROM TestEntity.BaseEntity",
                    "INSERT INTO TestEntity.BaseEntity (ID, Name) SELECT '" + pid1 + "', '1'",
                    "INSERT INTO TestEntity.BaseEntity (ID, Name) SELECT '" + pid2 + "', '2'",
                    "INSERT INTO TestEntity.BaseEntity (ID, Name) SELECT '" + pid3 + "', '3'",
                    "INSERT INTO TestEntity.Child (ID, Name, ParentID) SELECT '" + cid11 + "', '11', '" + pid1 + "'",
                    "INSERT INTO TestEntity.Child (ID, Name, ParentID) SELECT '" + cid12 + "', '12', '" + pid1 + "'",
                    "INSERT INTO TestEntity.Child (ID, Name, ParentID) SELECT '" + cid21 + "', '21', '" + pid2 + "'",
                    "INSERT INTO TestEntity.Child (ID, Name, ParentID) SELECT '" + cid31 + "', '31', '" + pid3 + "'",
                });

                Assert.AreEqual("11, 12, 21, 31", TestUtility.DumpSorted(repository.TestEntity.Child.Query(), item => item.Name));

                repository.TestEntity.BaseEntity.Delete(new [] { new TestEntity.BaseEntity {
                                                                     ID = pid1
                                                                 }, new TestEntity.BaseEntity {
                                                                     ID = pid2
                                                                 } });

                Assert.AreEqual("31", TestUtility.DumpSorted(repository.TestEntity.Child.Query(), item => item.Name));
            }
        }
Пример #47
0
        public void SqlChangeID()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve <Common.DomRepository>();

                var id1 = Guid.NewGuid();
                var id2 = Guid.NewGuid();

                container.Resolve <ISqlExecuter>().ExecuteSql(new[]
                {
                    "DELETE FROM TestLogging.Complex",
                    "DELETE FROM TestLogging.Simple",
                    "INSERT INTO TestLogging.Simple (ID, Name) VALUES (" + SqlUtility.QuoteGuid(id1) + ", 'abc')",
                    "UPDATE TestLogging.Simple SET ID = " + SqlUtility.QuoteGuid(id2)
                });

                var actual = repository.Common.Log.Query().Where(log => new Guid?[] { id1, id2 }.Contains(log.ItemId)).ToArray();

                var expected = new[]
                {
                    new Common.Log {
                        ItemId = id1, Action = "Delete", Description = "...abc..."
                    },
                    new Common.Log {
                        ItemId = id1, Action = "Insert", Description = "..."
                    },
                    new Common.Log {
                        ItemId = id2, Action = "Insert", Description = "..."
                    },
                };

                Func <Common.Log[], string> report = logRecords =>
                                                     TestUtility.DumpSorted(logRecords, log => log.ItemId.ToString() + " " + log.Action + " " + log.Description.Contains("abc"));

                Assert.AreEqual(report(expected), report(actual));
            }
        }
Пример #48
0
        public void FilterIntOperations()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[]
                {
                    "DELETE FROM TestGenericFilter.Simple;",
                    "INSERT INTO TestGenericFilter.Simple (Code, Name) SELECT 1, 'abc1';",
                    "INSERT INTO TestGenericFilter.Simple (Code, Name) SELECT 2, 'abc2';",
                    "INSERT INTO TestGenericFilter.Simple (Code, Name) SELECT 12, 'abc12';",
                    "INSERT INTO TestGenericFilter.Simple (Code, Name) SELECT 3, 'def3';",
                });

                var repository = container.Resolve <Common.DomRepository>();
                FilterCode(repository, "equals", "2", "2");
                FilterCode(repository, "notequals", "2", "1, 12, 3");
                FilterCode(repository, "less", "2", "1");
                FilterCode(repository, "lessequal", "2", "1, 2");
                FilterCode(repository, "greater", "2", "12, 3");
                FilterCode(repository, "greaterequal", "2", "12, 2, 3");
                FilterCode(repository, "startswith", "1", "1, 12");
                FilterCode(repository, "startswith", "12", "12");
                FilterCode(repository, "startswith", "", "1, 12, 2, 3");
                FilterCode(repository, "startswith", "7", "");
                FilterCode(repository, "endswith", "2", "12, 2");
                FilterCode(repository, "endswith", "12", "12");
                FilterCode(repository, "endswith", "", "1, 12, 2, 3");
                FilterCode(repository, "endswith", "7", "");
                FilterCode(repository, "contains", "2", "12, 2");
                FilterCode(repository, "contains", "12", "12");
                FilterCode(repository, "contains", "", "1, 12, 2, 3");
                FilterCode(repository, "contains", "7", "");
                FilterCode(repository, "notcontains", "2", "1, 3");
                FilterCode(repository, "notcontains", "12", "1, 2, 3");
                FilterCode(repository, "notcontains", "", "");
                FilterCode(repository, "notcontains", "7", "1, 12, 2, 3");
            }
        }
Пример #49
0
        public void SimpleComposableFilterCaseInsensitive()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestFilter.CombinedFilters" });
                var repository = container.Resolve <Common.DomRepository>();

                var s1 = new TestFilter.CombinedFilters {
                    Name = "Abeceda"
                };
                var s2 = new TestFilter.CombinedFilters {
                    Name = "abeceda"
                };
                repository.TestFilter.CombinedFilters.Insert(new[] { s1, s2 });

                var filteredByContainsJustComposable = ExecuteCommand(new QueryDataSourceCommandInfo
                {
                    DataSource = "TestFilter.CombinedFilters",
                    Filter     = new TestFilter.ComposableFilterByContains {
                        Pattern = "Abec"
                    }
                }, container);

                var filteredByContainsWithGenericFilter = ExecuteCommand(new QueryDataSourceCommandInfo
                {
                    DataSource = "TestFilter.CombinedFilters",
                    Filter     = new TestFilter.ComposableFilterByContains {
                        Pattern = "Abec"
                    },
                    GenericFilter = new FilterCriteria[] { new FilterCriteria {
                                                               Property = "Name", Operation = "Contains", Value = "Abec"
                                                           } }
                }, container);
                // filter doubled should return same results as just one Composable filter
                Assert.AreEqual(filteredByContainsJustComposable.Records.Length, filteredByContainsWithGenericFilter.Records.Length);
                Assert.AreEqual(2, filteredByContainsWithGenericFilter.Records.Length);
            }
        }
Пример #50
0
        //================================================================

        private void TestIndexMultipleInsert(string s, int i, int r, bool shouldFail = false)
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[]
                {
                    "DELETE FROM TestUnique.Multi;",
                    "DELETE FROM TestUnique.R;"
                });

                var repository = container.Resolve <Common.DomRepository>();

                var r1 = new TestUnique.R {
                    S = "r1"
                };
                var r2 = new TestUnique.R {
                    S = "r2"
                };
                repository.TestUnique.R.Insert(new[] { r1, r2 });

                repository.TestUnique.Multi.Insert(new TestUnique.Multi {
                    S = "a", I = 1, RID = r1.ID, ID = Guid.NewGuid()
                });

                Action insert = () => repository.TestUnique.Multi.Insert(new TestUnique.Multi {
                    S = s, I = i, RID = (r == 1) ? r1.ID : r2.ID, ID = Guid.NewGuid()
                });
                if (shouldFail)
                {
                    var ex = TestUtility.ShouldFail(insert, "It is not allowed to enter a duplicate record.");
                    TestUtility.AssertContains(ex.ToString(), "Cannot insert duplicate key", "Original SQL exception should be included.");
                }
                else
                {
                    insert();
                }
            }
        }
Пример #51
0
        public void MoneyPropertySizeAndDecimals()
        {
            using (var container = new RhetosTestContainer())
            {
                var context = container.Resolve <Common.ExecutionContext>();

                var tests = new List <(decimal Save, decimal Load)>
                {
                    (12.34100m, 12.34m),
                    (12.34900m, 12.34m),
                    (-12.3410m, -12.34m),
                    (-12.3490m, -12.34m),
                    (-922337203685477.58m, -922337203685477.58m), // T-SQL money limits.
                    (922337203685477.58m, 922337203685477.58m),   // T-SQL money limits.
                    (0m, 0m),
                    // Current behavior is rounding money values, but it should be changed in future,
                    // see https://github.com/Rhetos/Rhetos/issues/389: Money type should throw an exception, instead of implicit rounding, if saving more decimals then allowed.
                    (0.001m, 0m),
                    (0.009m, 0m),
                    (0.019m, 0.01m),
                    (-0.001m, 0m),
                    (-0.009m, 0m),
                    (-0.019m, -0.01m),
                };

                foreach (var test in tests)
                {
                    var entity = new TestStorage.AllProperties
                    {
                        ID            = Guid.NewGuid(),
                        MoneyProperty = test.Save
                    };
                    context.PersistenceStorage.Insert(entity);
                    Assert.AreEqual(test.Load, context.Repository.TestStorage.AllProperties.Load(x => x.ID == entity.ID).Single().MoneyProperty,
                                    $"The money property should be cut off on the second decimal position ({test.Save}).");
                }
            }
        }
Пример #52
0
        public void SqlExecuterInPersistenceTransaction()
        {
            var ids = new[] { Guid.NewGuid(), Guid.NewGuid() };

            using (var container = new RhetosTestContainer(commitChanges: false))
            {
                var repository  = container.Resolve <Common.DomRepository>();
                var sqlExecuter = container.Resolve <ISqlExecuter>();

                // Initial empty state:
                Assert.AreEqual("", TestUtility.DumpSorted(repository.TestEntity.BaseEntity.Load(ids), item => item.Name));

                // Write using SqlExecuter, read using object model persistence transaction:
                sqlExecuter.ExecuteSql(string.Format(
                                           "INSERT INTO TestEntity.BaseEntity (ID, Name) SELECT {0}, 'e0'",
                                           SqlUtility.QuoteGuid(ids[0])));
                Assert.AreEqual("e0", TestUtility.DumpSorted(repository.TestEntity.BaseEntity.Load(ids), item => item.Name));

                // Write using object model persistence transaction, read using SqlExecuter
                repository.TestEntity.BaseEntity.Insert(new TestEntity.BaseEntity {
                    ID = ids[1], Name = "e1"
                });
                var sqlReport = new List <string>();
                sqlExecuter.ExecuteReader(string.Format(
                                              "SELECT Name FROM TestEntity.BaseEntity WHERE ID IN ({0}, {1})",
                                              SqlUtility.QuoteGuid(ids[0]), SqlUtility.QuoteGuid(ids[1])),
                                          reader => sqlReport.Add(reader.GetString(0)));
                Assert.AreEqual("e0, e1", TestUtility.DumpSorted(sqlReport));
            }

            using (var container = new RhetosTestContainer(commitChanges: false))
            {
                var repository = container.Resolve <Common.DomRepository>();

                // Empty state after persistence transaction rollback:
                Assert.AreEqual("", TestUtility.DumpSorted(repository.TestEntity.BaseEntity.Load(ids), item => item.Name));
            }
        }
Пример #53
0
        public void AutoInherit()
        {
            using (var container = new RhetosTestContainer())
            {
                var names   = new[] { "1", "1b", "2", "3", "4" };
                var itemsE4 = names.Select(name => new TestRowPermissions4.E4 {
                    ID = Guid.NewGuid(), Name4 = name
                }).ToList();
                var itemsE3 = names.Select((name, x) => new TestRowPermissions3.E3 {
                    ID = Guid.NewGuid(), Name3 = name, E4ID = itemsE4[x].ID
                }).ToList();
                var itemsE2 = names.Select((name, x) => new TestRowPermissions2.E2 {
                    ID = Guid.NewGuid(), Name2 = name, E3ID = itemsE3[x].ID
                }).ToList();
                var itemsE1 = names.Select((name, x) => new TestRowPermissions1.E1 {
                    ID = Guid.NewGuid(), Name1 = name, E2ID = itemsE2[x].ID
                }).ToList();

                var reposE1         = container.Resolve <GenericRepository <TestRowPermissions1.E1> >();
                var reposE1Browse   = container.Resolve <GenericRepository <TestRowPermissions1.E1Browse> >();
                var reposE1BrowseRP = container.Resolve <GenericRepository <TestRowPermissions1.E1BrowseRP> >();
                var reposE2         = container.Resolve <GenericRepository <TestRowPermissions2.E2> >();
                var reposE3         = container.Resolve <Common.DomRepository>().TestRowPermissions3.E3;
                var reposE4         = container.Resolve <GenericRepository <TestRowPermissions4.E4> >();

                reposE4.Save(itemsE4, null, reposE4.Load());
                reposE3.Save(itemsE3, null, reposE3.Load());
                reposE2.Save(itemsE2, null, reposE2.Load());
                reposE1.Save(itemsE1, null, reposE1.Load());

                Assert.AreEqual("4", TestUtility.DumpSorted(reposE4.Load <Common.RowPermissionsReadItems>(), item => item.Name4));
                Assert.AreEqual("3->3", TestUtility.DumpSorted(reposE3.Query(null, typeof(Common.RowPermissionsReadItems)).ToList(), item => item.Name3 + "->" + item.E4.Name4));
                Assert.AreEqual("2, 3", TestUtility.DumpSorted(reposE2.Load <Common.RowPermissionsReadItems>(), item => item.Name2));
                Assert.AreEqual("1, 2, 3", TestUtility.DumpSorted(reposE1.Load <Common.RowPermissionsReadItems>(), item => item.Name1));
                Assert.AreEqual("1, 2, 3", TestUtility.DumpSorted(reposE1Browse.Load <Common.RowPermissionsReadItems>(), item => item.Name1Browse));
                Assert.AreEqual("1, 1b, 2, 3", TestUtility.DumpSorted(reposE1BrowseRP.Load <Common.RowPermissionsReadItems>(), item => item.Name1Browse));
            }
        }
Пример #54
0
        static void Main(string[] args)
        {
            ConsoleLogger.MinLevel = EventType.Info; // Use "Trace" for more detailed log.
            var rhetosServerPath = @"..\..\..\..\dist\RhetosRadionicaRhetosServer";

            Directory.SetCurrentDirectory(rhetosServerPath);
            // Set commitChanges parameter to COMMIT or ROLLBACK the data changes.
            using (var container = new RhetosTestContainer(commitChanges: true))
            {
                var context    = container.Resolve <Common.ExecutionContext>();
                var repository = context.Repository;

                var booksLoad = repository.Bookstore.Book.Load(b => b.Title.Contains("curiosity"));
                booksLoad.Dump();

                var booksQueryString = repository.Bookstore.Book.Query(b => b.Title.Contains("curiosity")).ToString();
                booksQueryString.Dump();

                var filter = new Bookstore.CommonMisspelling();
                //var booksQuery = repository.Bookstore.Book.Query(filter).ToSimple();
                //booksQuery.Dump();

                var id = new Guid("77AC7BF5-DBCE-401C-BE0C-B8146A79EB7D");
                repository.Bookstore.Book.Query(new[] { id }).ToSimple().Dump();

                repository.Bookstore.Book.Insert(new[] { new Book {
                                                             NumberOfPages = 100, Title = "Insert preko konzole", Code = "B+++"
                                                         } });
                var existingBook = repository.Bookstore.Book.Query(new[] { id }).Single();
                existingBook.Title = "Editovana knjiga";
                repository.Bookstore.Book.Update(existingBook);

                var booksForRemoval = repository.Bookstore.Book.Query(b => b.Title == "Insert preko konzole");
                repository.Bookstore.Book.Delete(booksForRemoval);

                Console.WriteLine("Done.");
            }
        }
Пример #55
0
        public void InsertMultipleItems()
        {
            using (var container = new RhetosTestContainer())
            {
                DeleteOldData(container);
                var repository = container.Resolve <Common.DomRepository>();

                var tests = new ListOfTuples <string, string>
                {
                    { "+", "10" }, // Exactly specified values are considered before generated values, therefore this item is handled after core "9".
                    { "+", "11" },
                    { "+", "12" },
                    { "9", "9" },
                    { "+", "13" },
                    { "+", "14" },
                    { "AB+", "AB1000" },
                    { "X", "X" },
                    { "X+", "X1" },
                    { "AB007", "AB007" },
                    { "AB+", "AB1001" },
                    { "AB999", "AB999" },
                    { "AB+", "AB1002" },
                };

                repository.TestAutoCode.Simple.Insert(
                    tests.Select((test, index) => new TestAutoCode.Simple {
                    ID = new Guid(index + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Code = test.Item1
                }));

                IEnumerable <string> generatedCodes = repository.TestAutoCode.Simple.Load()
                                                      .OrderBy(item => item.ID)
                                                      .Select(item => item.Code);

                IEnumerable <string> expectedCodes = tests.Select(test => test.Item2);

                Assert.AreEqual(TestUtility.Dump(expectedCodes), TestUtility.Dump(generatedCodes));
            }
        }
Пример #56
0
        public void InsertMultipleItems()
        {
            using (var container = new RhetosTestContainer())
            {
                DeleteOldData(container);
                var repository = container.Resolve <Common.DomRepository>();

                var tests = new List <Tuple <string, string> >
                {
                    Tuple.Create("+", "10"), // Exactly specified values are considered before generated values, therefore this item is handled after core "9".
                    Tuple.Create("+", "11"),
                    Tuple.Create("+", "12"),
                    Tuple.Create("9", "9"),
                    Tuple.Create("+", "13"),
                    Tuple.Create("+", "14"),
                    Tuple.Create("AB+", "AB1000"),
                    Tuple.Create("X", "X"),
                    Tuple.Create("X+", "X1"),
                    Tuple.Create("AB007", "AB007"),
                    Tuple.Create("AB+", "AB1001"),
                    Tuple.Create("AB999", "AB999"),
                    Tuple.Create("AB+", "AB1002"),
                };

                repository.TestAutoCodeCached.Simple.Insert(
                    tests.Select((test, index) => new TestAutoCodeCached.Simple {
                    ID = Guid.NewGuid(), Code = test.Item1, Data = index.ToString()
                }));

                IEnumerable <string> generatedCodes = repository.TestAutoCodeCached.Simple.Load()
                                                      .OrderBy(item => int.Parse(item.Data))
                                                      .Select(item => item.Code);

                IEnumerable <string> expectedCodes = tests.Select(test => test.Item2);

                Assert.AreEqual(TestUtility.Dump(expectedCodes), TestUtility.Dump(generatedCodes));
            }
        }
Пример #57
0
        public void NotNullColumn()
        {
            using (var container = new RhetosTestContainer())
            {
                var sqlExecuter = container.Resolve <ISqlExecuter>();
                sqlExecuter.ExecuteSql(new[] {
                    "DELETE FROM TestSqlWorkarounds.HasNotNullProperty",
                    "INSERT INTO TestSqlWorkarounds.HasNotNullProperty (Name, Code) SELECT 'a', 1"
                });

                var repository = container.Resolve <Common.DomRepository>();

                Assert.AreEqual("a1", TestUtility.DumpSorted(repository.TestSqlWorkarounds.HasNotNullProperty.Query(), item => item.Name + item.Code));

                TestUtility.ShouldFail(
                    () => sqlExecuter.ExecuteSql(new[] { "INSERT INTO TestSqlWorkarounds.HasNotNullProperty (Name) SELECT 'b'" }),
                    "Cannot insert the value NULL into column 'Code', table '", ".TestSqlWorkarounds.HasNotNullProperty'");

                TestUtility.ShouldFail(
                    () => sqlExecuter.ExecuteSql(new[] { "INSERT INTO TestSqlWorkarounds.HasNotNullProperty (Code) SELECT 2" }),
                    "Cannot insert the value NULL into column 'Name', table '", ".TestSqlWorkarounds.HasNotNullProperty'");
            }
        }
Пример #58
0
        public void SimpleWithPredefinedSuffixLength2()
        {
            using (var container = new RhetosTestContainer())
            {
                DeleteOldData(container);
                var repository = container.Resolve <Common.DomRepository>();

                TestSimple(container, repository, "+++", "001");
                TestSimple(container, repository, "+", "002");

                TestSimple(container, repository, "AB99", "AB99");
                TestSimple(container, repository, "AB++", "AB100");

                TestSimple(container, repository, "AB999", "AB999");
                TestSimple(container, repository, "AB++++++", "AB001000");

                TestSimple(container, repository, "B999", "B999");
                TestSimple(container, repository, "B++", "B1000");

                TestSimple(container, repository, "C500", "C500");
                TestSimple(container, repository, "C++", "C501");
            }
        }
Пример #59
0
        public void InsertTransient()
        {
            using (var container = new RhetosTestContainer())
            {
                var context    = container.Resolve <Common.ExecutionContext>();
                var repository = container.Resolve <Common.DomRepository>();

                var b = new TestEntity.BaseEntity {
                    ID = Guid.NewGuid(), Name = "b"
                };
                var c = new TestEntity.Child {
                    Name = "c", ParentID = b.ID
                };
                repository.TestEntity.BaseEntity.Insert(b);
                repository.TestEntity.Child.Insert(c);

                Assert.AreNotEqual(default(Guid), c.ID);

                var report = repository.TestEntity.Child.Query().Where(item => item.ID == c.ID)
                             .Select(item => item.Name + " " + item.Parent.Name);
                Assert.AreEqual("c b", TestUtility.DumpSorted(report));
            }
        }
Пример #60
0
        public void DateTimeTest()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql("DELETE FROM TestTypes.Simple");
                var repository = container.Resolve <Common.DomRepository>();

                for (int i = 0; i < 7; i++)
                {
                    DateTime testTime = new DateTime(2013, 10, 27, 10, 45, 54, i * 1000 / 7);

                    var item = new TestTypes.Simple {
                        Start = testTime
                    };
                    repository.TestTypes.Simple.Insert(item);

                    var loaded = repository.TestTypes.Reader.Load().Single();
                    AssertIsNear(testTime, loaded.Start.Value);

                    repository.TestTypes.Simple.Delete(item);
                }
            }
        }