public void CheckOidWithTable() { NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, "dieReisen.dieLaender.oid = {0}"); q.Parameters.Add(1); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter] INNER JOIN [Reise] ON [Mitarbeiter].[ID] = [Reise].[IDMitarbeiter] INNER JOIN [relLandReise] ON [Reise].[ID] = [relLandReise].[IDReise] WHERE [relLandReise].[IDLand] = {{0}}", this.mitarbeiterJoinFields), q.GeneratedQuery); }
public void CheckIfGeneratedQueryCanBeCalledTwice() { NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, "vorname = 'Mirko'"); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter] WHERE [Mitarbeiter].[Vorname] = 'Mirko'", this.mitarbeiterFields), q.GeneratedQuery); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter] WHERE [Mitarbeiter].[Vorname] = 'Mirko'", this.mitarbeiterFields), q.GeneratedQuery); }
public void TestDeleteHierarchy() { Track t = this.p.NewTrack(); t.Name = "Track 1"; t = this.p.NewTrack(); t.Name = "Track 2"; pm.MakePersistent(p); pm.Save(); pm.UnloadCache(); IQuery q = new NDOQuery <Peer>(pm, null); IList l = q.Execute(); pm.Delete(l); pm.Save(); pm.UnloadCache(); Assert.AreEqual(1, l.Count, "1 Peer muss da sein"); Peer p2 = (Peer)l[0]; Assert.AreEqual(NDOObjectState.Transient, p2.NDOObjectState, "Peer muss transient sein"); foreach (Track t2 in p2.Tracks) { Assert.AreEqual(NDOObjectState.Transient, t2.NDOObjectState, "Track muss transient sein"); } Assert.AreEqual(NDOObjectState.Transient, p2.NDOObjectState, "Peer muss transient sein"); pm.MakePersistent(p2); }
public void CheckIfSimplePrefetchWorks() { NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm); q.AddPrefetch("dieReisen"); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter]", this.mitarbeiterFields), q.GeneratedQuery); }
public void TestIfOidWithInClauseWorks() { NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, "oid IN (1,2,3,4,5)"); var s = q.GeneratedQuery; Assert.AreEqual($"SELECT {this.mitarbeiterFields} FROM [Mitarbeiter] WHERE [Mitarbeiter].[ID] IN (1, 2, 3, 4, 5)", s); }
public void TestIfSqlCodeWorks() { var expression = "SELECT * FROM Mitarbeiter WHERE Vorname = 'Mirko'"; NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(this.pm, expression, false, QueryLanguage.Sql); Assert.AreEqual(expression, q.GeneratedQuery); }
public void TestIfInClauseWithQuotesInStringsWorks() { NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, "vorname IN ('1''','2''3','''3','4','5')"); var s = q.GeneratedQuery; Assert.AreEqual($"SELECT {this.mitarbeiterFields} FROM [Mitarbeiter] WHERE [Mitarbeiter].[Vorname] IN ('1''', '2''3', '''3', '4', '5')", s); }
public void TestIfRelationInInClauseWorks() { NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, "dieReisen.oid IN (1,2,3,4,5)"); var s = q.GeneratedQuery; Assert.AreEqual($"SELECT {this.mitarbeiterJoinFields} FROM [Mitarbeiter] INNER JOIN [Reise] ON [Mitarbeiter].[ID] = [Reise].[IDMitarbeiter] WHERE [Reise].[ID] IN (1, 2, 3, 4, 5)", s); }
public void TestPolymorphicRelationQueries() { NDOQuery <Reise> q = new NDOQuery <Reise>(pm, "belege.datum = {0}"); q.Parameters.Add(DateTime.Now); Assert.AreEqual($"SELECT {reiseJoinFields} FROM [Reise] INNER JOIN [relBelegKostenpunkt] ON [Reise].[ID] = [relBelegKostenpunkt].[IDReise] INNER JOIN [Beleg] ON [Beleg].[ID] = [relBelegKostenpunkt].[IDBeleg] AND [relBelegKostenpunkt].[TCBeleg] = 926149172 WHERE [Beleg].[Datum] = {{0}} UNION \r\nSELECT {reiseJoinFields} FROM [Reise] INNER JOIN [relBelegKostenpunkt] ON [Reise].[ID] = [relBelegKostenpunkt].[IDReise] INNER JOIN [PKWFahrt] ON [PKWFahrt].[ID] = [relBelegKostenpunkt].[IDBeleg] AND [relBelegKostenpunkt].[TCBeleg] = 734406058 WHERE [PKWFahrt].[Datum] = {{0}}", q.GeneratedQuery); }
public void CheckIfSqlQueryIsProcessed() { NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, "SELECT * FROM Mitarbeiter WHERE ID = {0}", false, QueryLanguage.Sql); q.Parameters.Add(1); IList generatedParameters = null; string expression = null; Mock <IPersistenceHandler> handlerMock = new Mock <IPersistenceHandler>(); handlerMock.Setup(h => h.PerformQuery(It.IsAny <string>(), It.IsAny <IList>(), It.IsAny <DataSet>())).Returns(new DataTable()).Callback <string, IList, DataSet>((s, l, d) => { generatedParameters = l; expression = s; }); var handler = handlerMock.Object; Mock <IPersistenceHandlerManager> phManagerMock = new Mock <IPersistenceHandlerManager>(); phManagerMock.Setup(m => m.GetPersistenceHandler(It.IsAny <Type>())).Returns(handler); var container = pm.ConfigContainer; container.RegisterInstance <IPersistenceHandlerManager>(phManagerMock.Object); q.Execute(); Assert.NotNull(generatedParameters); Assert.AreEqual(1, generatedParameters.Count); Assert.AreEqual(1, generatedParameters[0]); Assert.AreEqual($"SELECT {this.mitarbeiterFields} FROM Mitarbeiter WHERE ID = {{0}}", expression); container.RegisterType <IPersistenceHandler, SqlPersistenceHandler>(); }
public void TestValueTypeRelation() { NDOQuery <Sozialversicherungsnummer> q = new NDOQuery <Sozialversicherungsnummer>(pm, "arbeiter.position.X > 2 AND arbeiter.position.Y < 5"); var fields = new SqlColumnListGenerator(pm.NDOMapping.FindClass(typeof(Sozialversicherungsnummer))).Result(false, false, true); Assert.AreEqual(String.Format($"SELECT {fields} FROM [Sozialversicherungsnummer] INNER JOIN [Mitarbeiter] ON [Mitarbeiter].[ID] = [Sozialversicherungsnummer].[IDSozial] WHERE [Mitarbeiter].[Position_X] > 2 AND [Mitarbeiter].[Position_Y] < 5", this.mitarbeiterFields), q.GeneratedQuery); }
public void TestSortedQueryAsc() { r.AddKostenpunkt(kp); DateTime yesterday = DateTime.Today - new TimeSpan(1, 0, 0, 0); kp.Datum = yesterday; r.AddKostenpunkt(kp = CreatePkw()); kp.Datum = DateTime.Today; pm.MakePersistent(r); pm.Save(); pm.UnloadCache(); IQuery q = new NDOQuery <Kostenpunkt>(pm); q.Orderings.Add(new AscendingOrder("datum")); NDO.Logging.DebugLogAdapter la = new NDO.Logging.DebugLogAdapter(); pm.LogAdapter = la; pm.VerboseMode = true; IList l = q.Execute(); pm.VerboseMode = false; Assert.AreEqual(2, l.Count, "Count wrong"); Assert.That(yesterday == ((Kostenpunkt)l[0]).Datum, "Order wrong"); Assert.That(DateTime.Today == ((Kostenpunkt)l[1]).Datum, "Wrong object"); }
public void DirectDeleteQueryIsCorrect() { var q = new NDOQuery <Mitarbeiter>(NDOFactory.Instance.PersistenceManager, "vorname = 'Mirko'"); var sql = q.GetDirectDeleteQuery(); Assert.AreEqual("DELETE FROM [Mitarbeiter] WHERE [Mitarbeiter].[Vorname] = 'Mirko'", sql); }
public void OidTest() { NDOoidAndHandler testobj = new NDOoidAndHandler(); testobj.MyId = guid; testobj.Text = "Test"; pm.MakePersistent(testobj); pm.Save(); pm.UnloadCache(); IQuery q = new NDOQuery <NDOoidAndHandler>(pm); testobj = null; testobj = (NDOoidAndHandler)q.ExecuteSingle(true); Assert.AreEqual(guid, testobj.MyId, "Wrong guid"); Assert.AreEqual("Test", testobj.Text, "Wrong text"); testobj.Text = "Neuer Text"; pm.Save(); testobj = null; testobj = (NDOoidAndHandler)q.ExecuteSingle(true); Assert.AreEqual(guid, testobj.MyId, "Wrong guid"); Assert.AreEqual("Neuer Text", testobj.Text, "Wrong text"); pm.Delete(testobj); pm.Save(); }
public void CanPerformDirectDelete() { pm.MakePersistent(m); pm.Save(); var firstName = m.Vorname; Assert.IsTrue(pm.Objects <Mitarbeiter>().Where(m => m.Vorname == firstName).Count > 0); var q = new NDOQuery <Mitarbeiter>(pm, "vorname = {0}"); q.Parameters.Add(firstName); q.DeleteDirectly(); Assert.AreEqual(0, pm.Objects <Mitarbeiter>().Where(m => m.Vorname == firstName).Count); m = CreateMitarbeiter("Mirko", "Matytschak"); pm.MakePersistent(m); pm.Save(); firstName = m.Vorname; Assert.IsTrue(pm.Objects <Mitarbeiter>().Where(m => m.Vorname == firstName).Count > 0); pm.Objects <Mitarbeiter>().Where(m => m.Vorname == firstName).DeleteDirectly(); Assert.AreEqual(0, pm.Objects <Mitarbeiter>().Where(m => m.Vorname == firstName).Count); }
public void TearDown() { var pm = PmFactory.NewPersistenceManager(); NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm); pm.Delete(q.Execute()); }
public void TestAggregateQuery() { Mitarbeiter mm; IList l = new ArrayList(); for (int i = 0; i < 20; i++) { mm = new Mitarbeiter(); mm.Vorname = "lkj"; mm.Nachname = i.ToString(); mm.Position = new System.Drawing.Point(0, i); pm.MakePersistent(mm); l.Add(mm); } pm.Save(); decimal sum = 0m; foreach (Mitarbeiter m2 in l) { sum += m2.Position.Y; } NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, null); decimal newsum = (decimal)q.ExecuteAggregate("position.Y", AggregateType.Sum); Assert.AreEqual(sum, newsum, "Summe stimmt nicht"); decimal count = (decimal)q.ExecuteAggregate("position.X", AggregateType.Count); Assert.AreEqual(20, count, "Count stimmt nicht"); }
public void TearDown() { var pm = PmFactory.NewPersistenceManager(); pm.TransactionMode = TransactionMode.None; //pm.UnloadCache(); IList reiseliste = pm.GetClassExtent(typeof(Reise), true); pm.Delete(reiseliste); pm.Save(); pm.UnloadCache(); IQuery q; IList liste; // We can't delete orphan Beleg object with NDO, so use direct Sql statements using (var handler = pm.GetSqlPassThroughHandler()) { var sql = "DELETE FROM " + pm.NDOMapping.FindClass(typeof(Beleg)).TableName; handler.Execute(sql); } q = new NDOQuery <Contact>(pm); liste = q.Execute(); pm.Delete(liste); pm.Save(); q = new NDOQuery <Adresse>(pm); liste = q.Execute(); pm.Delete(liste); pm.Save(); pm.Dispose(); }
public void PrefetchOccurs() { Reise r = new Reise() { Zweck = "NDO" }; Mitarbeiter m = new Mitarbeiter() { Vorname = "Mirko", Nachname = "Matytschak" }; pm.MakePersistent(m); m.Hinzufuegen(r); pm.Save(); NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm); q.AddPrefetch(nameof(Mitarbeiter.Reisen)); var m2 = q.ExecuteSingle(); var oc = pm.GetObjectContainer(); Assert.AreEqual(2, oc.RootObjects.Count); }
public void CheckNotOperator() { NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, "NOT (vorname LIKE 'M%')"); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter] WHERE NOT ([Mitarbeiter].[Vorname] LIKE 'M%')", this.mitarbeiterFields), q.GeneratedQuery); q = new NDOQuery <Mitarbeiter>(pm, "vorname LIKE 'M%' AND NOT nachname = 'Matytschak'"); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter] WHERE [Mitarbeiter].[Vorname] LIKE 'M%' AND NOT [Mitarbeiter].[Nachname] = 'Matytschak'", this.mitarbeiterFields), q.GeneratedQuery); q = new NDOQuery <Mitarbeiter>(pm, "NOT (vorname LIKE 'M%' AND nachname = 'Matytschak')"); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter] WHERE NOT ([Mitarbeiter].[Vorname] LIKE 'M%' AND [Mitarbeiter].[Nachname] = 'Matytschak')", this.mitarbeiterFields), q.GeneratedQuery); q = new NDOQuery <Mitarbeiter>(pm, "dieReisen.zweck = 'ADC' OR NOT dieReisen.zweck = 'ADW'"); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter] INNER JOIN [Reise] ON [Mitarbeiter].[ID] = [Reise].[IDMitarbeiter] WHERE [Reise].[Zweck] = 'ADC' OR NOT [Reise].[Zweck] = 'ADW'", this.mitarbeiterJoinFields), q.GeneratedQuery); q = new NDOQuery <Mitarbeiter>(pm, "NOT (dieReisen.zweck = 'ADC' OR dieReisen.zweck = 'ADW')"); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter] INNER JOIN [Reise] ON [Mitarbeiter].[ID] = [Reise].[IDMitarbeiter] WHERE NOT ([Reise].[Zweck] = 'ADC' OR [Reise].[Zweck] = 'ADW')", this.mitarbeiterJoinFields), q.GeneratedQuery); bool thrown = false; try { q = new NDOQuery <Mitarbeiter>(pm, "vorname LIKE 'M%' AND nachname = NOT 'Matytschak'"); string s = q.GeneratedQuery; } catch (OqlExpressionException) { thrown = true; } Assert.AreEqual(true, thrown); // TODO: This is a wrong expression which passes the syntax check. // Mysql allows WHERE NOT True but disallows nachname = NOT True // Sql Server doesn't know the symbol True q = new NDOQuery <Mitarbeiter>(pm, "vorname LIKE 'M%' AND nachname = NOT True"); string t = q.GeneratedQuery; // Make sure, GeneratedQuery ist called twice. Console.WriteLine(t); Assert.AreEqual($"SELECT {this.mitarbeiterFields} FROM [Mitarbeiter] WHERE [Mitarbeiter].[Vorname] LIKE 'M%' AND [Mitarbeiter].[Nachname] = NOT TRUE", q.GeneratedQuery); }
public void HintTest() { ClassWithHint testobj = new ClassWithHint(); testobj.Text = "Test"; pm.MakePersistent(testobj); pm.Save(); pm.UnloadCache(); IQuery q = new NDOQuery <ClassWithHint>(pm); testobj = null; testobj = (ClassWithHint)q.ExecuteSingle(true); Assert.AreEqual(guid, testobj.NDOObjectId.Id[0], "Wrong guid #1"); Assert.AreEqual("Test", testobj.Text, "Wrong text #1"); testobj.Text = "Neuer Text"; pm.Save(); testobj = null; testobj = (ClassWithHint)q.ExecuteSingle(true); Assert.AreEqual(guid, testobj.NDOObjectId.Id[0], "Wrong guid #2"); Assert.AreEqual("Neuer Text", testobj.Text, "Wrong text #2"); pm.Delete(testobj); pm.Save(); }
public void CheckMitarbeiterQuery() { NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm); List <Mitarbeiter> l = q.Execute(); Assert.AreEqual(2, l.Count); }
private void SaveAndReload() { pm.Save(); pm.UnloadCache(); NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm); m = (Mitarbeiter)q.ExecuteSingle(true); }
public void TestAddRange() { AddRange(); NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm); m = q.ExecuteSingle(true); Assert.AreEqual(2, m.Reisen.Count, "Count of Reisen wrong"); }
public void CheckThatOneJoinAppearsOnlyOneTime() { NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, "adresse.lkz LIKE 'D%' AND adresse.ort <> 'Bad Tölz'"); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter] INNER JOIN [Adresse] ON [Adresse].[ID] = [Mitarbeiter].[IDAdresse] WHERE [Adresse].[Lkz] LIKE 'D%' AND [Adresse].[Ort] <> 'Bad Tölz'", this.mitarbeiterJoinFields), q.GeneratedQuery); q = new NDOQuery <Mitarbeiter>(pm, "dieReisen.zweck = 'ADC' OR dieReisen.zweck = 'ADW'"); Assert.AreEqual(String.Format("SELECT {0} FROM [Mitarbeiter] INNER JOIN [Reise] ON [Mitarbeiter].[ID] = [Reise].[IDMitarbeiter] WHERE [Reise].[Zweck] = 'ADC' OR [Reise].[Zweck] = 'ADW'", this.mitarbeiterJoinFields), q.GeneratedQuery); }
public void TestTopicHierarchieWorkaround() { Topic t = new Topic("Main Topic"); pm.MakePersistent(t); pm.Save(); Topic t2 = t.NewSubTopic("Middle Topic"); Assert.AreEqual(NDOObjectState.Created, t2.NDOObjectState, "t2 müsste Created sein"); Assert.AreEqual(t, t2.Owner, "Owner stimmt nicht"); Assert.AreEqual(1, t.Subtopics.Count, "t müsste einen Untergebenen in der Liste haben"); Topic t3 = t2.NewSubTopic("End Topic"); Assert.AreEqual(NDOObjectState.Created, t3.NDOObjectState, "t3 müsste Created sein"); Assert.NotNull(t3.Owner, "t3 müsste einen Owner haben"); pm.Save(); pm.UnloadCache(); IQuery q = new NDOQuery <Topic>(pm, "oid = {0}"); q.Parameters.Add(t.NDOObjectId.Id[0]); t = (Topic)q.ExecuteSingle(true); Assert.AreEqual(1, t.Subtopics.Count, "t müsste einen Untergebenen in der Liste haben"); t2 = (Topic)t.Subtopics[0]; ObjectId oid2 = t2.NDOObjectId; Assert.NotNull(t2.Owner, "t2 müsste einen Owner haben"); Assert.AreEqual(1, t2.Subtopics.Count, "t2 müsste einen Untergebenen in der Liste haben"); t3 = (Topic)t2.Subtopics[0]; ObjectId oid3 = t3.NDOObjectId; t2.RemoveSubTopic(t3); t.RemoveSubTopic(t2); Assert.Null(t2.Owner, "Owner muss null sein"); Assert.AreEqual(NDOObjectState.Deleted, t2.NDOObjectState, "t2 muss gelöscht sein"); Assert.AreEqual(NDOObjectState.Deleted, t3.NDOObjectState, "t3 muss gelöscht sein"); pm.Delete(t); pm.Save(); pm.UnloadCache(); IList l = q.Execute(); Assert.AreEqual(0, l.Count, "Liste muss leer sein 1"); q = new NDOQuery <Topic>(pm, "oid = {0}"); q.Parameters.Add(oid2.Id[0]); l = q.Execute(); Assert.AreEqual(0, l.Count, "Liste muss leer sein 2"); q = new NDOQuery <Topic>(pm, "oid = {0}"); q.Parameters.Add(oid3.Id[0]); l = q.Execute(); Assert.AreEqual(0, l.Count, "Liste muss leer sein 3"); }
public void TearDown() { IQuery q = new NDOQuery <Derived>(pm, null); IList l = q.Execute(); pm.Delete(l); pm.Close(); pm = null; }
public void Angriff() { // pm.MakePersistent(m); // pm.Save(); NDOQuery <Mitarbeiter> q = new NDOQuery <Mitarbeiter>(pm, "nachname LIKE {0}"); q.Parameters.Add("dummy';SELECT * from Mitarbeiter; --"); IList l = q.Execute(); }
public void BitwiseOperatorsWork() { var pm = NDOFactory.Instance.PersistenceManager; var query = new NDOQuery <Buero>(pm, "Nummer & 2 = 0"); Assert.That(query.GeneratedQuery.IndexOf("[Buero].[Nummer] & 2 = 0") > -1); query = new NDOQuery <Buero>(pm, "Nummer | 2 = 0"); Assert.That(query.GeneratedQuery.IndexOf("[Buero].[Nummer] | 2 = 0") > -1); }
public void TearDown() { var pm = PmFactory.NewPersistenceManager(); NDOQuery <Parent> q = new NDOQuery <Parent>(pm, null); IList l = q.Execute(); pm.Delete(l); pm.Dispose(); }