More unit tests.
Fixes: 26281, 26308, 27166, 27168, 27169, 27171 [TFS Changeset #66294]
This commit is contained in:
@@ -753,7 +753,7 @@ namespace umbraco.Test
|
||||
/// <summary>
|
||||
/// The user to be used to create stuff
|
||||
/// </summary>
|
||||
private User m_User = new User(0);
|
||||
private static User m_User = new User(0);
|
||||
|
||||
/// <summary>
|
||||
/// Used for each test initialization. Before each test is run a new root doc is created.
|
||||
@@ -769,7 +769,7 @@ namespace umbraco.Test
|
||||
/// Completely remove the document, this will first recycle it and then delete it (the api doesn't directly support deleting completey in one step)
|
||||
/// </summary>
|
||||
/// <param name="d"></param>
|
||||
private void RecycleAndDelete(Document d)
|
||||
internal static void RecycleAndDelete(Document d)
|
||||
{
|
||||
if (d == null)
|
||||
{
|
||||
@@ -804,7 +804,7 @@ namespace umbraco.Test
|
||||
/// Returns a random docuemnt type that supports a text property
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private int GetExistingDocTypeId()
|
||||
internal static int GetExistingDocTypeId()
|
||||
{
|
||||
var types = DocumentType.GetAllAsList();
|
||||
DocumentType found = null;
|
||||
@@ -831,7 +831,7 @@ namespace umbraco.Test
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
private Property GetTextFieldProperty(DocumentType dt, Document d)
|
||||
internal static Property GetTextFieldProperty(DocumentType dt, Document d)
|
||||
{
|
||||
TextFieldDataType txtField = new TextFieldDataType();
|
||||
var prop = dt.PropertyTypes
|
||||
@@ -843,7 +843,7 @@ namespace umbraco.Test
|
||||
/// Returns a content node
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private int GetExistingNodeId()
|
||||
internal static int GetExistingNodeId()
|
||||
{
|
||||
var ids = Document.getAllUniqueNodeIdsFromObjectType(Document._objectType).ToList();
|
||||
var r = new Random();
|
||||
@@ -858,7 +858,7 @@ namespace umbraco.Test
|
||||
/// </summary>
|
||||
/// <param name="d"></param>
|
||||
/// <returns></returns>
|
||||
private IEnumerable<IconI> GetChildNodesOfParent(Document d)
|
||||
internal static IEnumerable<IconI> GetChildNodesOfParent(Document d)
|
||||
{
|
||||
if (d.ParentId == (int)RecycleBin.RecycleBinType.Content)
|
||||
{
|
||||
@@ -877,7 +877,7 @@ namespace umbraco.Test
|
||||
}
|
||||
}
|
||||
|
||||
private DocumentType GetExistingDocType()
|
||||
internal static DocumentType GetExistingDocType()
|
||||
{
|
||||
DocumentType dct = new DocumentType(GetExistingDocTypeId());
|
||||
Assert.IsTrue(dct.Id > 0);
|
||||
@@ -888,7 +888,7 @@ namespace umbraco.Test
|
||||
/// Creates a new node based on an existing doc type
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private Document CreateNewUnderRoot(DocumentType dt)
|
||||
internal static Document CreateNewUnderRoot(DocumentType dt)
|
||||
{
|
||||
string Name = "TEST-" + Guid.NewGuid().ToString("N");
|
||||
int ParentId = -1;
|
||||
|
||||
318
umbraco.Test/LanguageTest.cs
Normal file
318
umbraco.Test/LanguageTest.cs
Normal file
@@ -0,0 +1,318 @@
|
||||
using umbraco.cms.businesslogic.language;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Xml;
|
||||
using System.Collections.Generic;
|
||||
using umbraco.BusinessLogic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Data.SqlClient;
|
||||
using umbraco.DataLayer;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using System.Data;
|
||||
|
||||
namespace umbraco.Test
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for LanguageTest and is intended
|
||||
///to contain all LanguageTest Unit Tests
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class LanguageTest
|
||||
{
|
||||
/// <summary>
|
||||
///A test for getAll
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void Language_GetAllTest()
|
||||
{
|
||||
//check with sql that it's the correct number of children
|
||||
var ids = new List<int>();
|
||||
using (var reader = Application.SqlHelper.ExecuteReader(Language.m_SQLOptimizedGetAll))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
ids.Add(Convert.ToInt32(reader.GetShort("id")));
|
||||
}
|
||||
}
|
||||
|
||||
var all = Language.GetAllAsList();
|
||||
|
||||
Assert.AreEqual<int>(ids.Distinct().Count(), all.Count());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///A test for ToXml
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void Language_ToXmlTest()
|
||||
{
|
||||
var all = Language.GetAllAsList();
|
||||
|
||||
XmlDocument xd = new XmlDocument();
|
||||
var x = all.First().ToXml(xd);
|
||||
|
||||
Assert.IsNotNull(x.Attributes["Id"].Value);
|
||||
Assert.IsNotNull(x.Attributes["CultureAlias"].Value);
|
||||
Assert.IsNotNull(x.Attributes["FriendlyName"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///A test for GetByCultureCode
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void Language_GetByCultureCodeTest()
|
||||
{
|
||||
var all = Language.GetAllAsList();
|
||||
var lang = Language.GetByCultureCode(all.First().CultureAlias);
|
||||
Assert.AreEqual(all.First().CultureAlias, lang.CultureAlias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///A test for MakeNew
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void Language_MakeNewTest()
|
||||
{
|
||||
var newLang = MakeNew();
|
||||
DeleteLanguage(newLang);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// try to make a duplicate, this should fail with an sql exception
|
||||
/// </summary>
|
||||
[TestMethod()]
|
||||
[ExpectedException(typeof(SqlHelperException))]
|
||||
public void Language_MakeDuplicateTest()
|
||||
{
|
||||
var all = Language.GetAllAsList();
|
||||
Language.MakeNew(all.First().CultureAlias);
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void Language_DeleteWithAssignedDomainTest()
|
||||
{
|
||||
var newLang = MakeNew();
|
||||
|
||||
var newDoc = DocumentTest.CreateNewUnderRoot(DocumentTest.GetExistingDocType());
|
||||
|
||||
Domain.MakeNew("www.test" + Guid.NewGuid().ToString("N") + ".com", newDoc.Id, newLang.id);
|
||||
|
||||
//this shouldn't delete it
|
||||
bool hasErr = false;
|
||||
try
|
||||
{
|
||||
newLang.Delete();
|
||||
}
|
||||
catch (DataException)
|
||||
{
|
||||
hasErr = true;
|
||||
}
|
||||
Assert.IsTrue(hasErr);
|
||||
|
||||
//we will need to delete the domain first, then the language
|
||||
var d = Domain.GetDomainsById(newDoc.Id).First();
|
||||
d.Delete();
|
||||
|
||||
DeleteLanguage(newLang);
|
||||
}
|
||||
|
||||
#region Tests to write
|
||||
///// <summary>
|
||||
/////A test for id
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void idTest()
|
||||
//{
|
||||
// int id = 0; // TODO: Initialize to an appropriate value
|
||||
// Language target = new Language(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 FriendlyName
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void FriendlyNameTest()
|
||||
//{
|
||||
// int id = 0; // TODO: Initialize to an appropriate value
|
||||
// Language target = new Language(id); // TODO: Initialize to an appropriate value
|
||||
// string actual;
|
||||
// actual = target.FriendlyName;
|
||||
// Assert.Inconclusive("Verify the correctness of this test method.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for CultureAlias
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void CultureAliasTest()
|
||||
//{
|
||||
// int id = 0; // TODO: Initialize to an appropriate value
|
||||
// Language target = new Language(id); // TODO: Initialize to an appropriate value
|
||||
// string expected = string.Empty; // TODO: Initialize to an appropriate value
|
||||
// string actual;
|
||||
// target.CultureAlias = expected;
|
||||
// actual = target.CultureAlias;
|
||||
// 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
|
||||
// Language target = new Language(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 Import
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void ImportTest()
|
||||
//{
|
||||
// XmlNode xmlData = null; // TODO: Initialize to an appropriate value
|
||||
// Language expected = null; // TODO: Initialize to an appropriate value
|
||||
// Language actual;
|
||||
// actual = Language.Import(xmlData);
|
||||
// Assert.AreEqual(expected, actual);
|
||||
// Assert.Inconclusive("Verify the correctness of this test method.");
|
||||
//}
|
||||
|
||||
|
||||
|
||||
///// <summary>
|
||||
/////A test for Delete
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void DeleteTest()
|
||||
//{
|
||||
// int id = 0; // TODO: Initialize to an appropriate value
|
||||
// Language target = new Language(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 Language Constructor
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void LanguageConstructorTest()
|
||||
//{
|
||||
// int id = 0; // TODO: Initialize to an appropriate value
|
||||
// Language target = new Language(id);
|
||||
// Assert.Inconclusive("TODO: Implement code to verify target");
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
/// <summary>
|
||||
/// a helper class to create a new language and validate everything. This does NOT delete it when the test is done.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private Language MakeNew()
|
||||
{
|
||||
var all = Language.GetAllAsList();
|
||||
|
||||
//get all cultures not installed
|
||||
var nonInstalled = CultureInfo.GetCultures(CultureTypes.AllCultures)
|
||||
.Select(x => x.Name)
|
||||
.Except(all.Select(x => x.CultureAlias))
|
||||
.ToList();
|
||||
|
||||
Language.MakeNew(nonInstalled.First());
|
||||
|
||||
//now get all installed again to make sure it's there
|
||||
var newAll = Language.GetAllAsList();
|
||||
|
||||
//the new counts should be different
|
||||
Assert.AreNotEqual<int>(all.Count(), newAll.Count());
|
||||
//the differnce should be 1
|
||||
Assert.AreEqual<int>(1, newAll.Except(all).Count());
|
||||
|
||||
//now we need to delete
|
||||
var newLang = newAll.Except(all).Single();
|
||||
return newLang;
|
||||
}
|
||||
|
||||
private void DeleteLanguage(Language lang)
|
||||
{
|
||||
var id = lang.id;
|
||||
|
||||
lang.Delete();
|
||||
|
||||
//check with sql that it is gone
|
||||
var count = Application.SqlHelper.ExecuteScalar<int>("SELECT COUNT(*) FROM umbracoLanguage WHERE id=@id",
|
||||
Application.SqlHelper.CreateParameter("@id", id));
|
||||
|
||||
Assert.AreEqual(0, count);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Test context
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Intitialize and cleanup
|
||||
//
|
||||
//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
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,16 @@ using umbraco.editorControls.textfield;
|
||||
using umbraco.editorControls.label;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
using umbraco.cms.businesslogic;
|
||||
using umbraco.cms.businesslogic.property;
|
||||
|
||||
namespace umbraco.Test
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for MediaTest and is intended
|
||||
///to contain all MediaTest Unit Tests
|
||||
/// This will test the Media data layer.
|
||||
/// These test assume the following criteria, if this criteria is not met, these tests will fail:
|
||||
/// - There is a Label data type assigned to one of your Media types.
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class MediaTest
|
||||
@@ -31,6 +33,24 @@ namespace umbraco.Test
|
||||
Assert.IsInstanceOfType(m_NewRootMedia, typeof(Media));
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void Media_UpdateDataTest()
|
||||
{
|
||||
//System.Diagnostics.Debugger.Break();
|
||||
|
||||
//set the value of a text property
|
||||
var m = CreateNewUnderRoot(m_ExistingMediaType);
|
||||
var p = GetLabelProperty(m_ExistingMediaType, m);
|
||||
p.Value = "HELLO!";
|
||||
|
||||
Assert.AreEqual("HELLO!", m.getProperty(p.PropertyType).Value);
|
||||
|
||||
//completely delete
|
||||
m.delete(true);
|
||||
|
||||
Assert.IsFalse(Media.IsNode(m.Id));
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void Media_DeleteHeirarchyPermanentlyTest()
|
||||
{
|
||||
@@ -314,6 +334,27 @@ namespace umbraco.Test
|
||||
/// </summary>
|
||||
private Media m_NewRootMedia;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a label property of the document type specified. This will throw an exception if one is not found.
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
private Property GetLabelProperty(MediaType mt, Media m)
|
||||
{
|
||||
DataTypeNoEdit lblField = new DataTypeNoEdit();
|
||||
var prop = mt.PropertyTypes
|
||||
.Where(x => x.DataTypeDefinition.DataType.Id == lblField.Id).First();
|
||||
return m.GenericProperties.Where(x => x.PropertyType.Id == prop.Id).First();
|
||||
}
|
||||
|
||||
private Property GetUploadProperty(MediaType mt, Media m)
|
||||
{
|
||||
DataTypeNoEdit lblField = new DataTypeNoEdit();
|
||||
var prop = mt.PropertyTypes
|
||||
.Where(x => x.DataTypeDefinition.DataType.Id == lblField.Id).First();
|
||||
return m.GenericProperties.Where(x => x.PropertyType.Id == prop.Id).First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets initialized for each test and is set to an existing document type
|
||||
/// </summary>
|
||||
|
||||
304
umbraco.Test/MediaTypeTest.cs
Normal file
304
umbraco.Test/MediaTypeTest.cs
Normal file
@@ -0,0 +1,304 @@
|
||||
using umbraco.cms.businesslogic.media;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using umbraco.BusinessLogic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
|
||||
namespace umbraco.Test
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for MediaTypeTest and is intended
|
||||
///to contain all MediaTypeTest Unit Tests
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class MediaTypeTest
|
||||
{
|
||||
/// <summary>
|
||||
///A test for GetAll
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void MediaType_GetAllTest()
|
||||
{
|
||||
//check with sql that it's the correct number of children
|
||||
var ids = new List<int>();
|
||||
using (var reader = Application.SqlHelper.ExecuteReader(MediaType.m_SQLOptimizedGetAll,
|
||||
Application.SqlHelper.CreateParameter("@nodeObjectType", MediaType._objectType)))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
ids.Add(reader.Get<int>("id"));
|
||||
}
|
||||
}
|
||||
|
||||
var all = MediaType.GetAllAsList();
|
||||
|
||||
Assert.AreEqual<int>(ids.Distinct().Count(), all.Count());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will create 3 media types, and create nodes in the following structure:
|
||||
/// - root
|
||||
/// -- node1 (of media type #1)
|
||||
/// --- node 2 (of media type #2)
|
||||
/// ---- node 3 (of media type #1)
|
||||
/// ----- node 4 (of media type #3)
|
||||
///
|
||||
/// Then we'll delete media type #1. The result should be that node1 and node3 are completely deleted from the database and node2 and node4 are
|
||||
/// moved to the recycle bin.
|
||||
/// </summary>
|
||||
[TestMethod()]
|
||||
public void MediaType_DeleteDocTypeWithContentAndChildrenOfDifferentDocTypes()
|
||||
{
|
||||
//System.Diagnostics.Debugger.Break();
|
||||
|
||||
//create the doc types
|
||||
var mt1 = CreateNewMediaType();
|
||||
var mt2 = CreateNewMediaType();
|
||||
var mt3 = CreateNewMediaType();
|
||||
|
||||
//create the heirarchy
|
||||
mt1.AllowedChildContentTypeIDs = new int[] { mt2.Id, mt3.Id };
|
||||
mt1.Save();
|
||||
mt2.AllowedChildContentTypeIDs = new int[] { mt1.Id };
|
||||
mt2.Save();
|
||||
|
||||
//create the content tree
|
||||
var node1 = Media.MakeNew("TEST" + Guid.NewGuid().ToString("N"), mt1, m_User, -1);
|
||||
var node2 = Media.MakeNew("TEST" + Guid.NewGuid().ToString("N"), mt2, m_User, node1.Id);
|
||||
var node3 = Media.MakeNew("TEST" + Guid.NewGuid().ToString("N"), mt1, m_User, node2.Id);
|
||||
var node4 = Media.MakeNew("TEST" + Guid.NewGuid().ToString("N"), mt3, m_User, node3.Id);
|
||||
|
||||
//do the deletion of doc type #1
|
||||
DeleteMediaType(mt1);
|
||||
|
||||
//do our checks
|
||||
Assert.IsFalse(Media.IsNode(node1.Id), "node1 is not deleted"); //this was of doc type 1, should be gone
|
||||
Assert.IsFalse(Media.IsNode(node3.Id), "node3 is not deleted"); //this was of doc type 1, should be gone
|
||||
|
||||
Assert.IsTrue(Media.IsNode(node2.Id), "node2 is deleted");
|
||||
Assert.IsTrue(Media.IsNode(node4.Id), "node4 is deleted");
|
||||
|
||||
node2 = new Media(node2.Id);//need to re-query the node
|
||||
Assert.IsTrue(node2.IsTrashed, "node2 is not in the trash");
|
||||
node4 = new Media(node4.Id); //need to re-query the node
|
||||
Assert.IsTrue(node4.IsTrashed, "node 4 is not in the trash");
|
||||
|
||||
//remove the old data
|
||||
DeleteMediaType(mt2);
|
||||
DeleteMediaType(mt3);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests adding every type of property to a new media type on a new tab, then delete the tab, then the media type
|
||||
/// </summary>
|
||||
[TestMethod()]
|
||||
public void MediaType_AddPropertiesToTabThenDeleteItTest()
|
||||
{
|
||||
//System.Diagnostics.Debugger.Break();
|
||||
|
||||
//allow itself to be created under itself
|
||||
m_NewMediaType.AllowedChildContentTypeIDs = new int[] { m_NewMediaType.Id };
|
||||
//create a tab
|
||||
m_NewMediaType.AddVirtualTab("TEST");
|
||||
|
||||
//test the tab
|
||||
var tabs = m_NewMediaType.getVirtualTabs.ToList();
|
||||
Assert.AreEqual(1, tabs.Count);
|
||||
|
||||
//create a property
|
||||
var allDataTypes = DataTypeDefinition.GetAll().ToList(); //get all definitions
|
||||
var i = 0;
|
||||
foreach (var dataType in allDataTypes)
|
||||
{
|
||||
//add a property type of the first type found in the list
|
||||
m_NewMediaType.AddPropertyType(dataType, "testProperty" + (++i).ToString(), "Test Property" + i.ToString());
|
||||
//test the prop
|
||||
var prop = m_NewMediaType.getPropertyType("testProperty" + i.ToString());
|
||||
Assert.IsTrue(prop.Id > 0);
|
||||
Assert.AreEqual("Test Property" + i.ToString(), prop.Name);
|
||||
//put the properties to the tab
|
||||
m_NewMediaType.SetTabOnPropertyType(prop, tabs[0].Id);
|
||||
//re-get the property since data is cached in the object
|
||||
prop = m_NewMediaType.getPropertyType("testProperty" + i.ToString());
|
||||
Assert.AreEqual<int>(tabs[0].Id, prop.TabId);
|
||||
}
|
||||
|
||||
//now we need to delete the tab
|
||||
m_NewMediaType.DeleteVirtualTab(tabs[0].Id);
|
||||
}
|
||||
|
||||
#region Test to write
|
||||
///// <summary>
|
||||
/////A test for Save
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void SaveTest()
|
||||
//{
|
||||
// Guid id = new Guid(); // TODO: Initialize to an appropriate value
|
||||
// MediaType target = new MediaType(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 MakeNew
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void MakeNewTest()
|
||||
//{
|
||||
// User u = null; // TODO: Initialize to an appropriate value
|
||||
// string Text = string.Empty; // TODO: Initialize to an appropriate value
|
||||
// MediaType expected = null; // TODO: Initialize to an appropriate value
|
||||
// MediaType actual;
|
||||
// actual = MediaType.MakeNew(u, Text);
|
||||
// Assert.AreEqual(expected, actual);
|
||||
// Assert.Inconclusive("Verify the correctness of this test method.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for GetByAlias
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void GetByAliasTest()
|
||||
//{
|
||||
// string Alias = string.Empty; // TODO: Initialize to an appropriate value
|
||||
// MediaType expected = null; // TODO: Initialize to an appropriate value
|
||||
// MediaType actual;
|
||||
// actual = MediaType.GetByAlias(Alias);
|
||||
// Assert.AreEqual(expected, actual);
|
||||
// Assert.Inconclusive("Verify the correctness of this test method.");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for delete
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void deleteTest()
|
||||
//{
|
||||
// Guid id = new Guid(); // TODO: Initialize to an appropriate value
|
||||
// MediaType target = new MediaType(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 MediaType Constructor
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void MediaTypeConstructorTest1()
|
||||
//{
|
||||
// int id = 0; // TODO: Initialize to an appropriate value
|
||||
// MediaType target = new MediaType(id);
|
||||
// Assert.Inconclusive("TODO: Implement code to verify target");
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////A test for MediaType Constructor
|
||||
/////</summary>
|
||||
//[TestMethod()]
|
||||
//public void MediaTypeConstructorTest()
|
||||
//{
|
||||
// Guid id = new Guid(); // TODO: Initialize to an appropriate value
|
||||
// MediaType target = new MediaType(id);
|
||||
// Assert.Inconclusive("TODO: Implement code to verify target");
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region Private properties and methods
|
||||
|
||||
private User m_User = new User(0);
|
||||
|
||||
/// <summary>
|
||||
/// before each test starts, this object is created so it can be used for testing.
|
||||
/// </summary>
|
||||
private MediaType m_NewMediaType;
|
||||
|
||||
/// <summary>
|
||||
/// Create a brand new media type
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private MediaType CreateNewMediaType()
|
||||
{
|
||||
var mt = MediaType.MakeNew(m_User, "TEST" + Guid.NewGuid().ToString("N"));
|
||||
Assert.IsTrue(mt.Id > 0);
|
||||
Assert.AreEqual(DateTime.Now.Date, mt.CreateDateTime.Date);
|
||||
return mt;
|
||||
}
|
||||
|
||||
private void DeleteMediaType(MediaType mt)
|
||||
{
|
||||
var id = mt.Id;
|
||||
|
||||
mt.delete();
|
||||
|
||||
//check with sql that it is gone
|
||||
var count = Application.SqlHelper.ExecuteScalar<int>("SELECT COUNT(*) FROM umbracoNode WHERE id=@id",
|
||||
Application.SqlHelper.CreateParameter("@id", id));
|
||||
|
||||
Assert.AreEqual(0, count);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Test Context
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Initialize and cleanup
|
||||
//
|
||||
//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()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
/// <summary>
|
||||
/// Create a new document type for use in tests
|
||||
/// </summary>
|
||||
[TestInitialize()]
|
||||
public void MyTestInitialize()
|
||||
{
|
||||
m_NewMediaType = CreateNewMediaType();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the created document type
|
||||
/// </summary>
|
||||
[TestCleanup()]
|
||||
public void MyTestCleanup()
|
||||
{
|
||||
DeleteMediaType(m_NewMediaType);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,9 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="DocumentTest.cs" />
|
||||
<Compile Include="DocumentTypeTest.cs" />
|
||||
<Compile Include="LanguageTest.cs" />
|
||||
<Compile Include="MediaTest.cs" />
|
||||
<Compile Include="MediaTypeTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user