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); } }
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)); } }
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); } } }
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); } }
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); }
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)); } }
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"); } }
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); }
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)); } }
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"); } }
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"); } }
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); }
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"))); }
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))); }
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); }
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); }
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); }
public void DomRepositoryHasModuleRepositories() { using (var executionContext = new CommonTestExecutionContext()) { var repository = new Common.DomRepository(executionContext); Assert.IsNotNull(repository.TestDataStructure); } }
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 }); } }
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 }); } }
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 }); } }
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 }); } }
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 }); } }
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 }); } }
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 }); } }
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); } }
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"); } }
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"); } }
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())); }
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"); } }
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())); }
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 }); } }
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]); } }
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"); } }
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); } }
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); } }
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."); } }
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())); }
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)); } }
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)); } }
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); } }
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); }
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); }
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); }
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); }
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); }
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); }
public EntityHelper(RhetosTestContainer container) { _executionContext = container.Resolve <Common.ExecutionContext>(); _repository = container.Resolve <Common.DomRepository>(); }
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); }
public EntityHelperMultiple(RhetosTestContainer container, Common.DomRepository repository) { _repository = container.Resolve <Common.DomRepository>(); }
public EntityHelper(UnitOfWorkScope scope) { _executionContext = scope.Resolve <Common.ExecutionContext>(); _repository = scope.Resolve <Common.DomRepository>(); }
private void TestReleaseLock(Common.ReleaseLock parameters, Common.DomRepository repository) { repository.Common.ReleaseLock.Execute(parameters); }
private static string ReportCachingTestView(Common.DomRepository repository) { return(string.Join(", ", repository.TestDataStructure.CachingTestView.Query().Select(item => item.S).OrderBy(x => x))); }
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))); }
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))); }
private void TestReleaseLock(Common.ReleaseLock parameters, Common.DomRepository repository, Rhetos.Utilities.IUserInfo userInfo) { repository.Common.ReleaseLock.Execute(parameters); }
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))); }
private static void AssertData(Common.DomRepository repository, string expected) { Assert.AreEqual(expected, TestUtility.DumpSorted(repository.TestInvalidData.Simple.Query(), item => item.Name)); }
private static string ReportSimple(Common.DomRepository repository) { return(ReportSimple(repository.TestHierarchy.Simple.Query())); }
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))); }