public void ShortStringPropertyTooLong() { using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); var tests = new List <string> { new string('a', 257), new string('a', 17000), }; foreach (var test in tests) { var entity1 = new TestStorage.AllProperties { ID = Guid.NewGuid(), ShortStringProperty = test }; TestUtility.ShouldFail <SqlException>( () => context.PersistenceStorage.Insert(entity1), "String or binary data would be truncated"); // SQL Server 2019 includes table and column name, but older version do not. } } }
public void AutoFilter_Simple() { using (var scope = TestScope.Create()) { var repository = scope.Resolve <Common.DomRepository>(); repository.TestFilter.AutoFilter1.Delete(repository.TestFilter.AutoFilter1.Query()); repository.TestFilter.AutoFilter2.Delete(repository.TestFilter.AutoFilter2.Query()); repository.TestFilter.AutoFilter1.Insert( new[] { "a1", "a2", "b1", "b2" } .Select(name => new TestFilter.AutoFilter1 { Name = name })); repository.TestFilter.AutoFilter2.Insert( new[] { "a1", "a2", "b1", "b2" } .Select(name => new TestFilter.AutoFilter2 { Name = name })); TestClientRead <TestFilter.AutoFilter1>(scope, "a1, a2", item => item.Name); TestClientRead <TestFilter.AutoFilter2>(scope, "a1, a2, b1, b2", item => item.Name); TestClientRead <TestFilter.AutoFilter2Browse>(scope, "b1x, b2x", item => item.Name2); } }
public void Dependant_FKConstraintDeleteUniqueReferenced() { using (var scope = TestScope.Create()) { var repository = scope.Resolve <Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { Name = "s1", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var d1 = new TestPolymorphic.DependantUniqueReference { Name = "d1", ID = s1.ID }; repository.TestPolymorphic.DependantUniqueReference.Insert(new[] { d1 }); Assert.AreEqual("s1-d1", TestUtility.DumpSorted( repository.TestPolymorphic.SimpleBase.Query(new[] { d1.ID }), item => item.Name + "-" + item.Extension_DependantUniqueReference.Name)); var ex = TestUtility.ShouldFail <Rhetos.UserException>( () => repository.TestPolymorphic.Simple1.Delete(new[] { s1 }), "It is not allowed to delete"); TestUtility.AssertContains(ex.ToString(), new[] { "DependantUniqueReference", "REFERENCE", "SimpleBase" }, "Expected inner SQL exception"); } }
public void FilterByReferencedAndLinkedItems() { using (var scope = TestScope.Create()) { scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestFilter.Source" }); var repository = scope.Resolve <Common.DomRepository>(); var s1 = new TestFilter.Source { Name = "A s1" }; var s2 = new TestFilter.Source { Name = "B s2" }; repository.TestFilter.Source.Insert(new[] { s1, s2 }); var d1 = new TestFilter.SourceDetail { ParentID = s1.ID, Name2 = "C d1" }; var d2 = new TestFilter.SourceDetail { ParentID = s2.ID, Name2 = "D d2" }; repository.TestFilter.SourceDetail.Insert(new[] { d1, d2 }); var filteredDetailByMaster = repository.TestFilter.SourceDetail.Filter(new TestFilter.FilterByPrefix { Prefix = "A" }); Assert.AreEqual("C d1", TestUtility.DumpSorted(filteredDetailByMaster, item => item.Name2)); var filteredMasterByDetail = repository.TestFilter.Source.Filter(new TestFilter.FilterDetail { Prefix = "C" }); Assert.AreEqual("A s1", TestUtility.DumpSorted(filteredMasterByDetail, item => item.Name)); } }
public void SimpleComposableFilterGenericFilterReferenced() { using (var scope = TestScope.Create()) { scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestFilter.CombinedFilters", "DELETE FROM TestFilter.Simple" }); var repository = scope.Resolve <Common.DomRepository>(); var refEnt = new TestFilter.Simple { Name = "test" }; repository.TestFilter.Simple.Insert(new[] { refEnt }); var s1 = new TestFilter.CombinedFilters { Name = "Abeceda", SimpleID = refEnt.ID }; var s2 = new TestFilter.CombinedFilters { Name = "abeceda" }; repository.TestFilter.CombinedFilters.Insert(new[] { s1, s2 }); // Containing "ece" and referenced object name contains "es" var filteredByContainsWithGenericFilter = ExecuteCommand(new ReadCommandInfo { DataSource = "TestFilter.CombinedFilters", Filters = new[] { new FilterCriteria(new TestFilter.ComposableFilterByContains { Pattern = "ece" }), new FilterCriteria("Simple.Name", "Contains", "es") }, ReadRecords = true, ReadTotalCount = true }, scope); Assert.AreEqual(1, filteredByContainsWithGenericFilter.Records.Length); } }
public void PersistentObjectIgnoredWhenVerifyingOldData() { using (var scope = TestScope.Create()) { scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;", "INSERT INTO TestLockItems.Simple (Name) VALUES ('abc locked')" }); var repository = scope.Resolve <Common.DomRepository>(); var s1 = repository.TestLockItems.Simple.Load().Single(); Assert.AreEqual("abc locked", s1.Name); s1.Name = "def"; TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1 }), "[Test] Name contains lock mark"); Assert.AreEqual("def", s1.Name); Assert.AreEqual("abc locked", repository.TestLockItems.Simple.Load().Single().Name); TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1 }), "[Test] Name contains lock mark"); Assert.AreEqual("def", s1.Name); Assert.AreEqual("abc locked", repository.TestLockItems.Simple.Load().Single().Name); TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Insert(new[] { s1 }), "Inserting a record that already exists in database."); Assert.AreEqual("def", s1.Name); Assert.AreEqual("abc locked", repository.TestLockItems.Simple.Load().Single().Name); } }
public void DataStructureReadParameters_Basic() { using (var scope = TestScope.Create()) { var readParameters = scope.Resolve <IDataStructureReadParameters>().GetReadParameters( "TestFilter.MultipleReadTypes", extendedSet: false); var expected = @" CommonFilter2: TestFilter.CommonFilter2 IEnumerable<MultipleReadTypes>: System.Collections.Generic.IEnumerable`1[TestFilter.MultipleReadTypes] List<TestFilter.MultipleReadTypes>: System.Collections.Generic.List`1[TestFilter.MultipleReadTypes] QueryFilter1: TestFilter.QueryFilter1 string[]: System.String[] System.Collections.Generic.IEnumerable<System.Guid>: System.Collections.Generic.IEnumerable`1[System.Guid] System.Guid: System.Guid TestFilter.CommonFilter2: TestFilter.CommonFilter2 TestFilter.FilterBy1: TestFilter.FilterBy1 TestFilter.ItemFilter1: TestFilter.ItemFilter1 TestFilter.Query1: TestFilter.Query1 "; Assert.AreEqual( string.Join("\r\n", expected.Split("\r\n").Where(line => !string.IsNullOrWhiteSpace(line)).OrderBy(x => x)), string.Join("\r\n", readParameters.Select(rp => rp.ToString()).OrderBy(x => x))); } }
public void RollbackByDefault() { var id1 = Guid.NewGuid(); TestUtility.ShouldFail <FrameworkException>(() => { using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); context.Repository.TestEntity.BaseEntity.Insert(new TestEntity.BaseEntity { ID = id1, Name = TestNamePrefix + Guid.NewGuid() }); throw new FrameworkException(nameof(RollbackByDefault)); // The exception that is not handled within transaction scope. #pragma warning disable CS0162 // Unreachable code detected scope.Resolve <IPersistenceTransaction>().CommitOnDispose(); #pragma warning restore CS0162 // Unreachable code detected } }, nameof(RollbackByDefault)); using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); Assert.IsFalse(context.Repository.TestEntity.BaseEntity.Query(new[] { id1 }).Any()); } }
public void TestForThisAndActiveItemsFilter() { using (var scope = TestScope.Create()) { scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestDeactivatable.BasicEnt;", }); var e1ID = Guid.NewGuid(); var repository = scope.Resolve <Common.DomRepository>(); var entity = new BasicEnt { ID = e1ID, Name = "ttt", Active = false }; var entity2 = new BasicEnt { Name = "ttt2", Active = true }; var entity3 = new BasicEnt { Name = "ttt3", Active = false }; repository.TestDeactivatable.BasicEnt.Insert(new[] { entity, entity2, entity3 }); Assert.AreEqual(1, repository.TestDeactivatable.BasicEnt.Query(new ActiveItems()).Count()); Assert.AreEqual(2, repository.TestDeactivatable.BasicEnt.Query(new ActiveItems { ItemID = e1ID }).Count()); } }
public void CommitAndCloseWithDiscard() { var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); TestUtility.ShouldFail <FrameworkException>(() => { using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); context.Repository.TestEntity.BaseEntity.Insert(new TestEntity.BaseEntity { ID = id1, Name = TestNamePrefix + Guid.NewGuid() }); scope.Resolve <IPersistenceTransaction>().DiscardOnDispose(); scope.CommitAndClose(); context.Repository.TestEntity.BaseEntity.Insert(new TestEntity.BaseEntity { ID = id2, Name = TestNamePrefix + Guid.NewGuid() }); } }, "disposed persistence transaction"); // CommitAndClose should close the transaction, even if it was discarded. using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); // CommitAndClose should rollback the transaction. var ids = new[] { id1, id2 }; Assert.AreEqual( "", TestUtility.DumpSorted(context.Repository.TestEntity.BaseEntity.Load(ids), item => item.ID)); } }
public void IndependentTransactions() { const int threadCount = 2; int initialCount; using (var scope = TestScope.Create()) { ConcurrencyUtility.CheckForParallelism(scope.Resolve <ISqlExecuter>(), threadCount); var context = scope.Resolve <Common.ExecutionContext>(); initialCount = context.Repository.TestEntity.BaseEntity.Query().Count(); } var id1 = Guid.NewGuid(); Parallel.For(0, threadCount, thread => { using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); Assert.AreEqual(initialCount, context.Repository.TestEntity.BaseEntity.Query().Count()); Thread.Sleep(100); context.Repository.TestEntity.BaseEntity.Insert(new TestEntity.BaseEntity { ID = id1, Name = TestNamePrefix + Guid.NewGuid() }); // Each thread uses the same ID to make sure only one thread can run this code at same time. Assert.AreEqual(initialCount + 1, context.Repository.TestEntity.BaseEntity.Query().Count()); } }); }
public void EarlyCommitAndClose() { var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); TestUtility.ShouldFail <FrameworkException>(() => { using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); context.Repository.TestEntity.BaseEntity.Insert(new TestEntity.BaseEntity { ID = id1, Name = TestNamePrefix + Guid.NewGuid() }); scope.CommitAndClose(); // CommitAndClose is incorrectly placed at this position. context.Repository.TestEntity.BaseEntity.Insert(new TestEntity.BaseEntity { ID = id2, Name = TestNamePrefix + Guid.NewGuid() }); } }, "disposed persistence transaction"); using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); // Only operations before CommitAndClose are committed. var ids = new[] { id1, id2 }; Assert.AreEqual( id1.ToString(), TestUtility.DumpSorted(context.Repository.TestEntity.BaseEntity.Load(ids), item => item.ID)); } }
public void EarlyCommitOnDispose() { var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); TestUtility.ShouldFail <FrameworkException>(() => { using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); context.Repository.TestEntity.BaseEntity.Insert(new TestEntity.BaseEntity { ID = id1, Name = TestNamePrefix + Guid.NewGuid() }); scope.Resolve <IPersistenceTransaction>().CommitOnDispose(); // Commit-on-dispose is incorrectly placed at this position. context.Repository.TestEntity.BaseEntity.Insert(new TestEntity.BaseEntity { ID = id2, Name = TestNamePrefix + Guid.NewGuid() }); throw new FrameworkException(nameof(EarlyCommitOnDispose)); // The exception is not handled within transaction scope to discard the transaction. } }, nameof(EarlyCommitOnDispose)); using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); // The transaction is committed because of incorrect implementation pattern above. var ids = new[] { id1, id2 }; Assert.AreEqual( TestUtility.DumpSorted(ids), TestUtility.DumpSorted(context.Repository.TestEntity.BaseEntity.Load(ids), item => item.ID)); } }
public void LongStringPropertySave() { using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); var tests = new List <string> { "abc", "ABC", "", null, @"čćšđžČĆŠĐŽ", @"`~!@#$%^&*()_+-=[]\{}|;':"",./<>?", new string('a', 256), new string('a', 17000), }; foreach (var test in tests) { var entity1 = new TestStorage.AllProperties { ID = Guid.NewGuid(), LongStringProperty = test }; context.PersistenceStorage.Insert(entity1); Assert.AreEqual(test, context.Repository.TestStorage.AllProperties.Load(x => x.ID == entity1.ID).Single().LongStringProperty); } } }
public void UpdateLockedData() { using (var scope = TestScope.Create()) { scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" }); var repository = scope.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); } }
public void SqlDependsOnID() { using (var scope = TestScope.Create()) { var features = new Dictionary <string, string> { { "base", "DataStructureInfo TestSqlWorkarounds.DependencyBase" }, { "base.A", "PropertyInfo TestSqlWorkarounds.DependencyBase.A" }, { "base.B", "PropertyInfo TestSqlWorkarounds.DependencyBase.B" }, { "depA", "SqlObjectInfo TestSqlWorkarounds.DependencyA" }, { "depB", "SqlObjectInfo TestSqlWorkarounds.DependencyB" }, { "depAll", "SqlObjectInfo TestSqlWorkarounds.DependencyAll" }, { "depID", "SqlObjectInfo TestSqlWorkarounds.DependencyID" } }; Dictionary <Guid, string> featuresById = features .Select(f => new { Name = f.Key, Id = ReadConceptId(f.Value, scope) }) .ToDictionary(fid => fid.Id, fid => fid.Name); var deployedDependencies = ReadConceptDependencies(featuresById.Keys, scope) .Select(dep => featuresById[dep.Item1] + "-" + featuresById[dep.Item2]); // Second concept depends on first concept. var expectedDependencies = new[] { "base-base.A", "base-base.B", // Standard properties depend on their entity. "base.A-depA", // Standard dependency on property. "base.B-depB", // Standard dependency on property. "base-depAll", "base.A-depAll", "base.B-depAll", // SqlDependsOnDataStructure includes all properties. "base-depID" // SqlDependsOnID does not include properties. }; Assert.AreEqual(TestUtility.DumpSorted(expectedDependencies), TestUtility.DumpSorted(deployedDependencies)); } }
public void DeleteModifiedPersistentObject() { using (var scope = TestScope.Create()) { scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" }); var repository = scope.Resolve <Common.DomRepository>(); { var s3Lock = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s3_lock" }; repository.TestLockItems.Simple.Insert(new[] { s3Lock }); AssertData("s3_lock", repository); AssertData("s3_lock", repository); } { var s3Persistent = repository.TestLockItems.Simple.Load().Single(); s3Persistent.Name = "abc"; TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Persistent }), "[Test] Name contains lock mark"); AssertData("s3_lock", repository); AssertData("s3_lock", repository); } } }
public void SqlDependsOnCaseInsensitive() { using (var scope = TestScope.Create()) { var features = new Dictionary <string, string> { { "1", "SqlViewInfo TestSqlWorkarounds.AutoDependsOn1" }, { "1CI", "SqlViewInfo TestSqlWorkarounds.AutoDependsOn1CI" }, { "2", "SqlViewInfo TestSqlWorkarounds.AutoDependsOn2" }, { "3", "SqlViewInfo TestSqlWorkarounds.AutoDependsOn3" }, { "4", "SqlViewInfo TestSqlWorkarounds.AutoDependsOn4" }, }; Dictionary <Guid, string> featuresById = features .Select(f => new { Name = f.Key, Id = ReadConceptId(f.Value, scope) }) .ToDictionary(fid => fid.Id, fid => fid.Name); var deployedDependencies = ReadConceptDependencies(featuresById.Keys, scope) .Select(dep => featuresById[dep.Item1] + "-" + featuresById[dep.Item2]); var expectedDependencies = "2-1, 2-1CI, 3-2, 4-3"; // Second concept depends on first concept. Assert.AreEqual( TestUtility.DumpSorted(expectedDependencies.Split(',').Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s))), TestUtility.DumpSorted(deployedDependencies)); } }
public void DeleteLockedData() { using (var scope = TestScope.Create()) { scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" }); var repository = scope.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); TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Lock }), "[Test] Name contains lock mark."); TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s1, s3Lock }), "[Test] Name contains lock mark."); TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Delete(new[] { s3Lock, s4 }), "[Test] Name contains lock mark."); AssertData("s1, s2, s3_lock, s4", repository); repository.TestLockItems.Simple.Delete(new[] { s1 }); AssertData("s2, s3_lock, s4", repository); } }
public void SqlDependsOnModule() { using (var scope = TestScope.Create()) { var features = new Dictionary <string, string> { { "X", "SqlViewInfo TestSqlWorkarounds2.OtherModuleObject" }, { "Entity", "DataStructureInfo TestSqlWorkarounds.E" }, { "Function", "SqlFunctionInfo TestSqlWorkarounds.Fun1" }, { "Property", "PropertyInfo TestSqlWorkarounds.E.I" }, { "View", "SqlViewInfo TestSqlWorkarounds.DependsOnNoProperties" }, }; Dictionary <Guid, string> featuresById = features .Select(f => new { Name = f.Key, Id = ReadConceptId(f.Value, scope) }) .ToDictionary(fid => fid.Id, fid => fid.Name); var deployedDependencies = ReadConceptDependencies(featuresById.Keys, scope) .Where(dep => featuresById[dep.Item1] == "X" || featuresById[dep.Item2] == "X") .Select(dep => featuresById[dep.Item1] + "-" + featuresById[dep.Item2]); var expectedDependencies = "Entity-X, Function-X, Property-X, View-X"; // Second concept depends on first concept. Assert.AreEqual( TestUtility.DumpSorted(expectedDependencies.Split(',').Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s))), TestUtility.DumpSorted(deployedDependencies)); } }
public void FilterByBase() { using (var scope = TestScope.Create()) { scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestFilter.Source" }); var repository = scope.Resolve <Common.DomRepository>(); var s1 = new TestFilter.Source { ID = Guid.NewGuid(), Name = "A s1" }; var s2 = new TestFilter.Source { ID = Guid.NewGuid(), Name = "B s2" }; var e1 = new TestFilter.SourceExtension { ID = s1.ID, Name2 = "C e1" }; var e2 = new TestFilter.SourceExtension { ID = s2.ID, Name2 = "D e2" }; repository.TestFilter.Source.Insert(new[] { s1, s2 }); repository.TestFilter.SourceExtension.Insert(new[] { e1, e2 }); var filteredExtensionByBase = repository.TestFilter.SourceExtension.Filter(new TestFilter.FilterByPrefix { Prefix = "A" }); Assert.AreEqual("C e1", TestUtility.DumpSorted(filteredExtensionByBase, item => item.Name2)); } }
public void AutoSqlDependsOnPolymorphic() { using (var scope = TestScope.Create()) { var features = new Dictionary <string, string> { { "Poly", "DataStructureInfo TestSqlWorkarounds.Poly" }, { "PolyView", "SqlObjectInfo TestSqlWorkarounds.Poly" }, { "PolyImplementation", "DataStructureInfo TestSqlWorkarounds.PolyImplementation" }, { "AutoDependsOnPoly", "SqlViewInfo TestSqlWorkarounds.AutoDependsOnPoly" } }; Dictionary <Guid, string> featuresById = features .Select(f => new { Name = f.Key, Id = ReadConceptId(f.Value, scope) }) .ToDictionary(fid => fid.Id, fid => fid.Name); var deployedDependencies = ReadConceptDependencies(featuresById.Keys, scope) .Select(dep => featuresById[dep.Item1] + "-" + featuresById[dep.Item2]); // The key dependency is "PolyView-AutoDependsOnPoly", it should be generated by AutodetectSqlDependencies: var expectedDependencies = "Poly-AutoDependsOnPoly, PolyView-AutoDependsOnPoly"; // Second concept depends on first concept. Assert.AreEqual( TestUtility.DumpSorted(expectedDependencies.Split(',').Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s))), TestUtility.DumpSorted(deployedDependencies)); } }
public void NullGenericFilterTest() { using (var scope = TestScope.Create()) { var genericRepos = scope.Resolve <GenericRepositories>().GetGenericRepository("Common.Claim"); var readCommand = new ReadCommandInfo { DataSource = "Common.Claim", Top = 3, OrderByProperties = new[] { new OrderByProperty { Property = "ClaimResource" } }, ReadRecords = true, ReadTotalCount = true }; var serverCommandsUtility = scope.Resolve <ServerCommandsUtility>(); var readResult = serverCommandsUtility.ExecuteReadCommand(readCommand, genericRepos); Console.WriteLine("Records.Length: " + readResult.Records.Length); Console.WriteLine("TotalCount: " + readResult.TotalCount); Assert.IsTrue(readResult.Records.Length < readResult.TotalCount); } }
public void LongIdentifiers() { using (var scope = TestScope.Create()) { var repos = scope.Resolve <Common.DomRepository>().TestLongIdentifiers; var p1 = new TestLongIdentifiers.LongIdentifier0000020000000003000000000400000000050000000006000000000700000000080000000009000000000C { LongName0100000000020000000003000000000400000000050000000006000000000700000000080000000009000000000C = "p1" }; repos.LongIdentifier0000020000000003000000000400000000050000000006000000000700000000080000000009000000000C .Insert(p1); var c1 = new TestLongIdentifiers.LongChild100000000020000000003000000000400000000050000000006000000000700000000080000000009000000000C { ChildName = "c1", LongIdentifier0000020000000003000000000400000000050000000006000000000700000000080000000009000000000CID = p1.ID }; var c2 = new TestLongIdentifiers.LongChild100000000020000000003000000000400000000050000000006000000000700000000080000000009000000000C { ChildName = "c2", LongIdentifier0000020000000003000000000400000000050000000006000000000700000000080000000009000000000CID = p1.ID }; repos.LongChild100000000020000000003000000000400000000050000000006000000000700000000080000000009000000000C .Insert(c1, c2); Assert.AreEqual("p1 c1, p1 c2", TestUtility.DumpSorted( repos.LongBrowse00000000020000000003000000000400000000050000000006000000000700000000080000000009000000000C.Query(), item => item.ParentName + " " + item.ChildName)); } }
public void AutoFilter_NoEffectOnServerObjectModel() { using (var scope = TestScope.Create()) { var repository = scope.Resolve <Common.DomRepository>(); repository.TestFilter.AutoFilter1.Delete(repository.TestFilter.AutoFilter1.Query()); repository.TestFilter.AutoFilter2.Delete(repository.TestFilter.AutoFilter2.Query()); repository.TestFilter.AutoFilter1.Insert( new[] { "a1", "a2", "b1", "b2" } .Select(name => new TestFilter.AutoFilter1 { Name = name })); repository.TestFilter.AutoFilter2.Insert( new[] { "a1", "a2", "b1", "b2" } .Select(name => new TestFilter.AutoFilter2 { Name = name })); Assert.AreEqual("a1, a2, b1, b2", TestUtility.DumpSorted(repository.TestFilter.AutoFilter1.Query(), item => item.Name)); Assert.AreEqual("a1, a2, b1, b2", TestUtility.DumpSorted(repository.TestFilter.AutoFilter2.Query(), item => item.Name)); Assert.AreEqual("a1, a2, b1, b2", TestUtility.DumpSorted(repository.TestFilter.AutoFilter2Browse.Query(), item => item.Name2)); var gr = scope.Resolve <GenericRepositories>(); Assert.AreEqual("a1, a2, b1, b2", TestUtility.DumpSorted(gr.GetGenericRepository <TestFilter.AutoFilter1>().Load(), item => item.Name)); Assert.AreEqual("a1, a2, b1, b2", TestUtility.DumpSorted(gr.GetGenericRepository <TestFilter.AutoFilter2>().Load(), item => item.Name)); Assert.AreEqual("a1, a2, b1, b2", TestUtility.DumpSorted(gr.GetGenericRepository <TestFilter.AutoFilter2Browse>().Load(), item => item.Name2)); } }
public void SqlFunction() { using (var scope = TestScope.Create()) { Assert.AreEqual("11", ReportSqlQueryResult(scope.Resolve <ISqlExecuter>(), "SELECT * FROM TestSqlWorkarounds.Fun2(10)")); } }
public void Dependant_FKConstraintInsert() { using (var scope = TestScope.Create()) { var repository = scope.Resolve <Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { Name = "a", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var dep = new TestPolymorphic.Dependant { Name = "dep", SimpleBaseID = s1.ID }; repository.TestPolymorphic.Dependant.Insert(new[] { dep }); var depInvalidReference = new TestPolymorphic.Dependant { Name = "depInvalidReference", SimpleBaseID = Guid.NewGuid() }; var ex = TestUtility.ShouldFail <Rhetos.UserException>( () => repository.TestPolymorphic.Dependant.Insert(new[] { depInvalidReference }), "It is not allowed to enter the record."); TestUtility.AssertContains(ex.ToString(), new[] { "Dependant", "FOREIGN KEY", "SimpleBase" }, "Expected inner SQL exception"); } }
public void SqlObject() { using (var scope = TestScope.Create()) { scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestSqlWorkarounds.E", "INSERT INTO TestSqlWorkarounds.E (I) VALUES (100)" }); string report = ""; scope.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 = ""; scope.Resolve <ISqlExecuter>().ExecuteReader( @"SELECT X FROM TestSqlWorkarounds.V3 ORDER BY X", reader => report += reader.GetInt32(0) + "."); Assert.AreEqual("101.102.", report); } }
public void CascadeDeleteExtension() { using (var scope = TestScope.Create()) { var repository = scope.Resolve <Common.DomRepository>(); var s1 = new TestPolymorphic.Simple1 { Name = "s1", Days = 1 }; repository.TestPolymorphic.Simple1.Insert(new[] { s1 }); var d1 = new TestPolymorphic.DependantExtension { Name = "d1", ID = s1.ID }; repository.TestPolymorphic.DependantExtension.Insert(new[] { d1 }); Assert.AreEqual("s1-d1", TestUtility.DumpSorted( repository.TestPolymorphic.DependantExtension.Query(new[] { d1.ID }).ToList(), item => item.Base.Name + "-" + item.Name)); repository.TestPolymorphic.Simple1.Delete(new[] { s1 }); Assert.AreEqual("", TestUtility.DumpSorted( repository.TestPolymorphic.DependantExtension.Query(new[] { d1.ID }).ToList(), item => item.Base.Name + "-" + item.Name)); } }
public void MoneyPropertySizeAndDecimals() { using (var scope = TestScope.Create(builder => { var options = new CommonConceptsRuntimeOptions() { AutoRoundMoney = true }; builder.RegisterInstance(options); builder.RegisterType <GenericRepositories>().AsImplementedInterfaces(); })) { var context = scope.Resolve <Common.ExecutionContext>(); var tests = new List <(decimal Save, decimal Load)> { (-922337203685477.58m, -922337203685477.58m), // T-SQL money limits. (922337203685477.58m, 922337203685477.58m), // T-SQL money limits. (0m, 0m), }; 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})."); } } }