[longomatch] Fix bugs founds with unit tests



commit b9be62e02ddc53a1a91b000a395918ead1d0d06f
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Jan 30 22:07:09 2014 +0100

    Fix bugs founds with unit tests

 LongoMatch.Core/Common/Coordinates.cs           |   16 +++++++++++++++-
 LongoMatch.Core/Store/Category.cs               |   14 +++++++-------
 LongoMatch.Core/Store/Project.cs                |    4 +++-
 LongoMatch.Core/Store/Templates/TeamTemplate.cs |    5 ++++-
 LongoMatch.Services/Services/FileDB.cs          |    7 +++----
 5 files changed, 32 insertions(+), 14 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Coordinates.cs b/LongoMatch.Core/Common/Coordinates.cs
index c644d6a..6d2d1fb 100644
--- a/LongoMatch.Core/Common/Coordinates.cs
+++ b/LongoMatch.Core/Common/Coordinates.cs
@@ -37,7 +37,7 @@ namespace LongoMatch.Common
                                return false;
                        
                        for (int i=0; i<Count; i++) {
-                               if (c[i].X != this[i].X || c[i].Y != this[i].X)
+                               if (c[i] != this[i])
                                        return false;
                        }
                        return true;
@@ -76,6 +76,20 @@ namespace LongoMatch.Common
                {
                        return string.Format ("[Point: X={0}, Y={1}]", X, Y);
                }
+               
+               public override bool Equals (object obj)
+               {
+                       Point p = obj as Point;
+                       if (p == null)
+                               return false;
+                               
+                       return p.X == X && p.Y == Y;
+               }
+               
+               public override int GetHashCode ()
+               {
+                       return (X.ToString() + "-" + Y.ToString()).GetHashCode();
+               }
        }
 }
 
diff --git a/LongoMatch.Core/Store/Category.cs b/LongoMatch.Core/Store/Category.cs
index f42aec9..b3248e0 100644
--- a/LongoMatch.Core/Store/Category.cs
+++ b/LongoMatch.Core/Store/Category.cs
@@ -159,39 +159,39 @@ namespace LongoMatch.Store
                // this constructor is automatically called during deserialization
                public Category(SerializationInfo info, StreamingContext context) {
                        _UUID = (Guid)info.GetValue("uuid", typeof(Guid));
-                       Name = info.GetString("name");
+                       Name = (string) info.GetValue("name", typeof(string));
                        Start = (Time)info.GetValue("start", typeof(Time));
                        Stop = (Time)info.GetValue("stop", typeof(Time));
                        HotKey = (HotKey)info.GetValue("hotkey", typeof(HotKey));
                        SubCategories = (List<ISubCategory>)info.GetValue("subcategories", 
typeof(List<ISubCategory>));
-                       Position = info.GetInt32("position");
+                       Position = (Int32) info.GetValue("position", typeof (Int32));
                        SortMethod = (SortMethodType)info.GetValue("sort_method", typeof(SortMethodType));
                        Color = Color.FromArgb(
                                ColorHelper.ShortToByte((ushort)info.GetValue("red", typeof(ushort))),
                                ColorHelper.ShortToByte((ushort)info.GetValue("green", typeof(ushort))),
                                ColorHelper.ShortToByte((ushort)info.GetValue("blue", typeof(ushort))));
                        try {
-                               TagFieldPosition = info.GetBoolean("tagfieldpos");
+                               TagFieldPosition = (bool) info.GetValue("tagfieldpos", typeof (bool));
                        } catch {
                                TagFieldPosition = true;
                        }
                        try {
-                               TagHalfFieldPosition = info.GetBoolean("taghalffieldpos");
+                               TagHalfFieldPosition =(bool) info.GetValue("taghalffieldpos", typeof (bool));
                        } catch {
                                TagHalfFieldPosition = false;
                        }
                        try {
-                               TagGoalPosition = info.GetBoolean("taggoalpos");
+                               TagGoalPosition = (bool) info.GetValue("taggoalpos", typeof (bool));
                        } catch {
                                TagGoalPosition = false;
                        }
                        try {
-                               FieldPositionIsDistance = info.GetBoolean("fieldposisdist");
+                               FieldPositionIsDistance =(bool) info.GetValue("fieldposisdist", typeof 
(bool));
                        } catch {
                                FieldPositionIsDistance = false;
                        }
                        try {
-                               HalfFieldPositionIsDistance = info.GetBoolean("halffieldposisdist");
+                               HalfFieldPositionIsDistance =(bool) info.GetValue("halffieldposisdist", 
typeof (bool));
                        } catch {
                                HalfFieldPositionIsDistance = false;
                        }
diff --git a/LongoMatch.Core/Store/Project.cs b/LongoMatch.Core/Store/Project.cs
index 81f84b8..b1f5e25 100644
--- a/LongoMatch.Core/Store/Project.cs
+++ b/LongoMatch.Core/Store/Project.cs
@@ -81,7 +81,9 @@ namespace LongoMatch.Store
                                return description;
                        }
                        set {
-                               value.UUID = UUID;
+                               if (value != null) {
+                                       value.UUID = UUID;
+                               }
                                description = value;
                        }
                }
diff --git a/LongoMatch.Core/Store/Templates/TeamTemplate.cs b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
index 29d2919..ec6980a 100644
--- a/LongoMatch.Core/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
@@ -61,7 +61,10 @@ namespace LongoMatch.Store.Templates
                                        return Image.Deserialize(thumbnailBuf);
                                else return null;
                        } set {
-                               thumbnailBuf = value.Serialize();
+                               if (value == null)
+                                       thumbnailBuf = null;
+                               else
+                                       thumbnailBuf = value.Serialize();
                        }
                }
                
diff --git a/LongoMatch.Services/Services/FileDB.cs b/LongoMatch.Services/Services/FileDB.cs
index ea8618d..817a4be 100644
--- a/LongoMatch.Services/Services/FileDB.cs
+++ b/LongoMatch.Services/Services/FileDB.cs
@@ -43,9 +43,9 @@ namespace LongoMatch.DB
                        if (!Directory.Exists(dbDirPath)) {
                                Directory.CreateDirectory(dbDirPath);
                        }
-                       if (File.Exists(dbDirPath)) {
+                       if (File.Exists(dbPath)) {
                                try {
-                                       projectsDB = SerializableObject.Load<LiteDB> (dbDirPath);
+                                       projectsDB = SerializableObject.Load<LiteDB> (dbPath);
                                }
                                catch  (Exception e){
                                        Log.Exception (e);
@@ -182,8 +182,7 @@ namespace LongoMatch.DB
                                if (File.Exists (projectFile)) {
                                        File.Delete (projectFile);
                                }
-                               projectsDB.Delete (id); 
-                               return true;
+                               return projectsDB.Delete (id);
                        } catch (Exception ex) {
                                Log.Exception (ex);
                                return false;


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