using umbraco.cms.businesslogic.relation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using umbraco.cms.businesslogic.web;
using System.Linq;
using umbraco.BusinessLogic;
namespace Umbraco.LegacyTests
{
///
///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, then deletes the relation
///
[TestMethod()]
public void Relation_Make_New()
{
var dt = DocumentType.GetAllAsList().First();
var parent = Document.MakeNew(Guid.NewGuid().ToString("N"), dt, m_User, -1);
var child = Document.MakeNew(Guid.NewGuid().ToString("N"), dt, m_User, -1);
var rt = RelationType.GetAll().First();
//make the relation
var r = Relation.MakeNew(parent.Id, child.Id, rt, Guid.NewGuid().ToString("N"));
Assert.IsTrue(r.Id > 0);
Assert.IsInstanceOfType(r, typeof(Relation));
//delete the relation
r.Delete();
//make sure it's gone by looking up both parent & children
Assert.AreEqual(0, Relation.GetRelations(parent.Id).Count());
Assert.AreEqual(0, Relation.GetRelations(child.Id).Count());
//now remove the documents
child.delete(true);
parent.delete(true);
}
///
/// Creates 2 documents, relates them, then deletes the parent doc and ensure that the relation is gone
///
[TestMethod()]
public void Relation_Relate_Docs_And_Delete_Parent()
{
var dt = DocumentType.GetAllAsList().First();
var parent = Document.MakeNew(Guid.NewGuid().ToString("N"), dt, m_User, -1);
var child = Document.MakeNew(Guid.NewGuid().ToString("N"), dt, m_User, -1);
var rt = RelationType.GetAll().First();
//make the relation
var r = Relation.MakeNew(parent.Id, child.Id, rt, Guid.NewGuid().ToString("N"));
Assert.IsTrue(r.Id > 0);
Assert.IsInstanceOfType(r, typeof(Relation));
//deletes the parent
parent.delete(true);
//make sure it's gone by looking up both parent & children
Assert.AreEqual(0, Relation.GetRelations(parent.Id).Count());
Assert.AreEqual(0, Relation.GetRelations(child.Id).Count());
//now remove the documents
child.delete(true);
}
private User m_User = new User(0);
#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
}
}