267
umbraco.Test/RelationTest.cs
Normal file
267
umbraco.Test/RelationTest.cs
Normal file
@@ -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
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for RelationTest and is intended
|
||||
///to contain all RelationTest Unit Tests
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class RelationTest
|
||||
{
|
||||
|
||||
///// <summary>
|
||||
///// Creates 2 documents and relates them
|
||||
/////</summary>
|
||||
//[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
|
||||
|
||||
///// <summary>
|
||||
/////A test for Relation Constructor
|
||||
/////</summary>
|
||||
//[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");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for Delete
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for GetRelations
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for GetRelations
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for GetRelationsAsList
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void GetRelationsAsListTest()
|
||||
//{
|
||||
// int NodeId = 0; // TODO: Initialize to an appropriate value
|
||||
// List<Relation> expected = null; // TODO: Initialize to an appropriate value
|
||||
// List<Relation> actual;
|
||||
// actual = Relation.GetRelationsAsList(NodeId);
|
||||
// Assert.AreEqual(expected, actual);
|
||||
// Assert.Inconclusive("Verify the correctness of this test method.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for IsRelated
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for IsRelated
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
|
||||
|
||||
///// <summary>
|
||||
/////A test for Save
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for Child
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for Comment
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for CreateDate
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for Id
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for Parent
|
||||
/////</summary>
|
||||
//[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.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for RelType
|
||||
/////</summary>
|
||||
//[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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new tag and a new document, assigns the tag to the document and deletes the document
|
||||
/// </summary>
|
||||
[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<int>(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<int>(1, Tag.GetTags(doc.Id).Count());
|
||||
|
||||
//delete the doc
|
||||
doc.delete(true);
|
||||
|
||||
//make sure it's not related any more
|
||||
Assert.AreEqual<int>(0, Tag.GetTags(doc.Id).Count());
|
||||
|
||||
Tag.RemoveTag(t);
|
||||
//make sure it's gone
|
||||
Assert.AreEqual<int>(0, Tag.GetTags().Where(x => x.Id == t).Count());
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test the AddTagsToNode method and deletes it
|
||||
/// </summary>
|
||||
[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<int>(2, tags.Count());
|
||||
|
||||
//make sure they are there by group
|
||||
Assert.AreEqual<int>(2, Tag.GetTags(grp).Count());
|
||||
|
||||
//make sure they are there by both group and node
|
||||
Assert.AreEqual<int>(2, Tag.GetTags(doc.Id, grp).Count());
|
||||
|
||||
doc.delete(true);
|
||||
|
||||
//make sure associations are gone
|
||||
Assert.AreEqual<int>(0, Tag.GetTags(doc.Id).Count());
|
||||
|
||||
//delete the tags
|
||||
foreach (var t in tags)
|
||||
{
|
||||
Tag.RemoveTag(t.Id);
|
||||
Assert.AreEqual<int>(0, Tag.GetTags().Where(x => x.Id == t.Id).Count());
|
||||
}
|
||||
}
|
||||
|
||||
private User m_User = new User(0);
|
||||
|
||||
#region Tests to write
|
||||
|
||||
///// <summary>
|
||||
|
||||
@@ -154,6 +154,7 @@
|
||||
<Compile Include="PermissionTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="PropertyTypeTest.cs" />
|
||||
<Compile Include="RelationTest.cs" />
|
||||
<Compile Include="StyleSheetTest.cs" />
|
||||
<Compile Include="TagTest.cs" />
|
||||
<Compile Include="TaskTest.cs" />
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -153,9 +153,10 @@ namespace umbraco.cms.businesslogic.Tags
|
||||
|
||||
public static IEnumerable<Tag> 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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<int>("SELECT count(*) FROM umbracoRelation WHERE childId = @childId AND parentId = @parentId",
|
||||
SqlHelper.CreateParameter("@childId", ChildId),
|
||||
SqlHelper.CreateParameter("@parentId", ParentID));
|
||||
|
||||
Reference in New Issue
Block a user