[longomatch] Start adding unit tests
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Start adding unit tests
- Date: Mon, 7 Jul 2014 11:18:23 +0000 (UTC)
commit 37e6aab14f687c3070ec2fe6b32f03fe262d6cc6
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed Jan 29 22:11:13 2014 +0100
Start adding unit tests
LongoMatch.mds | 4 +
Tests/Core/TestCategoriesTemplate.cs | 61 ++++++++++
Tests/Core/TestCategory.cs | 91 ++++++++++++++
Tests/Core/TestCoordinates.cs | 72 +++++++++++
Tests/Core/TestDrawing.cs | 32 +++++
Tests/Core/TestMediaFile.cs | 59 +++++++++
Tests/Core/TestPlay.cs | 131 ++++++++++++++++++++
Tests/Core/TestPlayer.cs | 81 +++++++++++++
Tests/Core/TestPoint.cs | 49 ++++++++
Tests/Core/TestProject.cs | 196 ++++++++++++++++++++++++++++++
Tests/Core/TestProjectDescription.cs | 52 ++++++++
Tests/Core/TestSubCategory.cs | 88 ++++++++++++++
Tests/Core/TestSubcategoriesTemplate.cs | 54 +++++++++
Tests/Core/TestTagStore.cs | 139 ++++++++++++++++++++++
Tests/Core/TestTeamTemplate.cs | 94 +++++++++++++++
Tests/Core/TestTimeNode.cs | 59 +++++++++
Tests/Services/TestDatabase.cs | 198 +++++++++++++++++++++++++++++++
Tests/Services/TestDatabasesManager.cs | 32 +++++
Tests/Tests.mdp | 48 ++++++++
Tests/Utils.cs | 61 ++++++++++
20 files changed, 1601 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.mds b/LongoMatch.mds
index c267a23..c02365d 100644
--- a/LongoMatch.mds
+++ b/LongoMatch.mds
@@ -28,6 +28,7 @@
<Entry build="True" name="LongoMatch.Addins" configuration="Debug" />
<Entry build="True" name="LongoMatch.Plugins" configuration="Debug" />
<Entry build="True" name="OxyPlotMono" configuration="Debug" />
+ <Entry build="True" name="Tests" configuration="Debug" />
</Configuration>
<Configuration name="Release" ctype="CombineConfiguration">
<Entry build="True" name="LongoMatch.GUI" configuration="Release" />
@@ -40,6 +41,7 @@
<Entry build="True" name="LongoMatch.Addins" configuration="Release" />
<Entry build="True" name="LongoMatch.Plugins" configuration="Release" />
<Entry build="True" name="OxyPlotMono" configuration="Release" />
+ <Entry build="True" name="Tests" configuration="Release" />
</Configuration>
</Configurations>
<StartMode startupentry="LongoMatchGtk" single="True">
@@ -53,6 +55,7 @@
<Execute type="None" entry="LongoMatch.Addins" />
<Execute type="None" entry="LongoMatch.Plugins" />
<Execute type="None" entry="OxyPlotMono" />
+ <Execute type="None" entry="Tests" />
</StartMode>
<Entries>
<Entry filename="LongoMatch.GUI/LongoMatch.GUI.mdp" />
@@ -65,5 +68,6 @@
<Entry filename="LongoMatch.Addins/LongoMatch.Addins.mdp" />
<Entry filename="LongoMatch.Plugins/LongoMatch.Plugins.mdp" />
<Entry filename="oxyplot/OxyPlotMono/OxyPlotMono.csproj" />
+ <Entry filename="Tests/Tests.mdp" />
</Entries>
</Combine>
\ No newline at end of file
diff --git a/Tests/Core/TestCategoriesTemplate.cs b/Tests/Core/TestCategoriesTemplate.cs
new file mode 100644
index 0000000..e8795e9
--- /dev/null
+++ b/Tests/Core/TestCategoriesTemplate.cs
@@ -0,0 +1,61 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+using LongoMatch.Common;
+using LongoMatch.Store;
+using LongoMatch.Store.Templates;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestCategoriesTemplate
+ {
+ [Test()]
+ public void TestSerialization ()
+ {
+ Categories cat = new Categories ();
+
+ Utils.CheckSerialization (cat);
+
+ cat.Name = "test";
+ cat.Version = new Version (1, 2);
+ cat.GamePeriods = new List<string> ();
+ cat.GamePeriods.Add ("1");
+ cat.GamePeriods.Add ("2");
+ cat.Add ( new Category {Name = "cat1"});
+ cat.Add ( new Category {Name = "cat2"});
+ cat.Add ( new Category {Name = "cat3"});
+
+ Utils.CheckSerialization (cat);
+
+ Categories newcat = Utils.SerializeDeserialize (cat);
+ Assert.AreEqual (cat.Name, newcat.Name);
+ Assert.AreEqual (cat.Version, newcat.Version);
+ Assert.AreEqual (cat.GamePeriods.Count, newcat.GamePeriods.Count);
+ Assert.AreEqual (cat.GamePeriods[0], newcat.GamePeriods[0]);
+ Assert.AreEqual (cat.GamePeriods[1], newcat.GamePeriods[1]);
+ Assert.AreEqual (cat.Count, newcat.Count);
+ Assert.AreEqual (cat[0].UUID, newcat[0].UUID);
+ Assert.AreEqual (cat[1].UUID, newcat[1].UUID);
+ Assert.AreEqual (cat[2].UUID, newcat[2].UUID);
+ }
+ }
+}
+
diff --git a/Tests/Core/TestCategory.cs b/Tests/Core/TestCategory.cs
new file mode 100644
index 0000000..dfdbdd9
--- /dev/null
+++ b/Tests/Core/TestCategory.cs
@@ -0,0 +1,91 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Drawing;
+using NUnit.Framework;
+using Newtonsoft.Json;
+
+using LongoMatch.Common;
+using LongoMatch.Store;
+using System.IO;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestCategory
+ {
+ [Test()]
+ public void TestSerialization ()
+ {
+ string jsonString;
+ Category cat;
+ MemoryStream stream;
+ StreamReader reader;
+
+ cat = new Category();
+ cat.Color = Color.AliceBlue;
+ cat.HotKey = new HotKey {Key=2, Modifier=4};
+ cat.Name = "test";
+ cat.Position = 2;
+ cat.SortMethod = SortMethodType.SortByDuration;
+ cat.Start = new Time (3000);
+ cat.Stop = new Time (4000);
+ cat.SubCategories = null;
+ cat.TagFieldPosition = true;
+ cat.TagGoalPosition = true;
+ cat.TagHalfFieldPosition = true;
+ cat.FieldPositionIsDistance = true;
+ cat.HalfFieldPositionIsDistance = false;
+ cat.SubCategories = new
System.Collections.Generic.List<LongoMatch.Interfaces.ISubCategory>();
+ cat.SubCategories.Add (new TagSubCategory {Name="TestSubcat"});
+
+ Utils.CheckSerialization (cat);
+
+ stream = new MemoryStream ();
+ SerializableObject.Save (cat, stream, SerializationType.Json);
+ stream.Seek (0, SeekOrigin.Begin);
+ reader = new StreamReader (stream);
+ jsonString = reader.ReadToEnd();
+ Assert.False (jsonString.Contains ("SortMethodString"));
+ stream.Seek (0, SeekOrigin.Begin);
+ Category newcat = SerializableObject.Load<Category> (stream, SerializationType.Json);
+
+ Assert.AreEqual (cat.UUID, newcat.UUID);
+ Assert.AreEqual (cat.Name, newcat.Name);
+ Assert.AreEqual (cat.Position, newcat.Position);
+ Assert.AreEqual (cat.SortMethod, newcat.SortMethod);
+ Assert.AreEqual (cat.Start.MSeconds, newcat.Start.MSeconds);
+ Assert.AreEqual (cat.Stop.MSeconds, newcat.Stop.MSeconds);
+ Assert.AreEqual (cat.TagFieldPosition, newcat.TagFieldPosition);
+ Assert.AreEqual (cat.TagGoalPosition, newcat.TagGoalPosition);
+ Assert.AreEqual (cat.TagHalfFieldPosition, newcat.TagHalfFieldPosition);
+ Assert.AreEqual (cat.FieldPositionIsDistance, newcat.FieldPositionIsDistance);
+ Assert.AreEqual (cat.HalfFieldPositionIsDistance, newcat.HalfFieldPositionIsDistance);
+ Assert.AreEqual (cat.HotKey, newcat.HotKey);
+ Assert.AreEqual (newcat.Color.R, Color.AliceBlue.R);
+ Assert.AreEqual (newcat.Color.G, Color.AliceBlue.G);
+ Assert.AreEqual (newcat.Color.B, Color.AliceBlue.B);
+ Assert.AreEqual (newcat.SubCategories.Count, 1);
+ Assert.AreEqual (newcat.SubCategories[0].Name, "TestSubcat");
+ }
+
+ public static void Main (string [] args)
+ {
+ }
+ }
+}
diff --git a/Tests/Core/TestCoordinates.cs b/Tests/Core/TestCoordinates.cs
new file mode 100644
index 0000000..e45ca39
--- /dev/null
+++ b/Tests/Core/TestCoordinates.cs
@@ -0,0 +1,72 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+using LongoMatch.Common;
+using LongoMatch.Store;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestCoordinates
+ {
+ [Test()]
+ public void TestSerialization ()
+ {
+ Coordinates coords = new Coordinates();
+ Point p1 = new Point (1, 2);
+ Point p2 = new Point (3, 4);
+ coords.Add(p1);
+ coords.Add(p2);
+
+ Utils.CheckSerialization(coords);
+ Coordinates newcoords = Utils.SerializeDeserialize(coords);
+
+ Assert.AreEqual (coords.Count, newcoords.Count);
+ Assert.AreEqual (coords[0].X, newcoords[0].X);
+ Assert.AreEqual (coords[1].X, newcoords[1].X);
+ Assert.AreEqual (coords[0].Y, newcoords[0].Y);
+ Assert.AreEqual (coords[1].Y, newcoords[1].Y);
+ }
+
+ [Test()]
+ public void TestEqual ()
+ {
+ Coordinates coords = new Coordinates();
+ coords.Add(new Point (1, 2));
+ coords.Add(new Point (3, 4));
+
+ Coordinates coords2 = new Coordinates();
+ coords2.Add (new Point (1, 2));
+ coords2.Add (new Point (3, 4));
+
+ Assert.AreEqual (coords, coords2);
+
+ /* Different number of elements */
+ coords2.Add (new Point (1, 2));
+ Assert.AreNotEqual (coords, coords2);
+
+ /* Same number of elements but different points */
+ coords2 = new Coordinates();
+ coords2.Add (new Point (1, 1));
+ coords2.Add (new Point (3, 4));
+ Assert.AreNotEqual (coords, coords2);
+ }
+ }
+}
+
diff --git a/Tests/Core/TestDrawing.cs b/Tests/Core/TestDrawing.cs
new file mode 100644
index 0000000..d3cd2e5
--- /dev/null
+++ b/Tests/Core/TestDrawing.cs
@@ -0,0 +1,32 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestDrawing
+ {
+ [Test()]
+ public void TestCase ()
+ {
+ }
+ }
+}
+
diff --git a/Tests/Core/TestMediaFile.cs b/Tests/Core/TestMediaFile.cs
new file mode 100644
index 0000000..08be46f
--- /dev/null
+++ b/Tests/Core/TestMediaFile.cs
@@ -0,0 +1,59 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+using LongoMatch.Common;
+using LongoMatch.Store;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestMediaFile
+ {
+ [Test()]
+ public void TestSerialization ()
+ {
+ MediaFile mf = new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
+ "aac", 320, 240, 1.3, new Image (null));
+ Utils.CheckSerialization (mf);
+
+ MediaFile newmf = Utils.SerializeDeserialize (mf);
+ Assert.AreEqual (mf.FilePath, newmf.FilePath);
+ Assert.AreEqual (mf.Length, newmf.Length);
+ Assert.AreEqual (mf.Fps, newmf.Fps);
+ Assert.AreEqual (mf.HasAudio, newmf.HasAudio);
+ Assert.AreEqual (mf.HasVideo, newmf.HasVideo);
+ Assert.AreEqual (mf.Container, newmf.Container);
+ Assert.AreEqual (mf.VideoCodec, newmf.VideoCodec);
+ Assert.AreEqual (mf.AudioCodec, newmf.AudioCodec);
+ Assert.AreEqual (mf.VideoWidth, newmf.VideoWidth);
+ Assert.AreEqual (mf.VideoHeight, newmf.VideoHeight);
+ Assert.AreEqual (mf.Par, newmf.Par);
+
+ }
+
+ [Test()]
+ public void TestGetFrames ()
+ {
+ MediaFile mf = new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
+ "aac", 320, 240, 1.3, new Image (null));
+ Assert.AreEqual (mf.GetFrames(), 850);
+ }
+ }
+}
+
diff --git a/Tests/Core/TestPlay.cs b/Tests/Core/TestPlay.cs
new file mode 100644
index 0000000..c6f20b1
--- /dev/null
+++ b/Tests/Core/TestPlay.cs
@@ -0,0 +1,131 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+using LongoMatch.Common;
+using LongoMatch.Store;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestPlay
+ {
+ Category cat1;
+
+ public Play CreatePlay () {
+ Play play = new Play();
+ cat1 = new Category {Name="Cat1"};
+
+ play.Category = cat1;
+ play.Notes = "notes";
+ play.Fps = 30;
+ play.Selected = true;
+ play.Team = LongoMatch.Common.Team.LOCAL;
+ play.GamePeriod = "2";
+ play.FieldPosition = new Coordinates();
+ play.FieldPosition.Add (new Point (1, 2));
+ play.HalfFieldPosition = new Coordinates ();
+ play.HalfFieldPosition.Add (new Point (4,5));
+ play.GoalPosition = new Coordinates ();
+ play.GoalPosition.Add (new Point (6, 7));
+ play.PlaybackRate = 1.5f;
+ play.Name = "Play";
+ play.Start = new Time(1000);
+ play.Stop = new Time(2000);
+ play.Rate = 2.3f;
+
+ play.Tags.Add(new StringTag {Value = "test"});
+ play.Teams.Add(new TeamTag {Value = Team.LOCAL});
+ play.Players.Add(new PlayerTag {Value = new Player {Name="Test"}});
+ return play;
+ }
+
+ [Test()]
+ public void TestCase ()
+ {
+ Play p = new Play ();
+ Utils.CheckSerialization (p);
+
+ p = CreatePlay ();
+ var newp = Utils.SerializeDeserialize (p);
+
+ Assert.AreEqual (p.Category.UUID, newp.Category.UUID);
+ Assert.AreEqual (p.Notes, newp.Notes);
+ Assert.AreEqual (p.Fps, newp.Fps);
+ Assert.AreEqual (p.Team, newp.Team);
+ Assert.AreEqual (p.GamePeriod, newp.GamePeriod);
+ Assert.AreEqual (p.FieldPosition, newp.FieldPosition);
+ Assert.AreEqual (p.HalfFieldPosition, newp.HalfFieldPosition);
+ Assert.AreEqual (p.GoalPosition, newp.GoalPosition);
+ Assert.AreEqual (p.PlaybackRate, newp.PlaybackRate);
+ Assert.AreEqual (p.Name, newp.Name);
+ Assert.AreEqual (p.Start, newp.Start);
+ Assert.AreEqual (p.Stop, newp.Stop);
+ Assert.AreEqual (p.Rate, newp.Rate);
+ Assert.AreEqual (p.PlaybackRate, newp.PlaybackRate);
+ }
+
+ [Test()]
+ public void TestStartFrame ()
+ {
+ Play p = CreatePlay ();
+ Assert.AreEqual (p.StartFrame, p.Start.MSeconds * p.Fps / 1000);
+ }
+
+ [Test()]
+ public void TestStopFrame ()
+ {
+ Play p = CreatePlay ();
+ Assert.AreEqual (p.StopFrame, p.Stop.MSeconds * p.Fps / 1000);
+ }
+
+ [Test()]
+ public void TestTotalFrames ()
+ {
+ Play p = CreatePlay ();
+ Assert.AreEqual (p.TotalFrames, p.StopFrame - p.StartFrame);
+ }
+
+ [Test()]
+ public void TestCentralFrame ()
+ {
+ Play p = CreatePlay ();
+ Assert.AreEqual (p.CentralFrame, p.StopFrame-((p.TotalFrames)/2));
+ }
+
+ [Test()]
+ public void TestKeyframe ()
+ {
+ Play p = CreatePlay ();
+ Assert.IsFalse (p.HasDrawings);
+ Assert.AreEqual (p.KeyFrame, 0);
+ p.KeyFrameDrawing = new Drawing {RenderTime = 1000};
+ Assert.AreEqual (p.KeyFrame, p.KeyFrameDrawing.RenderTime * p.Fps / 1000);
+ }
+
+ [Test()]
+ public void TestHasFrame ()
+ {
+ Play p = CreatePlay ();
+ Assert.IsTrue (p.HasFrame (35));
+ Assert.IsFalse (p.HasFrame (70));
+ Assert.IsFalse (p.HasFrame (3));
+ }
+ }
+}
+
diff --git a/Tests/Core/TestPlayer.cs b/Tests/Core/TestPlayer.cs
new file mode 100644
index 0000000..6beabde
--- /dev/null
+++ b/Tests/Core/TestPlayer.cs
@@ -0,0 +1,81 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+using LongoMatch.Common;
+using LongoMatch.Store;
+
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestPlayer
+ {
+ [Test()]
+ public void TestSerialization ()
+ {
+ Player player = new Player {Name="andoni", Position="runner",
+ Number = 5, Birthday = new DateTime (1984, 6, 11),
+ Nationality = "spanish", Height = 1.73f, Weight = 70,
+ Playing = true};
+
+ Utils.CheckSerialization (player);
+
+ Player newPlayer = Utils.SerializeDeserialize (player);
+ Assert.AreEqual (player.Name, newPlayer.Name);
+ Assert.AreEqual (player.Position, newPlayer.Position);
+ Assert.AreEqual (player.Number, newPlayer.Number);
+ Assert.AreEqual (player.Birthday, newPlayer.Birthday);
+ Assert.AreEqual (player.Nationality, newPlayer.Nationality);
+ Assert.AreEqual (player.Height, newPlayer.Height);
+ Assert.AreEqual (player.Weight, newPlayer.Weight);
+ Assert.AreEqual (player.Playing, newPlayer.Playing);
+ }
+
+ [Test()]
+ public void TestPhoto ()
+ {
+ Player player = new Player {Name="andoni", Position="runner",
+ Number = 5, Birthday = new DateTime (1984, 6, 11),
+ Nationality = "spanish", Height = 1.73f, Weight = 70,
+ Playing = true};
+
+ player.Photo = null;
+ Assert.AreEqual (player.Photo, null);
+ /* FIXME: test with real image */
+ player.Photo = new DummyImage ("test");
+ Utils.CheckSerialization (player);
+ }
+ }
+ [Serializable]
+ public class DummyImage: Image
+ {
+ string text;
+
+ public DummyImage (string text): base (null)
+ {
+ this.text = text;
+ }
+
+ public byte[] Serialize () {
+ Console.WriteLine ("SER");
+ return new byte[] {byte.Parse ("1")};
+ }
+ }
+}
+
diff --git a/Tests/Core/TestPoint.cs b/Tests/Core/TestPoint.cs
new file mode 100644
index 0000000..915e90f
--- /dev/null
+++ b/Tests/Core/TestPoint.cs
@@ -0,0 +1,49 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+using LongoMatch.Store;
+using LongoMatch.Common;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestPoint
+ {
+ [Test()]
+ public void TestSerialization ()
+ {
+ Point p = new Point (3, 4);
+
+ Utils.CheckSerialization (p);
+ Point newp = Utils.SerializeDeserialize (p);
+ Assert.AreEqual (p.X, newp.X);
+ Assert.AreEqual (p.Y, newp.Y);
+ }
+
+ [Test()]
+ public void TestEqual ()
+ {
+ Point p1 = new Point (1, 2);
+ Point p2 = new Point (1, 2);
+ Assert.AreEqual (p1, p2);
+ }
+
+ }
+}
+
diff --git a/Tests/Core/TestProject.cs b/Tests/Core/TestProject.cs
new file mode 100644
index 0000000..0ae75f2
--- /dev/null
+++ b/Tests/Core/TestProject.cs
@@ -0,0 +1,196 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+
+using LongoMatch.Common;
+using LongoMatch.Store;
+using LongoMatch.Store.Templates;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestProject
+ {
+
+ Project CreateProject () {
+ Project p = new Project ();
+ p.Categories = Categories.DefaultTemplate (10);
+ p.LocalTeamTemplate = TeamTemplate.DefaultTemplate (10);
+ p.VisitorTeamTemplate = TeamTemplate.DefaultTemplate (12);
+ MediaFile mf = new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
+ "aac", 320, 240, 1.3, new Image (null));
+ ProjectDescription pd = new ProjectDescription ();
+ pd.File = mf;
+ p.Description = pd;
+ return p;
+ }
+
+ [Test()]
+ public void TestSerialization ()
+ {
+ Project p = new Project ();
+
+ Utils.CheckSerialization (p);
+
+ p = CreateProject ();
+ Utils.CheckSerialization (p);
+ p.AddPlay (new Play());
+ Utils.CheckSerialization (p);
+
+ Project newp = Utils.SerializeDeserialize (p);
+ Assert.AreEqual (newp.CompareTo (p), 0);
+ Assert.AreEqual (newp.Description.CompareTo (p.Description), 0);
+ Assert.AreEqual (newp.AllPlays().Count, p.AllPlays().Count);
+ }
+
+ [Test ()]
+ public void TestPlaysGrouping () {
+ Project p = CreateProject ();
+ p.AddPlay (p.Categories[0], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[0], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[1], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[2], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[2], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[2], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[6], new Time (1000), new Time (2000), null);
+
+ IEnumerable<IGrouping<Category, Play>> g = p.PlaysGroupedByCategory;
+ Assert.AreEqual (g.Count(), 4);
+ IGrouping<Category, Play> gr = g.ElementAt (0);
+ Assert.AreEqual (gr.Key, p.Categories[0]);
+ Assert.AreEqual (gr.Count(), 2);
+
+ gr = g.ElementAt (1);
+ Assert.AreEqual (gr.Key, p.Categories[1]);
+ Assert.AreEqual (gr.Count(), 1);
+
+ gr = g.ElementAt (2);
+ Assert.AreEqual (gr.Key, p.Categories[2]);
+ Assert.AreEqual (gr.Count(), 3);
+
+ gr = g.ElementAt (3);
+ Assert.AreEqual (gr.Key, p.Categories[6]);
+ Assert.AreEqual (gr.Count(), 1);
+ }
+
+ [Test()]
+ public void Clear() {
+ }
+
+
+ [Test ()]
+ public void TestAddPlay () {
+ Project p = CreateProject ();
+ p.AddPlay (p.Categories[0], new Time (1000), new Time (2000), null);
+ Assert.AreEqual (p.AllPlays().Count, 1);
+ p.AddPlay (p.Categories[0], new Time (1000), new Time (2000), null);
+ Assert.AreEqual (p.AllPlays().Count, 2);
+ p.AddPlay (new Play());
+ Assert.AreEqual (p.AllPlays().Count, 3);
+ p.AddPlay (new Play());
+ Assert.AreEqual (p.AllPlays().Count, 4);
+ }
+
+ [Test ()]
+ public void TestRemovePlays () {
+ Play p1, p2, p3;
+ List<Play> plays = new List<Play> ();
+ Project p = CreateProject ();
+
+ p1 = new Play();
+ p2 = new Play();
+ p3 = new Play();
+ p.AddPlay (p1);
+ p.AddPlay (p2);
+ p.AddPlay (p3);
+ plays.Add(p1);
+ plays.Add(p2);
+ p.RemovePlays (plays);
+ Assert.AreEqual (p.AllPlays().Count, 1);
+ Assert.AreEqual (p.AllPlays()[0], p3);
+ }
+
+ [Test ()]
+ public void TestRemoveCategory () {
+ Project p = CreateProject ();
+ p.AddPlay (p.Categories[0], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[0], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[0], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[2], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[3], new Time (1000), new Time (2000), null);
+ p.RemoveCategory(p.Categories[0]);
+ Assert.AreEqual(p.AllPlays().Count, 2);
+ Assert.AreEqual(p.Categories.Count, 9);
+ p.RemoveCategory(p.Categories[0]);
+ p.RemoveCategory(p.Categories[0]);
+ p.RemoveCategory(p.Categories[0]);
+ p.RemoveCategory(p.Categories[0]);
+ p.RemoveCategory(p.Categories[0]);
+ p.RemoveCategory(p.Categories[0]);
+ p.RemoveCategory(p.Categories[0]);
+ p.RemoveCategory(p.Categories[0]);
+ Assert.Throws<Exception>(
+ delegate {p.RemoveCategory(p.Categories[0]);});
+ }
+
+ [Test ()]
+ public void TestRemovePlayer () {
+ Play play = new Play();
+ Project project = CreateProject ();
+ Player player = project.LocalTeamTemplate[0];
+ PlayerTag tag = new PlayerTag {Value=player};
+ play.Players.Add (tag);
+ project.AddPlay (play);
+ project.RemovePlayer (project.LocalTeamTemplate, player);
+ Assert.AreEqual (project.LocalTeamTemplate.Count, 9);
+ Assert.IsFalse (play.Players.Contains (tag));
+ }
+
+ [Test ()]
+ [Ignore ("FIXME")]
+ public void TestDeleteSubcategoryTags () {
+ }
+
+ [Test ()]
+ public void TestPlaysInCategory () {
+ Project p = CreateProject ();
+ p.AddPlay (p.Categories[0], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[0], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[0], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[2], new Time (1000), new Time (2000), null);
+ p.AddPlay (p.Categories[3], new Time (1000), new Time (2000), null);
+ Assert.AreEqual (p.PlaysInCategory (p.Categories[0]).Count, 3);
+ Assert.AreEqual (p.PlaysInCategory (p.Categories[1]).Count, 0);
+ Assert.AreEqual (p.PlaysInCategory (p.Categories[2]).Count, 1);
+ Assert.AreEqual (p.PlaysInCategory (p.Categories[3]).Count, 1);
+ }
+
+ [Test ()]
+ public void TestEquals () {
+ Project p1 = CreateProject();
+ Project p2 = Utils.SerializeDeserialize (p1);
+ Project p3 = new Project ();
+
+ Assert.IsTrue (p1.Equals(p2));
+ Assert.IsFalse (p1.Equals(p3));
+ }
+ }
+}
diff --git a/Tests/Core/TestProjectDescription.cs b/Tests/Core/TestProjectDescription.cs
new file mode 100644
index 0000000..546028b
--- /dev/null
+++ b/Tests/Core/TestProjectDescription.cs
@@ -0,0 +1,52 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+using LongoMatch.Common;
+using LongoMatch.Store;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestProjectDescription
+ {
+ [Test()]
+ public void TestSerialization ()
+ {
+ MediaFile mf = new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
+ "aac", 320, 240, 1.3, new Image (null));
+ ProjectDescription pd = new ProjectDescription ();
+ Utils.CheckSerialization (pd);
+
+ pd.File = mf;
+ pd.Competition = "Comp";
+ pd.LastModified = DateTime.Now;
+ pd.LocalGoals = 1;
+ pd.VisitorGoals = 2;
+ pd.MatchDate = DateTime.Now;
+ pd.Season = "Season";
+
+ Utils.CheckSerialization (pd);
+
+ ProjectDescription newpd = Utils.SerializeDeserialize(pd);
+ Assert.AreEqual (pd.CompareTo (newpd), 0);
+ Assert.AreEqual (pd.UUID, newpd.UUID);
+ }
+ }
+}
+
diff --git a/Tests/Core/TestSubCategory.cs b/Tests/Core/TestSubCategory.cs
new file mode 100644
index 0000000..0b74c79
--- /dev/null
+++ b/Tests/Core/TestSubCategory.cs
@@ -0,0 +1,88 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.IO;
+using System.Collections.Generic;
+using NUnit.Framework;
+
+using LongoMatch.Common;
+using LongoMatch.Store;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestSubCategory
+ {
+ [Test()]
+ public void TestTagSubcategoryProps ()
+ {
+ string tag1="tag1", tag2="tag2";
+ List<string> elementsDesc;
+ TagSubCategory subcat = new TagSubCategory {Name="Test",
+ AllowMultiple = true, FastTag = true};
+
+ subcat.Add (tag1);
+ subcat.Add (tag2);
+ elementsDesc = subcat.ElementsDesc ();
+ Assert.AreEqual (elementsDesc.Count, 2);
+ Assert.AreEqual (elementsDesc[0], tag1);
+ Assert.AreEqual (elementsDesc[1], tag2);
+ }
+
+
+ [Test()]
+ public void TestTagSubcategorySerialization ()
+ {
+ string tag1="tag1", tag2="tag2";
+ List<string> elementsDesc;
+ MemoryStream stream;
+ TagSubCategory subcat, newsubcat;
+
+ subcat = new TagSubCategory {Name="Test",
+ AllowMultiple = true, FastTag = true};
+ subcat.Add (tag1);
+ subcat.Add (tag2);
+
+ Utils.CheckSerialization (subcat);
+
+ stream = new MemoryStream ();
+ SerializableObject.Save (subcat, stream, SerializationType.Json);
+ stream.Seek (0, SeekOrigin.Begin);
+ var reader = new StreamReader (stream);
+ var jsonString = reader.ReadToEnd();
+ Console.WriteLine (jsonString);
+ /* Count property is removed */
+ Assert.False (jsonString.Contains ("Count"));
+ Assert.True (jsonString.Contains ("_items"));
+ Assert.True (jsonString.Contains ("_size"));
+ stream.Seek (0, SeekOrigin.Begin);
+
+ newsubcat = SerializableObject.Load<TagSubCategory> (stream, SerializationType.Json);
+
+ Assert.AreEqual (subcat.Name, newsubcat.Name);
+ Assert.AreEqual (subcat.AllowMultiple, newsubcat.AllowMultiple);
+ Assert.AreEqual (subcat.Count, newsubcat.Count);
+ Assert.AreEqual (subcat.FastTag, newsubcat.FastTag);
+ elementsDesc = newsubcat.ElementsDesc ();
+ Assert.AreEqual (elementsDesc.Count, 2);
+ Assert.AreEqual (elementsDesc[0], tag1);
+ Assert.AreEqual (elementsDesc[1], tag2);
+ }
+ }
+}
+
diff --git a/Tests/Core/TestSubcategoriesTemplate.cs b/Tests/Core/TestSubcategoriesTemplate.cs
new file mode 100644
index 0000000..769a25c
--- /dev/null
+++ b/Tests/Core/TestSubcategoriesTemplate.cs
@@ -0,0 +1,54 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+using LongoMatch.Common;
+using LongoMatch.Store;
+using LongoMatch.Store.Templates;
+using System.Collections.Generic;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestSubcategoriesTemplate
+ {
+ [Test()]
+ public void TestSerialization ()
+ {
+ string tag1="tag1", tag2="tag2";
+ SubCategoryTemplate t = new SubCategoryTemplate {Name="Test",
+ AllowMultiple = true, FastTag = true};
+
+ Utils.CheckSerialization (t);
+ t.Add (tag1);
+ t.Add (tag2);
+ Utils.CheckSerialization (t);
+
+ SubCategoryTemplate newt = Utils.SerializeDeserialize (t);
+ Assert.AreEqual (t.Name, newt.Name);
+ Assert.AreEqual (t.AllowMultiple, newt.AllowMultiple);
+ Assert.AreEqual (t.Count, newt.Count);
+ Assert.AreEqual (t.FastTag, newt.FastTag);
+ Assert.AreEqual (t.Count, 2);
+ Assert.AreEqual (t[0], tag1);
+ Assert.AreEqual (t[1], tag2);
+
+ }
+ }
+}
+
diff --git a/Tests/Core/TestTagStore.cs b/Tests/Core/TestTagStore.cs
new file mode 100644
index 0000000..bde6687
--- /dev/null
+++ b/Tests/Core/TestTagStore.cs
@@ -0,0 +1,139 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+
+using LongoMatch.Common;
+using LongoMatch.Store;
+using System.IO;
+
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TagStore
+ {
+ StringTag tag1, tag2, tag3, tag4;
+ SubCategory<string> subcat1, subcat2, subcat3;
+ StringTagStore store;
+
+ void FillStore () {
+ store = new StringTagStore ();
+ subcat1 = new SubCategory<string> {Name = "subcat1"};
+ subcat2 = new SubCategory<string> {Name = "subcat2"};
+ subcat3 = new SubCategory<string> {Name = "subcat3"};
+ tag1 = new StringTag {SubCategory=subcat1, Value="tag1"};
+ tag2 = new StringTag {SubCategory=subcat1, Value="tag2"};
+ tag3 = new StringTag {SubCategory=subcat2, Value="tag3"};
+ tag4 = new StringTag {SubCategory=subcat3, Value="tag4"};
+ store.Add (tag1);
+ store.Add (tag2);
+ store.Add (tag3);
+ store.Add (tag4);
+ }
+
+ [Test()]
+ public void TestAddRemove ()
+ {
+ FillStore ();
+ Assert.AreEqual (store.Tags.Count, 4);
+ Assert.True (store.Contains (tag4));
+ store.Remove (tag4);
+ Assert.False (store.Contains (tag4));
+ Assert.AreEqual (store.Tags.Count, 3);
+ store.Add (tag4);
+ Assert.AreEqual (store.Tags.Count, 4);
+ Assert.True (store.Contains (tag4));
+ }
+
+ [Test()]
+ public void TestRemoveByCategory ()
+ {
+ FillStore ();
+ store.RemoveBySubcategory (subcat1);
+ Assert.AreEqual (store.Tags.Count, 2);
+ store.RemoveBySubcategory (subcat2);
+ Assert.AreEqual (store.Tags.Count, 1);
+ store.RemoveBySubcategory (subcat3);
+ Assert.AreEqual (store.Tags.Count, 0);
+ }
+
+ [Test()]
+ public void TestUniqueElements ()
+ {
+ FillStore ();
+
+ Assert.AreEqual (store.AllUniqueElements.Count, 4);
+ var tag = new StringTag {SubCategory=subcat1, Value="tag1"};
+ store.Add (tag);
+ Assert.AreEqual (store.AllUniqueElements.Count, 4);
+ }
+
+ [Test()]
+ public void TestGetTags ()
+ {
+ FillStore ();
+
+ Assert.AreEqual (store.GetTags (subcat1).Count, 2);
+ Assert.AreEqual (store.GetTags (subcat2).Count, 1);
+ Assert.AreEqual (store.GetTags (subcat3).Count, 1);
+ }
+
+ [Test()]
+ public void TestTagValues ()
+ {
+ FillStore ();
+
+ var values = store.GetTagsValues();
+ Assert.AreEqual (values[0], "tag1");
+ Assert.AreEqual (values[1], "tag2");
+ Assert.AreEqual (values[2], "tag3");
+ Assert.AreEqual (values[3], "tag4");
+ }
+
+ [Test()]
+ public void TestRemoveByPlayer ()
+ {
+ var store = new PlayersTagStore ();
+ var subcat1 = new SubCategory<string> {Name = "subcat1"};
+ var player1 = new Player ();
+ var player2 = new Player ();
+ var tag1 = new PlayerTag {SubCategory=subcat1, Value=player1};
+ var tag2 = new PlayerTag {SubCategory=subcat1, Value=player2};
+ store.Add (tag1);
+ store.Add (tag2);
+
+ store.RemoveByPlayer (player1);
+ Assert.AreEqual (store.Tags.Count, 1);
+ store.RemoveByPlayer (player2);
+ Assert.AreEqual (store.Tags.Count, 0);
+ }
+
+ [Test()]
+ public void TestSerialization ()
+ {
+ FillStore ();
+
+ Utils.CheckSerialization (store);
+
+ var newstore = Utils.SerializeDeserialize (store);
+ Assert.AreEqual (store.Tags.Count, newstore.Tags.Count);
+ }
+ }
+}
+
diff --git a/Tests/Core/TestTeamTemplate.cs b/Tests/Core/TestTeamTemplate.cs
new file mode 100644
index 0000000..f2ef1a8
--- /dev/null
+++ b/Tests/Core/TestTeamTemplate.cs
@@ -0,0 +1,94 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+using LongoMatch.Common;
+using LongoMatch.Store;
+using LongoMatch.Store.Templates;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestTeamTemplate
+ {
+ [Test()]
+ public void TestSerialization ()
+ {
+ TeamTemplate t = new TeamTemplate();
+
+ Utils.CheckSerialization(t);
+
+ t.Name = "test";
+ t.Version = new Version (1, 2);
+ t.TeamName = "team";
+ t.Add (new Player {Name="P1"});
+ t.Add (new Player {Name="P2"});
+ t.Add (new Player {Name="P3"});
+
+
+ Utils.CheckSerialization (t);
+
+ TeamTemplate newt = Utils.SerializeDeserialize(t);
+
+ Assert.AreEqual (t.Name, newt.Name);
+ Assert.AreEqual (t.Version, newt.Version);
+ Assert.AreEqual (t.TeamName, newt.TeamName);
+ Assert.AreEqual (t.Count, newt.Count);
+ Assert.AreEqual (t[0].Name, newt[0].Name);
+ Assert.AreEqual (t[1].Name, newt[1].Name);
+ Assert.AreEqual (t[2].Name, newt[2].Name);
+ }
+
+
+ [Test()]
+ public void TestPlayingPlayers ()
+ {
+ TeamTemplate t = new TeamTemplate();
+ Player p1, p2, p3;
+
+ t.Name = "test";
+ t.Version = new Version (1, 2);
+ t.TeamName = "team";
+
+ Assert.AreEqual (t.PlayingPlayersList.Count, 0);
+
+ p1 = new Player {Name="P1", Playing = true};
+ p2 = new Player {Name="P2", Playing = false};
+ p3 = new Player {Name="P3", Playing = true};
+ t.Add (p1);
+ Assert.AreEqual (t.PlayingPlayersList.Count, 1);
+ t.Add (p2);
+ Assert.AreEqual (t.PlayingPlayersList.Count, 1);
+ t.Add (p3);
+ Assert.AreEqual (t.PlayingPlayersList.Count, 2);
+ Assert.AreEqual (t.PlayingPlayersList[0], p1);
+ Assert.AreEqual (t.PlayingPlayersList[1], p3);
+ }
+
+ [Test()]
+ public void TestCreateDefaultTemplate ()
+ {
+ TeamTemplate t = TeamTemplate.DefaultTemplate (10);
+
+ Assert.AreEqual (t.Count, 10);
+ t.AddDefaultItem (8);
+ Assert.AreEqual (t.Count, 11);
+ }
+
+ }
+}
diff --git a/Tests/Core/TestTimeNode.cs b/Tests/Core/TestTimeNode.cs
new file mode 100644
index 0000000..6c3b42e
--- /dev/null
+++ b/Tests/Core/TestTimeNode.cs
@@ -0,0 +1,59 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+using LongoMatch.Common;
+using LongoMatch.Store;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestTimeNode
+ {
+ [Test()]
+ public void TestSerialization ()
+ {
+ TimeNode tn = new TimeNode();
+
+ Utils.CheckSerialization (tn);
+
+ tn.Start = new Time (1000);
+ tn.Stop = new Time (2000);
+ tn.Name = "Test";
+ tn.Rate = 2.0f;
+
+ Utils.CheckSerialization (tn);
+
+ TimeNode newtn = Utils.SerializeDeserialize (tn);
+ Assert.AreEqual (tn.Start, newtn.Start);
+ Assert.AreEqual (tn.Stop, newtn.Stop);
+ Assert.AreEqual (tn.Name, newtn.Name);
+ Assert.AreEqual (tn.Rate, newtn.Rate);
+ }
+
+ [Test()]
+ public void TestDuration ()
+ {
+ TimeNode tn = new TimeNode();
+ tn.Start = new Time (1000);
+ tn.Stop = new Time (2000);
+ Assert.AreEqual (tn.Duration, tn.Stop - tn.Start);
+ }
+ }
+}
+
diff --git a/Tests/Services/TestDatabase.cs b/Tests/Services/TestDatabase.cs
new file mode 100644
index 0000000..59dcb90
--- /dev/null
+++ b/Tests/Services/TestDatabase.cs
@@ -0,0 +1,198 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Collections.Generic;
+using System.IO;
+using NUnit.Framework;
+
+using LongoMatch.DB;
+using LongoMatch.Store;
+
+namespace Tests.Services
+{
+ [TestFixture()]
+ public class TestDatabase
+ {
+ string tmpdir;
+
+ [SetUp] public void CreateDBDir()
+ {
+ do {
+ tmpdir = Path.GetTempPath() + Guid.NewGuid().ToString();
+ } while (Directory.Exists(tmpdir));
+ }
+
+ [TearDown] public void DeleteDBDir()
+ {
+ try {
+ Directory.Delete (tmpdir);
+ } catch (Exception) {
+ }
+ }
+
+ [Test()]
+ public void TestCreateEmptyDatabase ()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ Assert.IsTrue (Directory.Exists (dbdir));
+ Assert.IsTrue (File.Exists (Path.Combine (dbdir, "test.ldb")));
+ Assert.AreEqual (db.Count, 0);
+ }
+
+ [Test()]
+ public void TestLoadExistingDatabase ()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ DataBase newdb = new DataBase (dbdir);
+ Assert.AreEqual (db.LastBackup, newdb.LastBackup);
+ }
+
+ [Test()]
+ public void TestReloadDB ()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ db.AddProject (new Project {Description = new ProjectDescription()});
+ File.Delete (Path.Combine (dbdir, "test.ldb"));
+ db = new DataBase (dbdir);
+ Assert.IsTrue (File.Exists (Path.Combine (dbdir, "test.ldb")));
+ Assert.AreEqual (db.Count, 1);
+ }
+
+ [Test()]
+ public void TestDBWithErrorProject ()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ db.AddProject (new Project {Description = new ProjectDescription()});
+ var writer = File.CreateText (Path.Combine (dbdir, "wrongfile"));
+ writer.WriteLine("TEST&%&$&%");
+ writer.WriteLine("}~4");
+ writer.Flush();
+ writer.Close();
+ File.Delete (Path.Combine (dbdir, "test.ldb"));
+ db = new DataBase (dbdir);
+ Assert.AreEqual (db.Count, 1);
+ }
+
+ [Test()]
+ public void TestGetAllProjects()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ ProjectDescription pd1 = new ProjectDescription ();
+ ProjectDescription pd2 = new ProjectDescription ();
+ Project p1 = new Project {Description = pd1};
+ Project p2 = new Project {Description = pd2};
+ db.AddProject (p1);
+ db.AddProject (p2);
+ Assert.AreEqual (db.Count, 2);
+ List<ProjectDescription> projects = db.GetAllProjects ();
+ Assert.AreEqual (db.Count, 2);
+ Assert.AreEqual (projects.Count, 2);
+ Assert.AreEqual (projects[0], pd1);
+ Assert.AreEqual (projects[1], pd2);
+ }
+
+ [Test()]
+ public void TestGetProject()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ ProjectDescription pd1 = new ProjectDescription ();
+ Project p1 = new Project {Description = pd1};
+ db.AddProject (p1);
+ Project p2 = db.GetProject (p1.UUID);
+ Assert.AreEqual (p1.UUID, p2.UUID);
+ Assert.IsNull (db.GetProject (new Guid()));
+ }
+
+ [Test()]
+ public void TestAddProject()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ ProjectDescription pd1 = new ProjectDescription ();
+ Project p1 = new Project {Description = pd1};
+ Assert.IsTrue (db.AddProject (p1));
+ Assert.IsTrue (File.Exists (Path.Combine (dbdir, p1.UUID.ToString())));
+ Assert.IsTrue (db.AddProject (p1));
+ Assert.AreEqual (db.Count, 1);
+ }
+
+ [Test()]
+ public void TestRemoveProject()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ ProjectDescription pd1 = new ProjectDescription ();
+ Project p1 = new Project {Description = pd1};
+ Assert.IsTrue (db.AddProject (p1));
+ Assert.IsTrue (File.Exists (Path.Combine (dbdir, p1.UUID.ToString())));
+ Assert.AreEqual (db.Count, 1);
+ Assert.IsTrue (db.RemoveProject (p1.UUID));
+ Assert.IsFalse (File.Exists (Path.Combine (dbdir, p1.UUID.ToString())));
+ Assert.AreEqual (db.Count, 0);
+ Assert.IsFalse (db.RemoveProject (p1.UUID));
+ }
+
+ [Test()]
+ public void TestUpdateProject()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ ProjectDescription pd1 = new ProjectDescription ();
+ Project p1 = new Project {Description = pd1};
+ DateTime lastModified = p1.Description.LastModified;
+ Assert.IsTrue (db.AddProject (p1));
+ Assert.IsTrue (db.UpdateProject (p1));
+ Assert.AreNotEqual (p1.Description.LastModified, lastModified);
+ }
+
+ [Test()]
+ public void TestExists()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ ProjectDescription pd1 = new ProjectDescription ();
+ Project p1 = new Project {Description = pd1};
+ Assert.IsFalse (db.Exists (p1));
+ db.AddProject (p1);
+ Assert.IsTrue (db.Exists (p1));
+ }
+
+ [Test()]
+ public void TestBackup ()
+ {
+ }
+
+ [Test()]
+ public void TestDelete ()
+ {
+ string dbdir = Path.Combine (tmpdir, "test.ldb");
+ DataBase db = new DataBase (dbdir);
+ Assert.IsTrue (Directory.Exists (dbdir));
+ db.Delete ();
+ Assert.IsFalse (Directory.Exists (dbdir));
+ db.Delete ();
+ }
+ }
+}
+
diff --git a/Tests/Services/TestDatabasesManager.cs b/Tests/Services/TestDatabasesManager.cs
new file mode 100644
index 0000000..08be1b8
--- /dev/null
+++ b/Tests/Services/TestDatabasesManager.cs
@@ -0,0 +1,32 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+
+namespace Tests.Services
+{
+ [TestFixture()]
+ public class TestDatabasesManager
+ {
+ [Test()]
+ public void TestCase ()
+ {
+ }
+ }
+}
+
diff --git a/Tests/Tests.mdp b/Tests/Tests.mdp
new file mode 100644
index 0000000..c0cce63
--- /dev/null
+++ b/Tests/Tests.mdp
@@ -0,0 +1,48 @@
+<Project name="Tests" fileversion="2.0" DefaultNamespace="Tests" language="C#" targetFramework="4.0"
ctype="DotNetProject">
+ <Configurations active="Release">
+ <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+ <Output directory="bin/Debug" assembly="Tests" />
+ <Build debugmode="True" target="Exe" />
+ <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False"
generateoverflowchecks="False" definesymbols="DEBUG;" generatexmldocumentation="False"
ctype="CSharpCompilerParameters" />
+ </Configuration>
+ <Configuration name="Release" ctype="DotNetProjectConfiguration">
+ <Output directory="bin/Release" assembly="Tests" />
+ <Build debugmode="False" target="Exe" />
+ <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False"
generateoverflowchecks="False" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+ </Configuration>
+ </Configurations>
+ <Contents>
+ <File subtype="Code" buildaction="Compile" name="Utils.cs" />
+ <File subtype="Directory" buildaction="Compile" name="Core" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestCategory.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestCoordinates.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestDrawing.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestMediaFile.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestPlay.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestPlayer.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestPoint.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestProject.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestProjectDescription.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestSubCategory.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestTagStore.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestTimeNode.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestCategoriesTemplate.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestTeamTemplate.cs" />
+ <File subtype="Code" buildaction="Compile" name="Core/TestSubcategoriesTemplate.cs" />
+ <File subtype="Directory" buildaction="Compile" name="Services" />
+ <File subtype="Code" buildaction="Compile" name="Services/TestDatabase.cs" />
+ <File subtype="Code" buildaction="Compile" name="Services/TestDatabasesManager.cs" />
+ </Contents>
+ <References>
+ <ProjectReference type="Gac" localcopy="False" refto="nunit.core, Version=2.6.0.0, Culture=neutral,
PublicKeyToken=96d09a1eb7f44a77" />
+ <ProjectReference type="Gac" localcopy="False" refto="nunit.framework, Version=2.6.0.0, Culture=neutral,
PublicKeyToken=96d09a1eb7f44a77" />
+ <ProjectReference specificVersion="False" type="Gac" localcopy="False" refto="System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Project" localcopy="True" refto="LongoMatch.Core" />
+ <ProjectReference type="Gac" localcopy="False" refto="Newtonsoft.Json, Version=5.0.0.0, Culture=neutral,
PublicKeyToken=b9a188c8922137c6" />
+ <ProjectReference specificVersion="False" type="Gac" localcopy="False" refto="System.Drawing,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <ProjectReference specificVersion="False" type="Gac" localcopy="False" refto="System.Core,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Project" localcopy="True" refto="LongoMatch.Services" />
+ </References>
+</Project>
\ No newline at end of file
diff --git a/Tests/Utils.cs b/Tests/Utils.cs
new file mode 100644
index 0000000..240c761
--- /dev/null
+++ b/Tests/Utils.cs
@@ -0,0 +1,61 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.IO;
+using LongoMatch.Common;
+using NUnit.Framework;
+
+namespace Tests
+{
+ public class Utils
+ {
+ public Utils ()
+ {
+ }
+
+ public static T SerializeDeserialize<T> (T obj) {
+ var stream = new MemoryStream ();
+ SerializableObject.Save (obj, stream, SerializationType.Json);
+ stream.Seek (0, SeekOrigin.Begin);
+ var jsonString = new StreamReader(stream).ReadToEnd();
+ Console.WriteLine (jsonString);
+ stream.Seek(0, SeekOrigin.Begin);
+
+ return SerializableObject.Load<T>(stream, SerializationType.Json);
+ }
+
+ public static void CheckSerialization<T> (T obj) {
+ var stream = new MemoryStream ();
+ SerializableObject.Save (obj, stream, SerializationType.Json);
+ stream.Seek (0, SeekOrigin.Begin);
+ var jsonString = new StreamReader(stream).ReadToEnd();
+ Console.WriteLine (jsonString);
+ stream.Seek(0, SeekOrigin.Begin);
+
+ var newobj = SerializableObject.Load<T>(stream, SerializationType.Json);
+
+ stream = new MemoryStream ();
+ SerializableObject.Save (newobj, stream, SerializationType.Json);
+ stream.Seek(0, SeekOrigin.Begin);
+ var newJsonString = new StreamReader(stream).ReadToEnd();
+ Console.WriteLine (newJsonString);
+ Assert.AreEqual (jsonString, newJsonString);
+ }
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]