[longomatch] Refactor some tests and add more tests for DB projects



commit b258d30a6b916125787e9ceabfc07a26c8f463a9
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Mar 16 20:01:41 2015 +0100

    Refactor some tests and add more tests for DB projects

 Tests/Core/Store/TestProject.cs |   44 ++++++++--------
 Tests/DB/TestStorage.cs         |  107 ++++++++++++++++++++++++++-------------
 2 files changed, 94 insertions(+), 57 deletions(-)
---
diff --git a/Tests/Core/Store/TestProject.cs b/Tests/Core/Store/TestProject.cs
index 4b84901..197e23b 100644
--- a/Tests/Core/Store/TestProject.cs
+++ b/Tests/Core/Store/TestProject.cs
@@ -85,37 +85,37 @@ namespace Tests.Core.Store
                }
 
                [Test ()]
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestGetScores ()
                {
                }
 
                [Test ()]
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestGetPenaltyCards ()
                {
                }
 
                [Test ()]
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestGetScoreEvents ()
                {
                }
 
                [Test ()]
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestGetPenaltyCardEvents ()
                {
                }
 
                [Test ()]
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestGetSubstitutionEventType ()
                {
                }
 
                [Test ()]
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestGetLineup ()
                {
                }
@@ -127,30 +127,30 @@ namespace Tests.Core.Store
                        var g = p.EventsGroupedByEventType;
                        Assert.AreEqual (g.Count (), 4);
                        var gr = g.ElementAt (0);
-                       Assert.AreEqual (p.EventTypes[0], gr.Key);
+                       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 (p.EventTypes [1], gr.Key);
                        Assert.AreEqual (1, gr.Count ());
                        
                        gr = g.ElementAt (2);
-                       Assert.AreEqual (p.EventTypes[2], gr.Key);
+                       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 (p.EventTypes [6], gr.Key);
                        Assert.AreEqual (1, gr.Count ());
                }
 
                [Test ()]
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void Clear ()
                {
                }
 
                [Test ()]
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void UpdateScore ()
                {
                }
@@ -194,25 +194,25 @@ namespace Tests.Core.Store
                }
 
                [Test ()] 
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestCleanupTimers ()
                {
                }
 
                [Test ()] 
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestUpdateEventTypesAndTimers ()
                {
                }
 
                [Test ()] 
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestSubstituePlayer ()
                {
                }
 
                [Test ()] 
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestCurrentLineup ()
                {
                }
@@ -229,25 +229,25 @@ namespace Tests.Core.Store
                }
 
                [Test ()] 
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestGetScore ()
                {
                }
 
                [Test ()] 
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestEventTaggedTeam ()
                {
                }
 
                [Test ()] 
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestConsolidateDescription ()
                {
                }
 
                [Test ()] 
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestEquals ()
                {
                        Project p1 = CreateProject ();
@@ -259,13 +259,13 @@ namespace Tests.Core.Store
                }
 
                [Test ()] 
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestExport ()
                {
                }
 
                [Test ()] 
-               [Ignore("Not implemented")]
+               [Ignore ("Not implemented")]
                public void TestImport ()
                {
                }
diff --git a/Tests/DB/TestStorage.cs b/Tests/DB/TestStorage.cs
index f525567..d3dfa90 100644
--- a/Tests/DB/TestStorage.cs
+++ b/Tests/DB/TestStorage.cs
@@ -57,6 +57,9 @@ namespace Tests.DB
                public void InitDB ()
                {
                        string dbPath = Path.Combine (Path.GetTempPath (), "TestDB");
+                       if (Directory.Exists (dbPath)) {
+                               Directory.Delete (dbPath, true);
+                       }
                        storage = new CouchbaseStorage (dbPath, "test-db");
                        db = storage.Database;
                }
@@ -187,21 +190,14 @@ namespace Tests.DB
                }
 
                [Test ()]
-               public void TestSaveDashboard ()
+               public void TestSaveLoadDashboard ()
                {
                        Dashboard dashboard = Dashboard.DefaultTemplate (10);
+                       dashboard.Image = dashboard.FieldBackground = dashboard.HalfFieldBackground =
+                               dashboard.GoalBackground = Utils.LoadImageFromFile ();
                        storage.Store (dashboard);
                        Assert.AreEqual (1, db.DocumentCount);
                        Assert.IsNotNull (db.GetExistingDocument (dashboard.ID.ToString ()));
-               }
-
-               [Test ()]
-               public void TestLoadDashboard ()
-               {
-                       Dashboard dashboard = Dashboard.DefaultTemplate (10);
-                       dashboard.Image = dashboard.GoalBackground =
-                               dashboard.HalfFieldBackground = dashboard.FieldBackground = 
Utils.LoadImageFromFile ();
-                       storage.Store (dashboard);
                        Dashboard dashboard2 = storage.Retrieve<Dashboard> (dashboard.ID);
                        Assert.IsNotNull (dashboard2);
                        Assert.AreEqual (dashboard.ID, dashboard2.ID);
@@ -215,20 +211,7 @@ namespace Tests.DB
                }
 
                [Test ()]
-               public void TestSavePlayer ()
-               {
-                       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, Mail = "test test", Color = Color.Red
-                       };
-                       storage.Store (player);
-                       Assert.AreEqual (1, db.DocumentCount);
-                       Assert.IsNotNull (db.GetExistingDocument (player.ID.ToString ()));
-               }
-
-               [Test ()]
-               public void TestLoadPlayer ()
+               public void TestSaveLoadPlayer ()
                {
                        Player player1 = new Player {Name = "andoni", Position = "runner",
                                Number = 5, Birthday = new DateTime (1984, 6, 11),
@@ -237,6 +220,8 @@ namespace Tests.DB
                        };
                        player1.Photo = Utils.LoadImageFromFile ();
                        storage.Store (player1);
+                       Assert.AreEqual (1, db.DocumentCount);
+                       Assert.IsNotNull (db.GetExistingDocument (player1.ID.ToString ()));
                        Player player2 = storage.Retrieve<Player> (player1.ID);
                        Assert.AreEqual (player1.ID, player2.ID);
                        Assert.AreEqual (player1.ToString (), player2.ToString ());
@@ -244,25 +229,77 @@ namespace Tests.DB
                }
 
                [Test ()]
-               public void TestSaveTeam ()
+               public void TestSaveLoadTeam ()
                {
-                       Team team = Team.DefaultTemplate (10);
-                       storage.Store<Team> (team);
+                       Team team1 = Team.DefaultTemplate (10);
+                       storage.Store<Team> (team1);
                        Assert.AreEqual (11, db.DocumentCount);
+                       Team team2 = storage.Retrieve<Team> (team1.ID);
+                       Assert.AreEqual (team1.ID, team2.ID);
+                       Assert.AreEqual (team1.List.Count, team2.List.Count);
+               }
+
+               [Test ()]
+               public void TestSaveLoadProjectDescription ()
+               {
+                       MediaFile mf = new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
+                                              "aac", 320, 240, 1.3, null, "Test asset");
+                       ProjectDescription pd1 = new ProjectDescription ();
+                       pd1.FileSet = new MediaFileSet ();
+                       pd1.FileSet.Add (mf);
+                       storage.Store (pd1);
+                       Assert.AreEqual (1, db.DocumentCount);
+
+                       ProjectDescription pd2 = storage.Retrieve<ProjectDescription> (pd1.ID);
+                       Assert.AreEqual (pd1.ID, pd2.ID);
                }
 
                [Test ()]
-               public void TestLoadTeam ()
+               public void TestSaveLoadProject ()
                {
-                       Team team = Team.DefaultTemplate (10);
-                       storage.Store<Team> (team);
-                       Team team2 = storage.Retrieve<Team> (team.ID);
-                       Assert.AreEqual (team.ID, team2.ID);
-                       Assert.AreEqual (team.List.Count, team2.List.Count);
+                       Project p = new Project ();
+                       p.Dashboard = Dashboard.DefaultTemplate (10);
+                       p.UpdateEventTypesAndTimers ();
+                       p.LocalTeamTemplate = Team.DefaultTemplate (10);
+                       p.VisitorTeamTemplate = Team.DefaultTemplate (12);
+                       MediaFile mf = new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
+                                              "aac", 320, 240, 1.3, null, "Test asset");
+                       ProjectDescription pd = new ProjectDescription ();
+                       pd.FileSet = new MediaFileSet ();
+                       pd.FileSet.Add (mf);
+                       p.Description = pd;
 
-                       for (int i = 0; i < team.List.Count; i++) {
-                               Assert.AreEqual (team.List [i].ID, team2.List [i].ID);
+                       storage.Store<Project> (p);
+                       /* 1 Project + 1 ProjectDescription 
+                        * Teams and Dashboard are serialized locally in the project
+                        */ 
+                       Assert.AreEqual (1 + 1, db.DocumentCount);
+               }
+
+
+               [Test ()]
+               public void TestSaveProjectWithEvents ()
+               {
+                       Project p = new Project ();
+                       p.Dashboard = Dashboard.DefaultTemplate (10);
+                       p.UpdateEventTypesAndTimers ();
+                       p.LocalTeamTemplate = Team.DefaultTemplate (10);
+                       p.VisitorTeamTemplate = Team.DefaultTemplate (12);
+                       MediaFile mf = new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
+                                              "aac", 320, 240, 1.3, null, "Test asset");
+                       ProjectDescription pd = new ProjectDescription ();
+                       pd.FileSet = new MediaFileSet ();
+                       pd.FileSet.Add (mf);
+                       p.Description = pd;
+
+                       for (int i = 0; i < 10; i++) {
+                               p.AddEvent (p.EventTypes [i], new Time (1000), new Time (2000), null, null, 
null, null);
                        }
+
+                       storage.Store<Project> (p);
+                       Assert.AreEqual (1 + 1 + 10, db.DocumentCount);
+                       storage.Store<Project> (p);
+                       Assert.AreEqual (1 + 1 + 10, db.DocumentCount);
                }
        }
 }


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