diff --git a/umbraco.Test/RelationTest.cs b/umbraco.Test/RelationTest.cs
new file mode 100644
index 0000000000..ded7497aaf
--- /dev/null
+++ b/umbraco.Test/RelationTest.cs
@@ -0,0 +1,267 @@
+using umbraco.cms.businesslogic.relation;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+using System.Collections.Generic;
+using umbraco.cms.businesslogic;
+
+namespace umbraco.Test
+{
+
+
+ ///
+ ///This is a test class for RelationTest and is intended
+ ///to contain all RelationTest Unit Tests
+ ///
+ [TestClass()]
+ public class RelationTest
+ {
+
+ /////
+ ///// Creates 2 documents and relates them
+ /////
+ //[TestMethod()]
+ //public void Relation_Make_New()
+ //{
+
+
+
+ // actual = Relation.MakeNew(ParentId, ChildId, RelType, Comment);
+ // Assert.AreEqual(expected, actual);
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+ #region Tests to write
+
+ /////
+ /////A test for Relation Constructor
+ /////
+ //[TestMethod()]
+ //public void RelationConstructorTest()
+ //{
+ // int Id = 0; // TODO: Initialize to an appropriate value
+ // Relation target = new Relation(Id);
+ // Assert.Inconclusive("TODO: Implement code to verify target");
+ //}
+
+ /////
+ /////A test for Delete
+ /////
+ //[TestMethod()]
+ //public void DeleteTest()
+ //{
+ // int Id = 0; // TODO: Initialize to an appropriate value
+ // Relation target = new Relation(Id); // TODO: Initialize to an appropriate value
+ // target.Delete();
+ // Assert.Inconclusive("A method that does not return a value cannot be verified.");
+ //}
+
+ /////
+ /////A test for GetRelations
+ /////
+ //[TestMethod()]
+ //public void GetRelationsTest()
+ //{
+ // int NodeId = 0; // TODO: Initialize to an appropriate value
+ // RelationType Filter = null; // TODO: Initialize to an appropriate value
+ // Relation[] expected = null; // TODO: Initialize to an appropriate value
+ // Relation[] actual;
+ // actual = Relation.GetRelations(NodeId, Filter);
+ // Assert.AreEqual(expected, actual);
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+ /////
+ /////A test for GetRelations
+ /////
+ //[TestMethod()]
+ //public void GetRelationsTest1()
+ //{
+ // int NodeId = 0; // TODO: Initialize to an appropriate value
+ // Relation[] expected = null; // TODO: Initialize to an appropriate value
+ // Relation[] actual;
+ // actual = Relation.GetRelations(NodeId);
+ // Assert.AreEqual(expected, actual);
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+ /////
+ /////A test for GetRelationsAsList
+ /////
+ //[TestMethod()]
+ //public void GetRelationsAsListTest()
+ //{
+ // int NodeId = 0; // TODO: Initialize to an appropriate value
+ // List expected = null; // TODO: Initialize to an appropriate value
+ // List actual;
+ // actual = Relation.GetRelationsAsList(NodeId);
+ // Assert.AreEqual(expected, actual);
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+ /////
+ /////A test for IsRelated
+ /////
+ //[TestMethod()]
+ //public void IsRelatedTest()
+ //{
+ // int ParentID = 0; // TODO: Initialize to an appropriate value
+ // int ChildId = 0; // TODO: Initialize to an appropriate value
+ // RelationType Filter = null; // TODO: Initialize to an appropriate value
+ // bool expected = false; // TODO: Initialize to an appropriate value
+ // bool actual;
+ // actual = Relation.IsRelated(ParentID, ChildId, Filter);
+ // Assert.AreEqual(expected, actual);
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+ /////
+ /////A test for IsRelated
+ /////
+ //[TestMethod()]
+ //public void IsRelatedTest1()
+ //{
+ // int ParentID = 0; // TODO: Initialize to an appropriate value
+ // int ChildId = 0; // TODO: Initialize to an appropriate value
+ // bool expected = false; // TODO: Initialize to an appropriate value
+ // bool actual;
+ // actual = Relation.IsRelated(ParentID, ChildId);
+ // Assert.AreEqual(expected, actual);
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+
+
+ /////
+ /////A test for Save
+ /////
+ //[TestMethod()]
+ //public void SaveTest()
+ //{
+ // int Id = 0; // TODO: Initialize to an appropriate value
+ // Relation target = new Relation(Id); // TODO: Initialize to an appropriate value
+ // target.Save();
+ // Assert.Inconclusive("A method that does not return a value cannot be verified.");
+ //}
+
+ /////
+ /////A test for Child
+ /////
+ //[TestMethod()]
+ //public void ChildTest()
+ //{
+ // int Id = 0; // TODO: Initialize to an appropriate value
+ // Relation target = new Relation(Id); // TODO: Initialize to an appropriate value
+ // CMSNode expected = null; // TODO: Initialize to an appropriate value
+ // CMSNode actual;
+ // target.Child = expected;
+ // actual = target.Child;
+ // Assert.AreEqual(expected, actual);
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+ /////
+ /////A test for Comment
+ /////
+ //[TestMethod()]
+ //public void CommentTest()
+ //{
+ // int Id = 0; // TODO: Initialize to an appropriate value
+ // Relation target = new Relation(Id); // TODO: Initialize to an appropriate value
+ // string expected = string.Empty; // TODO: Initialize to an appropriate value
+ // string actual;
+ // target.Comment = expected;
+ // actual = target.Comment;
+ // Assert.AreEqual(expected, actual);
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+ /////
+ /////A test for CreateDate
+ /////
+ //[TestMethod()]
+ //public void CreateDateTest()
+ //{
+ // int Id = 0; // TODO: Initialize to an appropriate value
+ // Relation target = new Relation(Id); // TODO: Initialize to an appropriate value
+ // DateTime actual;
+ // actual = target.CreateDate;
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+ /////
+ /////A test for Id
+ /////
+ //[TestMethod()]
+ //public void IdTest()
+ //{
+ // int Id = 0; // TODO: Initialize to an appropriate value
+ // Relation target = new Relation(Id); // TODO: Initialize to an appropriate value
+ // int actual;
+ // actual = target.Id;
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+ /////
+ /////A test for Parent
+ /////
+ //[TestMethod()]
+ //public void ParentTest()
+ //{
+ // int Id = 0; // TODO: Initialize to an appropriate value
+ // Relation target = new Relation(Id); // TODO: Initialize to an appropriate value
+ // CMSNode expected = null; // TODO: Initialize to an appropriate value
+ // CMSNode actual;
+ // target.Parent = expected;
+ // actual = target.Parent;
+ // Assert.AreEqual(expected, actual);
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+
+ /////
+ /////A test for RelType
+ /////
+ //[TestMethod()]
+ //public void RelTypeTest()
+ //{
+ // int Id = 0; // TODO: Initialize to an appropriate value
+ // Relation target = new Relation(Id); // TODO: Initialize to an appropriate value
+ // RelationType expected = null; // TODO: Initialize to an appropriate value
+ // RelationType actual;
+ // target.RelType = expected;
+ // actual = target.RelType;
+ // Assert.AreEqual(expected, actual);
+ // Assert.Inconclusive("Verify the correctness of this test method.");
+ //}
+ #endregion
+
+ #region Additional test attributes
+ //
+ //You can use the following additional attributes as you write your tests:
+ //
+ //Use ClassInitialize to run code before running the first test in the class
+ //[ClassInitialize()]
+ //public static void MyClassInitialize(TestContext testContext)
+ //{
+ //}
+ //
+ //Use ClassCleanup to run code after all tests in a class have run
+ //[ClassCleanup()]
+ //public static void MyClassCleanup()
+ //{
+ //}
+ //
+ //Use TestInitialize to run code before running each test
+ //[TestInitialize()]
+ //public void MyTestInitialize()
+ //{
+ //}
+ //
+ //Use TestCleanup to run code after each test has run
+ //[TestCleanup()]
+ //public void MyTestCleanup()
+ //{
+ //}
+ //
+ #endregion
+ }
+}
diff --git a/umbraco.Test/TagTest.cs b/umbraco.Test/TagTest.cs
index b5c824390a..f11d43565c 100644
--- a/umbraco.Test/TagTest.cs
+++ b/umbraco.Test/TagTest.cs
@@ -5,6 +5,7 @@ using umbraco.cms.businesslogic.web;
using System.Collections.Generic;
using umbraco.cms.businesslogic;
using System.Linq;
+using umbraco.BusinessLogic;
namespace umbraco.Test
{
@@ -35,6 +36,73 @@ namespace umbraco.Test
}
+ ///
+ /// Creates a new tag and a new document, assigns the tag to the document and deletes the document
+ ///
+ [TestMethod()]
+ public void Tag_Make_New_Assign_Node_Delete_Node()
+ {
+
+ var t = Tag.AddTag(Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"));
+ Assert.IsTrue(t > 0); //id should be greater than zero
+ Assert.AreEqual(1, Tag.GetTags().Where(x => x.Id == t).Count());
+
+ var dt = DocumentType.GetAllAsList().First();
+ var doc = Document.MakeNew(Guid.NewGuid().ToString("N"), dt, m_User, -1);
+
+ Tag.AssociateTagToNode(doc.Id, t);
+ //make sure it's associated
+ Assert.AreEqual(1, Tag.GetTags(doc.Id).Count());
+
+ //delete the doc
+ doc.delete(true);
+
+ //make sure it's not related any more
+ Assert.AreEqual(0, Tag.GetTags(doc.Id).Count());
+
+ Tag.RemoveTag(t);
+ //make sure it's gone
+ Assert.AreEqual(0, Tag.GetTags().Where(x => x.Id == t).Count());
+
+ }
+
+ ///
+ /// Test the AddTagsToNode method and deletes it
+ ///
+ [TestMethod()]
+ public void Tag_Add_Tags_To_Node()
+ {
+ var dt = DocumentType.GetAllAsList().First();
+ var doc = Document.MakeNew(Guid.NewGuid().ToString("N"), dt, m_User, -1);
+
+ var grp = Guid.NewGuid().ToString("N");
+ Tag.AddTagsToNode(doc.Id, string.Format("{0},{1}", Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N")), grp);
+
+ var tags = Tag.GetTags(doc.Id);
+ //make sure they are there by document
+ Assert.AreEqual(2, tags.Count());
+
+ //make sure they are there by group
+ Assert.AreEqual(2, Tag.GetTags(grp).Count());
+
+ //make sure they are there by both group and node
+ Assert.AreEqual(2, Tag.GetTags(doc.Id, grp).Count());
+
+ doc.delete(true);
+
+ //make sure associations are gone
+ Assert.AreEqual(0, Tag.GetTags(doc.Id).Count());
+
+ //delete the tags
+ foreach (var t in tags)
+ {
+ Tag.RemoveTag(t.Id);
+ Assert.AreEqual(0, Tag.GetTags().Where(x => x.Id == t.Id).Count());
+ }
+ }
+
+ private User m_User = new User(0);
+
#region Tests to write
/////
diff --git a/umbraco.Test/umbraco.Test.csproj b/umbraco.Test/umbraco.Test.csproj
index 96074ed23e..410bfa6c85 100644
--- a/umbraco.Test/umbraco.Test.csproj
+++ b/umbraco.Test/umbraco.Test.csproj
@@ -154,6 +154,7 @@
+
diff --git a/umbraco.sln b/umbraco.sln
index 01a8675932..47317006c8 100644
--- a/umbraco.sln
+++ b/umbraco.sln
@@ -9,7 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
SHOCKING.testrunconfig = SHOCKING.testrunconfig
umbraco weekly.build = umbraco weekly.build
umbraco.build = umbraco.build
- umbraco.vsmdi = umbraco.vsmdi
UMBRACOELISE.testrunconfig = UMBRACOELISE.testrunconfig
UMBRACOHUMMER.testrunconfig = UMBRACOHUMMER.testrunconfig
EndProjectSection
diff --git a/umbraco/cms/businesslogic/CMSNode.cs b/umbraco/cms/businesslogic/CMSNode.cs
index c21eca9afe..34b20435c4 100644
--- a/umbraco/cms/businesslogic/CMSNode.cs
+++ b/umbraco/cms/businesslogic/CMSNode.cs
@@ -15,6 +15,7 @@ using umbraco.cms.businesslogic.media;
using System.Collections;
using umbraco.cms.businesslogic.task;
using umbraco.cms.businesslogic.workflow;
+using umbraco.cms.businesslogic.Tags;
namespace umbraco.cms.businesslogic
{
@@ -554,6 +555,9 @@ order by level,sortOrder";
//remove permissions
Permission.DeletePermissions(this);
+ //removes tag associations (i know the key is set to cascade but do it anyways)
+ Tag.RemoveTagsFromNode(this.Id);
+
SqlHelper.ExecuteNonQuery("DELETE FROM umbracoNode WHERE uniqueID= @uniqueId", SqlHelper.CreateParameter("@uniqueId", _uniqueID));
FireAfterDelete(e);
}
diff --git a/umbraco/cms/businesslogic/Tags/Tag.cs b/umbraco/cms/businesslogic/Tags/Tag.cs
index 6fdcc5e3a4..910e2839be 100644
--- a/umbraco/cms/businesslogic/Tags/Tag.cs
+++ b/umbraco/cms/businesslogic/Tags/Tag.cs
@@ -153,9 +153,10 @@ namespace umbraco.cms.businesslogic.Tags
public static IEnumerable GetTags(int nodeId, string group)
{
- var sql = @"SELECT * FROM cmsTags
+ var sql = @"SELECT cmsTags.id, cmsTags.tag, cmsTags.[group], count(cmsTagRelationShip.tagid) AS nodeCount FROM cmsTags
INNER JOIN cmsTagRelationship ON cmsTagRelationShip.tagId = cmsTags.id
- WHERE cmsTags.[group] = @group AND cmsTagRelationship.nodeid = @nodeid";
+ WHERE cmsTags.[group] = @group AND cmsTagRelationship.nodeid = @nodeid
+ GROUP BY cmsTags.id, cmsTags.tag, cmsTags.[group]";
return ConvertSqlToTags(sql,
SqlHelper.CreateParameter("@group", group),
@@ -190,7 +191,6 @@ namespace umbraco.cms.businesslogic.Tags
string sql = @"SELECT cmsTags.id, cmsTags.tag, cmsTags.[group], count(cmsTagRelationShip.tagid) AS nodeCount FROM cmsTags
INNER JOIN cmsTagRelationShip ON cmsTagRelationShip.tagid = cmsTags.id
- INNER JOIN cmsContentXml ON cmsContentXml.nodeid = cmsTagRelationShip.nodeId
WHERE cmsTags.[group] = @group
GROUP BY cmsTags.id, cmsTags.tag, cmsTags.[group]";
@@ -207,11 +207,10 @@ namespace umbraco.cms.businesslogic.Tags
{
string sql = @"SELECT cmsTags.id, cmsTags.tag, cmsTags.[group], count(cmsTagRelationShip.tagid) AS nodeCount FROM cmsTags
- INNER JOIN cmsTagRelationShip ON cmsTagRelationShip.tagid = cmsTags.id
- Inner JOIN cmsContentXml ON cmsContentXml.nodeid = cmsTagRelationShip.nodeId
+ LEFT JOIN cmsTagRelationShip ON cmsTagRelationShip.tagid = cmsTags.id
GROUP BY cmsTags.id, cmsTags.tag, cmsTags.[group]";
- return ConvertSqlToTags(sql, SqlHelper.CreateParameter("@nodeId", "0"));
+ return ConvertSqlToTags(sql);
}
diff --git a/umbraco/cms/businesslogic/relation/Relation.cs b/umbraco/cms/businesslogic/relation/Relation.cs
index fa51a742da..66d95cab93 100644
--- a/umbraco/cms/businesslogic/relation/Relation.cs
+++ b/umbraco/cms/businesslogic/relation/Relation.cs
@@ -79,15 +79,19 @@ namespace umbraco.cms.businesslogic.relation
{
using (IRecordsReader dr = SqlHelper.ExecuteReader("select * from umbracoRelation where id = @id", SqlHelper.CreateParameter("@id", Id)))
{
- if(dr.Read())
- {
- this._id = dr.GetInt("id");
- this._parentNode = new CMSNode(dr.GetInt("parentId"));
- this._childNode = new CMSNode(dr.GetInt("childId"));
- this._relType = RelationType.GetById(dr.GetInt("relType"));
- this._comment = dr.GetString("comment");
- this._datetime = dr.GetDateTime("datetime");
- }
+ if (dr.Read())
+ {
+ this._id = dr.GetInt("id");
+ this._parentNode = new CMSNode(dr.GetInt("parentId"));
+ this._childNode = new CMSNode(dr.GetInt("childId"));
+ this._relType = RelationType.GetById(dr.GetInt("relType"));
+ this._comment = dr.GetString("comment");
+ this._datetime = dr.GetDateTime("datetime");
+ }
+ else
+ {
+ throw new ArgumentException("No relation found for id " + Id.ToString());
+ }
}
}
@@ -133,7 +137,7 @@ namespace umbraco.cms.businesslogic.relation
return _rels;
}
-public static bool IsRelated(int ParentID, int ChildId) {
+ public static bool IsRelated(int ParentID, int ChildId) {
int count = SqlHelper.ExecuteScalar("SELECT count(*) FROM umbracoRelation WHERE childId = @childId AND parentId = @parentId",
SqlHelper.CreateParameter("@childId", ChildId),
SqlHelper.CreateParameter("@parentId", ParentID));