コード例 #1
0
ファイル: LockPropertyTest.cs プロジェクト: koav/Rhetos
        public void UpdateLockedData()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = new Common.DomRepository(executionContext);

                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);
            }
        }
コード例 #2
0
ファイル: EntityTest.cs プロジェクト: koav/Rhetos
        public void CascadeDelete()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var repository = new Common.DomRepository(executionContext);

                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();

                executionContext.SqlExecuter.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));
            }
        }
コード例 #3
0
ファイル: LockItemsTest.cs プロジェクト: koav/Rhetos
        public void DeleteModifiedPersistentObject()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = new Common.DomRepository(executionContext);

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

                    AssertData("s3_lock", repository);
                    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);
                    executionContext.NHibernateSession.Clear();
                    AssertData("s3_lock", repository);
                }
            }
        }
コード例 #4
0
ファイル: LockPropertyTest.cs プロジェクト: koav/Rhetos
        public void UpdateLockedDataReference()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
                var repository = new Common.DomRepository(executionContext);
                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);
            }
        }
コード例 #5
0
ファイル: HierarchyTest.cs プロジェクト: quocngo2cs/Rhetos
        private static void PrepareSimpleData(Common.DomRepository repository, string treeDescription)
        {
            repository.TestHierarchy.Simple.Delete(repository.TestHierarchy.Simple.All());

            var items = new Dictionary <string, TestHierarchy.Simple>();

            var inputElements    = treeDescription.Split(',').Select(x => x.Trim()).ToArray();
            var rootNodes        = inputElements.Where(ni => !ni.Contains('-'));
            var parentChildEdges = inputElements.Where(ni => ni.Contains('-')).Select(edge =>
            {
                var split = edge.Split('-');
                return(new { Parent = split[0], Child = split[1] });
            });

            foreach (string node in rootNodes)
            {
                items.Add(node, new TestHierarchy.Simple {
                    ID = Guid.NewGuid(), Name = node
                });
            }

            foreach (var node in parentChildEdges)
            {
                items.Add(node.Child, new TestHierarchy.Simple {
                    ID = Guid.NewGuid(), Name = node.Child
                });
            }

            foreach (var node in parentChildEdges)
            {
                items[node.Child].ParentID = items[node.Parent].ID;
            }

            repository.TestHierarchy.Simple.Insert(items.Values);
        }
コード例 #6
0
ファイル: ClaimRepositoryTest.cs プロジェクト: koav/Rhetos
        public void CRUD()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var repository = new Common.DomRepository(executionContext);
                var unitTestClaims = repository.Common.Claim.Query().Where(c => c.ClaimResource.StartsWith("unittest_")).ToList();
                Console.WriteLine("Delete old: " + TestUtility.DumpSorted(unitTestClaims, c => c.ClaimResource + "." + c.ClaimRight) + ".");
                repository.Common.Claim.Delete(unitTestClaims);

                IClaimRepository cr = repository.Common.Claim;
                var c1 = new Claim("unittest_c1", "c11");
                var c2 = new Claim("unittest_c2", "c22");
                var c3 = new Claim("unittest_c3", "c33");
                cr.SaveClaims(new[] { c1, c2, c3 }, new ICommonClaim[] {}, new ICommonClaim[] {});

                var loaded = cr.LoadClaims().Where(c => c.ClaimResource.StartsWith("unittest_")).ToList();
                loaded.Sort((cl1, cl2) => cl1.ClaimResource.CompareTo(cl2.ClaimResource));
                Assert.AreEqual("c11, c22, c33", TestUtility.Dump(loaded, c => c.ClaimRight));

                loaded[0].ClaimRight = loaded[0].ClaimRight.ToUpper();
                var c4 = new Claim("unittest_c4", "c44");
                cr.SaveClaims(new[] { c4 }, new[] { loaded[0] }, new[] { loaded[1] });

                loaded = cr.LoadClaims().Where(c => c.ClaimResource.StartsWith("unittest_")).ToList();
                loaded.Sort((cl1, cl2) => cl1.ClaimResource.CompareTo(cl2.ClaimResource));
                Assert.AreEqual("C11, c33, c44", TestUtility.Dump(loaded, c => c.ClaimRight));
            }
        }
コード例 #7
0
ファイル: BrowseTest.cs プロジェクト: koav/Rhetos
        public void NullReference()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var repository = new Common.DomRepository(executionContext);

                Guid refID = Guid.NewGuid();
                executionContext.SqlExecuter.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");
            }
        }
コード例 #8
0
 private static int SimpleNumParts(Common.DomRepository repository, string documentName)
 {
     return(repository.Test9.Document.Query()
            .Where(d => d.Name == documentName)
            .Select(d => d.Extension_DocumentSimpleAggregate.NumParts)
            .Single().Value);
 }
コード例 #9
0
ファイル: DeactivatableTest.cs プロジェクト: koav/Rhetos
        public void ActivePropertyValueDoesNotHaveToBeDefinedOnUpdate()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var id1 = Guid.NewGuid();
                var id2 = Guid.NewGuid();
                var id3 = Guid.NewGuid();
                executionContext.SqlExecuter.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 = new Common.DomRepository(executionContext);
                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));
            }
        }
コード例 #10
0
        public void ComputeForNewBaseItems_InvalidCommand()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var repository = new Common.DomRepository(executionContext);

                var d1ID = Guid.NewGuid();
                var d2ID = Guid.NewGuid();
                executionContext.SqlExecuter.ExecuteSql(new[]
                    {
                        "DELETE FROM Test9.Document;",
                        "DELETE FROM Test9.DocumentCreationInfo;",
                        "INSERT INTO Test9.Document (ID, Name) SELECT '" + d1ID + "', 'd1'",
                        "INSERT INTO Test9.Document (ID, Name) SELECT '" + d2ID + "', 'd2'",
                        "INSERT INTO Test9.DocumentCreationInfo (ID, Rank) SELECT '" + d1ID + "', 1",
                        "INSERT INTO Test9.DocumentCreationInfo (ID, Rank) SELECT '" + d2ID + "', 2",
                    });

                Assert.AreEqual("d1:1, d2:2", ReportDocumentCreationInfo(repository), "initial");

                var documents = repository.Test9.Document;

                TestUtility.ShouldFail(() => documents.Insert(new[] { new Test9.Document { ID = d1ID, Name = "d1" } }), "existing");
                Assert.AreEqual("d1:1, d2:2", ReportDocumentCreationInfo(repository), "creation info of previously inserted documents shoud not be changed");

                // TODO: Instead of using the wrapper 'Save' function to check data validations, we should handle insert/update/delete events (NHibernate event listener) for faster and more reliable validations.
                TestUtility.ShouldFail(() => documents.Update(new[] { new Test9.Document { ID = Guid.NewGuid(), Name = "d3" } }));
                Assert.AreEqual("d1:1, d2:2", ReportDocumentCreationInfo(repository), "creation info of previously inserted documents shoud not be changed");
            }
        }
コード例 #11
0
        public void ComputeForNewBaseItems()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var repository = new Common.DomRepository(executionContext);

                var d1ID = Guid.NewGuid();
                executionContext.SqlExecuter.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");
            }
        }
コード例 #12
0
        private static string ReportDocumentAggregates(Common.DomRepository repository)
        {
            var    loadedData = repository.Test9.DocumentAggregates.Query().Select(item => item.NameNumParts).ToList();
            string report     = string.Join(", ", loadedData.OrderBy(s => s));

            Console.WriteLine(report);
            return(report);
        }
コード例 #13
0
 private string DumpSimple(Common.DomRepository repository)
 {
     return(TestUtility.DumpSorted(
                repository.TestDenyUserEdit.Simple.Query(),
                item => (item.Editable ?? "null")
                + " " + (item.NonEditable ?? "null")
                + " " + (item.NonEditableReference != null ? item.NonEditableReference.Name : "null")));
 }
コード例 #14
0
ファイル: LegacyEntityTest.cs プロジェクト: tjakopovic/Rhetos
        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)));
        }
コード例 #15
0
ファイル: EntityTest.cs プロジェクト: oklancir/Rhetos
        private static string ReportClaims(Common.DomRepository repository)
        {
            var loaded = repository.TestEntity.Claim.Load();
            var report = TestUtility.DumpSorted(loaded, claim => claim.ClaimResource + "-" + claim.ClaimRight);

            Console.WriteLine("Report: " + report);
            return(report);
        }
コード例 #16
0
        private static string ReportDocumentCreationInfo(Common.DomRepository repository)
        {
            var    loadedData = repository.Test9.DocumentCreationInfo.Query().Select(item => item.Base.Name + ":" + item.Rank).ToList();
            string report     = string.Join(", ", loadedData.OrderBy(s => s));

            Console.WriteLine(report);
            return(report);
        }
コード例 #17
0
        private static string ReportPersisted(Common.DomRepository repository)
        {
            var    loadedData = repository.Test6.Pers.Query().Select(item => item.Name + item.Num.CastToString()).ToList();
            string report     = string.Join(", ", loadedData.OrderBy(s => s));

            Console.WriteLine(report);
            return(report);
        }
コード例 #18
0
ファイル: ModuleRepositioryTest.cs プロジェクト: koav/Rhetos
 public void DomRepositoryHasModuleRepositories()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         Assert.IsNotNull(repository.TestDataStructure);
     }
 }
コード例 #19
0
ファイル: RegExMatchTest.cs プロジェクト: koav/Rhetos
 public void EmptyValuesAreAllowed()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new Simple { StringFrom200To249 = null };
         repository.TestRegex.Simple.Insert(new[] { entity });
     }
 }
コード例 #20
0
ファイル: MaxLengthTest.cs プロジェクト: koav/Rhetos
 public void ShouldThowUserExceptionOnInsert()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new SimpleMaxLength { StringLessThan10Chars = "More than 10 characters." };
         repository.TestLengthLimit.SimpleMaxLength.Insert(new[] { entity });
     }
 }
コード例 #21
0
ファイル: MaxValueTest.cs プロジェクト: koav/Rhetos
 public void NormallyInsertDecimal()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new SimpleDecimal { Value = (decimal)2.30 };
         repository.TestMaxValue.SimpleDecimal.Insert(new[] { entity });
     }
 }
コード例 #22
0
ファイル: MaxValueTest.cs プロジェクト: koav/Rhetos
 public void NormallyInsertDateTime()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new SimpleDateTime { Value = new DateTime(2013, 7, 5, 12, 33, 1) };
         repository.TestMaxValue.SimpleDateTime.Insert(new[] { entity });
     }
 }
コード例 #23
0
ファイル: MinLengthTest.cs プロジェクト: koav/Rhetos
 public void ShouldThowUserExceptionOnUpdate()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new SimpleMinLength { StringMoreThan2Chars = "." };
         repository.TestLengthLimit.SimpleMinLength.Update(new[] { entity });
     }
 }
コード例 #24
0
ファイル: MaxValueTest.cs プロジェクト: koav/Rhetos
 public void NormallyInsertInteger()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new SimpleInteger { Value = 1 };
         repository.TestMaxValue.SimpleInteger.Insert(new[] { entity });
     }
 }
コード例 #25
0
ファイル: RangeTest.cs プロジェクト: koav/Rhetos
 public void ShouldThowUserExceptionOnInsert()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new SimpleRange { FromValue = 1, ToValue = 0 };
         repository.TestRange.SimpleRange.Insert(new[] { entity });
     }
 }
コード例 #26
0
ファイル: SqlQueryableTest.cs プロジェクト: koav/Rhetos
        public void QueryableFromRepository()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var repository = new Common.DomRepository(executionContext);

                var secondString = repository.TestDataStructure.SqlQueryable1.Query().Where(item => item.i == 2).Select(item => item.s).Single();
                Assert.AreEqual("b", secondString);
            }
        }
コード例 #27
0
ファイル: DenySaveTest.cs プロジェクト: koav/Rhetos
        public void InsertValidAndInvalidData()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestDenySave.Simple;" });
                var repository = new Common.DomRepository(executionContext);

                TestUtility.ShouldFail(() => repository.TestDenySave.Simple.Insert(CreateSimple(3, 300)), "larger than 100");
            }
        }
コード例 #28
0
ファイル: RequiredPropertyTest.cs プロジェクト: koav/Rhetos
        public void NullString()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestRequired.Simple" });
                var repository = new Common.DomRepository(executionContext);

                TestUtility.ShouldFail(() => repository.TestRequired.Simple.Insert(new[] { new TestRequired.Simple { Count = 4, Name = null } }), "required", "Name");
            }
        }
コード例 #29
0
        private static void FilterIdentifierArray(Common.DomRepository repository, string operation, Guid[] values, Guid[] expectedValues)
        {
            Console.WriteLine("TEST Identifier: " + operation + " " + string.Join(", ", expectedValues.Select(x => x.ToString())));
            var source = repository.TestGenericFilter.Simple.Query();
            var result = GenericFilterHelperFilter(source, new[] { new FilterCriteria {
                                                                       Property = "Identifier", Operation = operation, Value = values
                                                                   } });

            Assert.AreEqual(TestUtility.DumpSorted(expectedValues.Select(x => x.ToString())), TestUtility.DumpSorted(result, item => item.Identifier.ToString()));
        }
コード例 #30
0
ファイル: ActionTest.cs プロジェクト: koav/Rhetos
 public void ThrowException()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         TestUtility.ShouldFail(
             () => repository.TestAction.ThrowException.Execute(new TestAction.ThrowException { Message = "abcd" }),
             "abcd");
     }
 }
コード例 #31
0
        private static void FilterStartDateNotIn(Common.DomRepository repository, string value, string expectedCodes)
        {
            Console.WriteLine("TEST DateIn: " + value);
            var source = repository.TestGenericFilter.Simple.Query();
            var result = GenericFilterHelperFilter(source, new[] { new FilterCriteria {
                                                                       Property = "Start", Operation = "DateNotIn", Value = value
                                                                   } });

            Assert.AreEqual(expectedCodes, TestUtility.DumpSorted(result, item => item.Code.ToString()));
        }
コード例 #32
0
ファイル: RangeTest.cs プロジェクト: koav/Rhetos
 public void ShouldInsertNormallyJustOneDate()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new DateRangeWithoutDef { FromDate = DateTime.Today };
         var entity2 = new DateRangeWithoutDef { ToDate = DateTime.Today };
         repository.TestRange.DateRangeWithoutDef.Insert(new[] { entity, entity2 });
     }
 }
コード例 #33
0
ファイル: LoggingTest.cs プロジェクト: koav/Rhetos
        public void Complex()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[]
                    {
                        "DELETE FROM TestLogging.Complex",
                        "DELETE FROM TestLogging.Simple",
                    });
                var repository = new Common.DomRepository(executionContext);
                var id = Guid.NewGuid();

                var simple = new TestLogging.Simple { ID = Guid.NewGuid() };
                repository.TestLogging.Simple.Insert(new[] { simple });

                var complex = new TestLogging.Complex
                {
                    bi = new byte[] { 1, 2, 3 },
                    bo = true,
                    da = new DateTime(2001, 2, 3),
                    t = new DateTime(2001, 2, 3, 4, 5, 6),
                    de = 123.4567m,
                    g = Guid.NewGuid(),
                    ls = "abc",
                    m = 11.22m,
                    r = simple
                };
                repository.TestLogging.Complex.Insert(new[] { complex });
                complex.ls = "def";
                repository.TestLogging.Complex.Update(new[] { complex });
                repository.TestLogging.Complex.Delete(new[] { complex });

                var ids = new Guid?[] { simple.ID, complex.ID };

                var ins = repository.Common.Log.Query().Where(log => log.TableName == "TestLogging.Complex" && log.Action == "Insert" && ids.Contains(log.ItemId)).Single();
                var upd = repository.Common.Log.Query().Where(log => log.TableName == "TestLogging.Complex" && log.Action == "Update" && ids.Contains(log.ItemId)).Single();
                var del = repository.Common.Log.Query().Where(log => log.TableName == "TestLogging.Complex" && log.Action == "Delete" && ids.Contains(log.ItemId)).Single();

                Assert.AreEqual("", ins.Description);
                Assert.AreEqual(@"<PREVIOUS ls=""abc"" />", upd.Description);

                var description = del.Description.Split(' ');
                Assert.AreEqual(@"<PREVIOUS", description[0]);
                Assert.AreEqual(@"bi=""0x010203""", description[1]);
                Assert.AreEqual(@"bo=""1""", description[2]);
                Assert.AreEqual(@"da=""2001-02-03""", description[3]);
                Assert.IsTrue(new Regex(@"^t=""2001-02-03T04:05:06(.0+)?""$").IsMatch(description[4]));// optional millisconds
                Assert.IsTrue(new Regex(@"^de=""123\.45670*""$").IsMatch(description[5]));// optional additional zeros
                Assert.AreEqual(@"g=""" + SqlUtility.GuidToString(complex.g.Value) + @"""", description[6]);
                Assert.AreEqual(@"ls=""def""", description[7]);
                Assert.AreEqual(@"m=""11.2200""", description[8]);
                Assert.AreEqual(@"rID=""" + SqlUtility.GuidToString(simple.ID) + @"""", description[9]);
                Assert.AreEqual(@"/>", description[10]);
            }
        }
コード例 #34
0
ファイル: RegExMatchTest.cs プロジェクト: koav/Rhetos
 public void EmptyValuesAreNotAllowedIfRequiredSet()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new SimpleRequired { StringFrom200To249 = null };
         TestUtility.ShouldFail(
             () => repository.TestRegex.SimpleRequired.Insert(new[] { entity }),
             "UserException", "Required", "Property:StringFrom200To249");
     }
 }
コード例 #35
0
ファイル: SqlFilter.cs プロジェクト: koav/Rhetos
 public void Spike2_NHInitializationTime()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestSqlFilter.Simple" });
         var repository = new Common.DomRepository(executionContext);
         var result = repository.TestSqlFilter.Simple.All();
         var report = string.Join("|", result.Select(item => item.Code + ", " + item.Start.Value.ToString("s")));
         Assert.AreEqual("", report);
     }
 }
コード例 #36
0
ファイル: ActionTest.cs プロジェクト: koav/Rhetos
 public void UseExecutionContext()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         Assert.IsTrue(executionContext.UserInfo.UserName.Length > 0);
         var repository = new Common.DomRepository(executionContext);
         TestUtility.ShouldFail(
             () => repository.TestAction.UEC.Execute(new TestAction.UEC { }),
             "User " + executionContext.UserInfo.UserName);
     }
 }
コード例 #37
0
ファイル: DenyUserEditTest.cs プロジェクト: koav/Rhetos
        public void HardcodedEntity_Insert()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var repository = new Common.DomRepository(executionContext);

                TestUtility.ShouldFail(
                    () => repository.TestDenyUserEdit.Hardcoded.Save(new[] { new TestDenyUserEdit.Hardcoded { Name = "abc" } }, null, null, true),
                    "It is not allowed to directly modify TestDenyUserEdit.Hardcoded.");
            }
        }
コード例 #38
0
        private static void FilterCode(Common.DomRepository repository, string operation, string value, string expectedCodes)
        {
            Console.WriteLine("TEST CODE: " + operation + " " + value);
            var source = repository.TestGenericFilter.Simple.Query();
            var result = GenericFilterHelperFilter(source, new[] { new FilterCriteria {
                                                                       Property = "Code", Operation = operation, Value =
                                                                           SameTypeOperations.Contains(operation) ? (object)int.Parse(value) : value
                                                                   } });

            Assert.AreEqual(expectedCodes, TestUtility.DumpSorted(result, item => item.Code.ToString()));
        }
コード例 #39
0
ファイル: ComputedTest.cs プロジェクト: koav/Rhetos
        public void SpecialLoad()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var repository = new Common.DomRepository(executionContext);

                var paremeter = new TestComputed.SpecialLoad { SpecialName = "spec" };
                var loaded = repository.TestComputed.Simple.Filter(paremeter);
                Assert.AreEqual("spec", TestUtility.DumpSorted(loaded, item => item.Name));
            }
        }
コード例 #40
0
ファイル: RequiredPropertyTest.cs プロジェクト: koav/Rhetos
        public void ValidData()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestRequired.Simple" });
                var repository = new Common.DomRepository(executionContext);

                repository.TestRequired.Simple.Insert(new[] { new TestRequired.Simple { Count = 1, Name = "test1" } });
                repository.TestRequired.Simple.Insert(new[] { new TestRequired.Simple { Count = 0, Name = "test2" } });
                Assert.AreEqual("0-test2, 1-test1", TestUtility.DumpSorted(repository.TestRequired.Simple.All(), item => item.Count + "-" + item.Name));
            }
        }
コード例 #41
0
ファイル: DeactivatableTest.cs プロジェクト: koav/Rhetos
 public void ActivePropertyValueDoesNotHaveToBeDefinedOnInsert()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         executionContext.SqlExecuter.ExecuteSql(new[] {
             "DELETE FROM TestDeactivatable.BasicEnt" });
         var repository = new Common.DomRepository(executionContext);
         var entity = new BasicEnt { Name = "ttt" };
         repository.TestDeactivatable.BasicEnt.Insert(new[] { entity });
         Assert.AreEqual(true, repository.TestDeactivatable.BasicEnt.All().Single().Active);
     }
 }
コード例 #42
0
        private static void TestIntAutoCode(RhetosTestContainer container, Common.DomRepository repository, int?input, int expectedCode)
        {
            Guid id = Guid.NewGuid();

            repository.TestAutoCode.IntegerAutoCode.Insert(new[] { new TestAutoCode.IntegerAutoCode {
                                                                       ID = id, Code = input
                                                                   } });

            int?generatedCode = repository.TestAutoCode.IntegerAutoCode.Query().Where(item => item.ID == id).Select(item => item.Code).Single();

            Console.WriteLine(input.ToString() + " => " + generatedCode.ToString());
            Assert.AreEqual(expectedCode, generatedCode);
        }
コード例 #43
0
        private static void TestSimple(RhetosTestContainer container, Common.DomRepository repository, string format, string expectedCode)
        {
            Guid id = Guid.NewGuid();

            repository.TestAutoCode.Simple.Insert(new[] { new TestAutoCode.Simple {
                                                              ID = id, Code = format
                                                          } });

            string generatedCode = repository.TestAutoCode.Simple.Query().Where(item => item.ID == id).Select(item => item.Code).Single();

            Console.WriteLine(format + " => " + generatedCode);
            Assert.AreEqual(expectedCode, generatedCode);
        }
コード例 #44
0
        private static void TestSimple(RhetosTestContainer container, Common.DomRepository repository, string format, string expectedCode)
        {
            Guid id = Guid.NewGuid();

            repository.TestAutoCodeCached.Simple.Insert(new[] { new TestAutoCodeCached.Simple {
                                                                    ID = id, Code = format
                                                                } });

            container.Resolve <Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

            string generatedCode = repository.TestAutoCodeCached.Simple.Query().Where(item => item.ID == id).Select(item => item.Code).Single();

            Console.WriteLine(format + " => " + generatedCode);
            Assert.AreEqual(expectedCode, generatedCode);
        }
コード例 #45
0
ファイル: AutoCodeTest.cs プロジェクト: tjakopovic/Rhetos
        private static void TestDoubleAutoCode(RhetosTestContainer container, Common.DomRepository repository, string formatA, string formatB, string expectedCodes)
        {
            Guid id = Guid.NewGuid();

            repository.TestAutoCode.DoubleAutoCode.Insert(new[] { new TestAutoCode.DoubleAutoCode {
                                                                      ID = id, CodeA = formatA, CodeB = formatB
                                                                  } });

            container.Resolve <Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

            string generatedCodes = repository.TestAutoCode.DoubleAutoCode.Query().Where(item => item.ID == id).Select(item => item.CodeA + "," + item.CodeB).Single();

            Console.WriteLine(formatA + "," + formatB + " => " + generatedCodes);
            Assert.AreEqual(expectedCodes, generatedCodes);
        }
コード例 #46
0
        private static void TestDoubleAutoCode(Common.DomRepository repository, string formatA, string formatB, string expectedCodes)
        {
            Guid id = Guid.NewGuid();

            repository.TestAutoCode.DoubleAutoCode.Insert(new[] { new TestAutoCode.DoubleAutoCode {
                                                                      ID = id, CodeA = formatA, CodeB = formatB
                                                                  } });

            string generatedCodes = repository.TestAutoCode.DoubleAutoCode.Query()
                                    .Where(item => item.ID == id)
                                    .Select(item => item.CodeA + "," + item.CodeB).Single();

            Console.WriteLine(formatA + "," + formatB + " => " + generatedCodes);
            Assert.AreEqual(expectedCodes, generatedCodes);
        }
コード例 #47
0
        private static void TestDoubleIntegerAutoCodeWithGroup(Common.DomRepository repository, int group, int?codeA, int?codeB, string expectedCodes)
        {
            Guid id = Guid.NewGuid();

            repository.TestAutoCode.IntegerAutoCodeForEach.Insert(new[] {
                new TestAutoCode.IntegerAutoCodeForEach {
                    ID = id, Grouping = group, CodeA = codeA, CodeB = codeB
                }
            });

            string generatedCodes = repository.TestAutoCode.IntegerAutoCodeForEach.Query()
                                    .Where(item => item.ID == id)
                                    .Select(item => item.CodeA.ToString() + "," + item.CodeB.ToString()).Single();

            Console.WriteLine(codeA.ToString() + "," + codeB.ToString() + " => " + generatedCodes);
            Assert.AreEqual(expectedCodes, generatedCodes);
        }
コード例 #48
0
ファイル: UniqueTest.cs プロジェクト: quocngo2cs/Rhetos
 public EntityHelper(RhetosTestContainer container)
 {
     _executionContext = container.Resolve <Common.ExecutionContext>();
     _repository       = container.Resolve <Common.DomRepository>();
 }
コード例 #49
0
ファイル: AutoCodeTest.cs プロジェクト: tjakopovic/Rhetos
        private static void TestDoubleIntegerAutoCodeWithGroup(RhetosTestContainer container, Common.DomRepository repository, int group, int codeA, int codeB, string expectedCodes)
        {
            Guid id = Guid.NewGuid();

            repository.TestAutoCode.IntegerAutoCodeForEach.Insert(new[] { new TestAutoCode.IntegerAutoCodeForEach {
                                                                              ID = id, Grouping = group, CodeA = codeA, CodeB = codeB
                                                                          } });

            container.Resolve <Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

            string generatedCodes = repository.TestAutoCode.IntegerAutoCodeForEach.Query().Where(item => item.ID == id).Select(item => item.CodeA.ToString() + "," + item.CodeB.ToString()).Single();

            Console.WriteLine(codeA.ToString() + "," + codeB.ToString() + " => " + generatedCodes);
            Assert.AreEqual(expectedCodes, generatedCodes);
        }
コード例 #50
0
ファイル: UniqueTest.cs プロジェクト: tjakopovic/Rhetos
 public EntityHelperMultiple(RhetosTestContainer container, Common.DomRepository repository)
 {
     _repository = container.Resolve <Common.DomRepository>();
 }
コード例 #51
0
 public EntityHelper(UnitOfWorkScope scope)
 {
     _executionContext = scope.Resolve <Common.ExecutionContext>();
     _repository       = scope.Resolve <Common.DomRepository>();
 }
コード例 #52
0
 private void TestReleaseLock(Common.ReleaseLock parameters, Common.DomRepository repository)
 {
     repository.Common.ReleaseLock.Execute(parameters);
 }
コード例 #53
0
ファイル: SqlQueryableTest.cs プロジェクト: oklancir/Rhetos
 private static string ReportCachingTestView(Common.DomRepository repository)
 {
     return(string.Join(", ", repository.TestDataStructure.CachingTestView.Query().Select(item => item.S).OrderBy(x => x)));
 }
コード例 #54
0
        static string ReportLegacy1(UnitOfWorkScope scope, Common.DomRepository domRepository)
        {
            var loaded = domRepository.Test13.Legacy1.Query().Select(l1 => l1.Name);

            return(string.Join(", ", loaded.OrderBy(x => x)));
        }
コード例 #55
0
        static string ReportLegacy2(UnitOfWorkScope scope, Common.DomRepository domRepository)
        {
            var loaded = domRepository.Test13.Legacy2.Query().Select(l2 => l2.Leg1.Name + " " + l2.NameNew + " " + l2.Same);

            return(string.Join(", ", loaded.OrderBy(x => x)));
        }
コード例 #56
0
 private void TestReleaseLock(Common.ReleaseLock parameters, Common.DomRepository repository, Rhetos.Utilities.IUserInfo userInfo)
 {
     repository.Common.ReleaseLock.Execute(parameters);
 }
コード例 #57
0
        static string ReportLegacy2(RhetosTestContainer container, Common.DomRepository domRepository)
        {
            var loaded = domRepository.Test13.Legacy2.Query().Select(l2 => l2.Leg1.Name + " " + l2.NameNew + " " + l2.Same);

            return(string.Join(", ", loaded.OrderBy(x => x)));
        }
コード例 #58
0
 private static void AssertData(Common.DomRepository repository, string expected)
 {
     Assert.AreEqual(expected, TestUtility.DumpSorted(repository.TestInvalidData.Simple.Query(), item => item.Name));
 }
コード例 #59
0
ファイル: HierarchyTest.cs プロジェクト: quocngo2cs/Rhetos
 private static string ReportSimple(Common.DomRepository repository)
 {
     return(ReportSimple(repository.TestHierarchy.Simple.Query()));
 }
コード例 #60
0
        static string ReportLegacy1(RhetosTestContainer container, Common.DomRepository domRepository)
        {
            var loaded = domRepository.Test13.Legacy1.Query().Select(l1 => l1.Name);

            return(string.Join(", ", loaded.OrderBy(x => x)));
        }