[longomatch] Add more unit tests



commit b762189cece1ca2a70e2c2f4d0697db8d96637fd
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Mar 5 13:32:13 2015 +0100

    Add more unit tests

 LongoMatch.Core/Store/ProjectDescription.cs |    5 +
 Tests/Core/Store/Templates/TestDashboard.cs |    6 +-
 Tests/Core/Store/TestProject.cs             |  269 +++++++++++++++++++++++++++
 Tests/Core/Store/TestProjectDescription.cs  |   78 ++++++++
 Tests/Core/Store/TestTag.cs                 |   33 ++++
 Tests/Core/Store/TestTimer.cs               |   33 ++++
 Tests/Core/TestProject.cs                   |  195 -------------------
 Tests/Core/TestProjectDescription.cs        |   52 -----
 Tests/Makefile.am                           |    4 +
 Tests/Tests.csproj                          |    4 +
 10 files changed, 429 insertions(+), 250 deletions(-)
---
diff --git a/LongoMatch.Core/Store/ProjectDescription.cs b/LongoMatch.Core/Store/ProjectDescription.cs
index b9d0ea4..65b0543 100644
--- a/LongoMatch.Core/Store/ProjectDescription.cs
+++ b/LongoMatch.Core/Store/ProjectDescription.cs
@@ -31,6 +31,11 @@ namespace LongoMatch.Core.Store
        {
                DateTime matchDate, lastModified;
 
+               public ProjectDescription ()
+               {
+                       MatchDate = LastModified = DateTime.Now;
+               }
+
                /// <summary>
                /// Unique ID of the parent project
                /// </summary>
diff --git a/Tests/Core/Store/Templates/TestDashboard.cs b/Tests/Core/Store/Templates/TestDashboard.cs
index 68f357e..91d5c2c 100644
--- a/Tests/Core/Store/Templates/TestDashboard.cs
+++ b/Tests/Core/Store/Templates/TestDashboard.cs
@@ -25,7 +25,7 @@ using LongoMatch.Core.Store.Templates;
 namespace Tests.Core
 {
        [TestFixture()]
-       public class TestCategoriesTemplate
+       public class TestDashboard
        {
                [Test()]
                public void TestSerialization ()
@@ -38,8 +38,8 @@ namespace Tests.Core
                        cat.GamePeriods = new List<string> ();
                        cat.GamePeriods.Add ("1");
                        cat.GamePeriods.Add ("2");
-                       cat.List.Add ( new CategoryButton {Name = "cat1"});
-                       cat.List.Add ( new CategoryButton {Name = "cat2"});
+                       cat.List.Add ( new AnalysisEventButton {Name = "cat1"});
+                       cat.List.Add ( new {Name = "cat2"});
                        cat.List.Add ( new CategoryButton {Name = "cat3"});
                        
                        Utils.CheckSerialization (cat);
diff --git a/Tests/Core/Store/TestProject.cs b/Tests/Core/Store/TestProject.cs
new file mode 100644
index 0000000..1773496
--- /dev/null
+++ b/Tests/Core/Store/TestProject.cs
@@ -0,0 +1,269 @@
+//
+//  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.Core.Common;
+using LongoMatch.Core.Store;
+using LongoMatch.Core.Store.Templates;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Tests.Core.Store
+{
+       [TestFixture ()]
+       public class TestProject
+       {
+       
+               Project CreateProject (bool fill = true)
+               {
+                       Project p = new Project ();
+                       p.Dashboard = Dashboard.DefaultTemplate (10);
+                       p.UpdateEventTypesAndTimers ();
+                       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, null);
+                       ProjectDescription pd = new ProjectDescription ();
+                       pd.FileSet = new MediaFileSet ();
+                       pd.FileSet.SetAngle (MediaFileAngle.Angle1, mf);
+                       p.Description = pd;
+                       if (fill) {
+                               p.AddEvent (p.EventTypes [0], new Time (1000), new Time (2000), null, null, 
null, null);
+                               p.AddEvent (p.EventTypes [0], new Time (1000), new Time (2000), null, null, 
null, null);
+                               p.AddEvent (p.EventTypes [1], new Time (1000), new Time (2000), null, null, 
null, null);
+                               p.AddEvent (p.EventTypes [2], new Time (1000), new Time (2000), null, null, 
null, null);
+                               p.AddEvent (p.EventTypes [2], new Time (1000), new Time (2000), null, null, 
null, null);
+                               p.AddEvent (p.EventTypes [2], new Time (1000), new Time (2000), null, null, 
null, null);
+                               p.AddEvent (p.EventTypes [6], new Time (1000), new Time (2000), null, null, 
null, null);
+                       }
+
+                       return p;
+               }
+
+               [Test ()]
+               public void TestSerialization ()
+               {
+                       Project p = new Project ();
+                       
+                       Utils.CheckSerialization (p);
+                       
+                       p = CreateProject ();
+                       Utils.CheckSerialization (p);
+                       p.AddEvent (new TimelineEvent ());
+                       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.Timeline.Count, p.Timeline.Count);
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void TestSetDescription ()
+               {
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void TestGetScores ()
+               {
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void TestGetPenaltyCards ()
+               {
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void TestGetScoreEvents ()
+               {
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void TestGetPenaltyCardEvents ()
+               {
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void TestGetSubstitutionEventType ()
+               {
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void TestGetLineup ()
+               {
+               }
+
+               [Test ()]
+               public void TestEventsGroupedByEventType ()
+               {
+                       Project p = CreateProject ();
+                       var g = p.PlaysGroupedByEventType;
+                       Assert.AreEqual (g.Count (), 4);
+                       var gr = g.ElementAt (0);
+                       Assert.AreEqual (p.EventTypes[0], gr.Key);
+                       Assert.AreEqual (2, gr.Count ());
+                       
+                       gr = g.ElementAt (1);
+                       Assert.AreEqual (p.EventTypes[1], gr.Key);
+                       Assert.AreEqual (1, gr.Count ());
+                       
+                       gr = g.ElementAt (2);
+                       Assert.AreEqual (p.EventTypes[2], gr.Key);
+                       Assert.AreEqual (3, gr.Count ());
+                       
+                       gr = g.ElementAt (3);
+                       Assert.AreEqual (p.EventTypes[6], gr.Key);
+                       Assert.AreEqual (1, gr.Count ());
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void Clear ()
+               {
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void UpdateScore ()
+               {
+               }
+
+
+               [Test ()]
+               public void TestAddEvent ()
+               {
+                       Project p = CreateProject (false);
+                       p.AddEvent (p.EventTypes [0], new Time (1000), new Time (2000), null, null, null, 
null, false);
+                       Assert.AreEqual (p.Timeline.Count, 0);
+                       p.AddEvent (p.EventTypes [0], new Time (1000), new Time (2000), null, null, null, 
null);
+                       Assert.AreEqual (p.Timeline.Count, 1);
+                       p.AddEvent (p.EventTypes [0], new Time (1000), new Time (2000), null, null, null, 
null);
+                       Assert.AreEqual (p.Timeline.Count, 2);
+                       p.AddEvent (new TimelineEvent ());
+                       Assert.AreEqual (p.Timeline.Count, 3);
+                       p.AddEvent (new TimelineEvent ());
+                       Assert.AreEqual (p.Timeline.Count, 4);
+                       /*FIXME: add test for score event updating pd score */
+               }
+
+               [Test ()]
+               public void TestRemoveEvents ()
+               {
+                       TimelineEvent p1, p2, p3;
+                       List<TimelineEvent> plays = new List<TimelineEvent> ();
+                       Project p = CreateProject (false);
+                       
+                       p1 = new TimelineEvent ();
+                       p2 = new TimelineEvent ();
+                       p3 = new TimelineEvent ();
+                       p.AddEvent (p1);
+                       p.AddEvent (p2);
+                       p.AddEvent (p3);
+                       plays.Add (p1);
+                       plays.Add (p2);
+                       p.RemovePlays (plays);
+                       Assert.AreEqual (p.Timeline.Count, 1);
+                       Assert.AreEqual (p.Timeline [0], p3);
+               }
+
+               [Test ()] 
+               [Ignore("Not implemented")]
+               public void TestCleanupTimers ()
+               {
+               }
+
+               [Test ()] 
+               [Ignore("Not implemented")]
+               public void TestUpdateEventTypesAndTimers ()
+               {
+               }
+
+               [Test ()] 
+               [Ignore("Not implemented")]
+               public void TestSubstituePlayer ()
+               {
+               }
+
+               [Test ()] 
+               [Ignore("Not implemented")]
+               public void TestCurrentLineup ()
+               {
+               }
+
+               [Test ()] 
+               public void TestEventsByType ()
+               {
+                       Project p = CreateProject ();
+                       Assert.AreEqual (2, p.EventsByType (p.EventTypes [0]).Count);
+                       Assert.AreEqual (1, p.EventsByType (p.EventTypes [1]).Count);
+                       Assert.AreEqual (3, p.EventsByType (p.EventTypes [2]).Count);
+                       Assert.AreEqual (0, p.EventsByType (p.EventTypes [3]).Count);
+                       Assert.AreEqual (1, p.EventsByType (p.EventTypes [6]).Count);
+               }
+
+               [Test ()] 
+               [Ignore("Not implemented")]
+               public void TestGetScore ()
+               {
+               }
+
+               [Test ()] 
+               [Ignore("Not implemented")]
+               public void TestEventTaggedTeam ()
+               {
+               }
+
+               [Test ()] 
+               [Ignore("Not implemented")]
+               public void TestConsolidateDescription ()
+               {
+               }
+
+               [Test ()] 
+               [Ignore("Not implemented")]
+               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));
+               }
+
+               [Test ()] 
+               [Ignore("Not implemented")]
+               public void TestExport ()
+               {
+               }
+
+               [Test ()] 
+               [Ignore("Not implemented")]
+               public void TestImport ()
+               {
+               }
+       }
+}
diff --git a/Tests/Core/Store/TestProjectDescription.cs b/Tests/Core/Store/TestProjectDescription.cs
new file mode 100644
index 0000000..e9a918c
--- /dev/null
+++ b/Tests/Core/Store/TestProjectDescription.cs
@@ -0,0 +1,78 @@
+//
+//  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.Core.Common;
+using LongoMatch.Core.Store;
+
+namespace Tests.Core.Store
+{
+       [TestFixture ()]
+       public class TestProjectDescription
+       {
+               [Test ()]
+               public void TestSerialization ()
+               {
+                       MediaFile mf = new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
+                                              "aac", 320, 240, 1.3, null);
+                       ProjectDescription pd = new ProjectDescription ();
+                       Utils.CheckSerialization (pd);
+                       
+                       pd.FileSet = new MediaFileSet ();
+                       pd.FileSet.SetAngle (MediaFileAngle.Angle1, mf);
+                       pd.Competition = "Comp";
+                       pd.Category = "Cat";
+                       pd.Group = "Group";
+                       pd.Phase = "Phase";
+                       pd.Season = "Season";
+                       pd.LastModified = DateTime.UtcNow.ToUniversalTime ();
+                       pd.LocalGoals = 1;
+                       pd.VisitorGoals = 2;
+                       pd.MatchDate = DateTime.UtcNow.ToUniversalTime ();
+
+                       Utils.CheckSerialization (pd);
+                       
+                       ProjectDescription newpd = Utils.SerializeDeserialize (pd);
+                       Assert.AreEqual (pd.CompareTo (newpd), 0);
+                       Assert.AreEqual (pd.FileSet.GetAngle (MediaFileAngle.Angle1).FilePath,
+                               newpd.FileSet.GetAngle (MediaFileAngle.Angle1).FilePath);
+                       Assert.AreEqual (pd.ID, newpd.ID);
+                       Assert.AreEqual (pd.Competition, newpd.Competition);
+                       Assert.AreEqual (pd.Category, newpd.Category);
+                       Assert.AreEqual (pd.Group, newpd.Group);
+                       Assert.AreEqual (pd.Phase, newpd.Phase);
+                       Assert.AreEqual (pd.Season, newpd.Season);
+                       Assert.AreEqual (pd.LocalGoals, newpd.LocalGoals);
+                       Assert.AreEqual (pd.VisitorGoals, newpd.VisitorGoals);
+                       Assert.AreEqual (pd.MatchDate, newpd.MatchDate);
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void TestSort ()
+               {
+               }
+
+               [Test ()]
+               [Ignore("Not implemented")]
+               public void TestSearch ()
+               {
+               }
+       }
+}
+
diff --git a/Tests/Core/Store/TestTag.cs b/Tests/Core/Store/TestTag.cs
new file mode 100644
index 0000000..9b39fc0
--- /dev/null
+++ b/Tests/Core/Store/TestTag.cs
@@ -0,0 +1,33 @@
+//
+//  Copyright (C) 2015 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 NUnit.Framework;
+using System;
+
+namespace Tests.Core.Store
+{
+       [TestFixture ()]
+       public class TestTag
+       {
+               [Test ()]
+               [Ignore ("Not implemented")]
+               public void TestCase ()
+               {
+               }
+       }
+}
+
diff --git a/Tests/Core/Store/TestTimer.cs b/Tests/Core/Store/TestTimer.cs
new file mode 100644
index 0000000..f0ca144
--- /dev/null
+++ b/Tests/Core/Store/TestTimer.cs
@@ -0,0 +1,33 @@
+//
+//  Copyright (C) 2015 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 NUnit.Framework;
+using System;
+
+namespace Tests.Core.Store
+{
+       [TestFixture ()]
+       public class TestTimer
+       {
+               [Test ()]
+               [Ignore ("Not implemented")]
+               public void TestCase ()
+               {
+               }
+       }
+}
+
diff --git a/Tests/Makefile.am b/Tests/Makefile.am
index a76498b..3834725 100644
--- a/Tests/Makefile.am
+++ b/Tests/Makefile.am
@@ -26,10 +26,14 @@ SOURCES = Core/Common/TestColor.cs \
        Core/Store/TestPlayer.cs \
        Core/Store/TestPlaysFilter.cs \
        Core/Store/TestPoint.cs \
+       Core/Store/TestProject.cs \
+       Core/Store/TestProjectDescription.cs \
        Core/Store/TestScore.cs \
+       Core/Store/TestTag.cs \
        Core/Store/TestTime.cs \
        Core/Store/TestTimeNode.cs \
        Core/Store/TestTimelineEvent.cs \
+       Core/Store/TestTimer.cs \
        Utils.cs
 
 RESOURCES = Core/dibujo.svg
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 1be40e1..5843200 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -65,6 +65,10 @@
     <Compile Include="Core\Store\Drawables\TestText.cs" />
     <Compile Include="Core\Common\TestImage.cs" />
     <Compile Include="Core\Store\Templates\TestTeamTemplate.cs" />
+    <Compile Include="Core\Store\TestProject.cs" />
+    <Compile Include="Core\Store\TestProjectDescription.cs" />
+    <Compile Include="Core\Store\TestTimer.cs" />
+    <Compile Include="Core\Store\TestTag.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\LongoMatch.Core\LongoMatch.Core.csproj">


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]