// // Erstellt: aweinert am 10.12.2007 // using System; using System.Xml; using MbUnit.Framework; using MbUnit.ReSharperRunner.Tasks; namespace MbUnit.ReSharper3.Tests { public class TestType { public void TestMethod() {} } [TestFixture] public class MbUnitTestTaskTest { [Test] public void Initialize_from_Contructor() { MbUnitTestTask testTask = new MbUnitTestTask("Foo", "Bar", false); Assert.AreEqual("Foo", testTask.TestType); Assert.AreEqual("Bar", testTask.TestMethod); Assert.AreEqual(false, testTask.Explicity); testTask = new MbUnitTestTask("Test", "for", true); Assert.AreEqual("Test", testTask.TestType); Assert.AreEqual("for", testTask.TestMethod); Assert.AreEqual(true, testTask.Explicity); } [Test] [ExpectedException(typeof(ArgumentNullException))] public void Faill_if_Constructor_TestMethod_is_null() { new MbUnitTestTask("Blah", null, false); } [Test] [ExpectedException(typeof(ArgumentNullException))] public void Faill_if_Constructor_TestType_is_null() { new MbUnitTestTask(null, "Blah", false); } [Test] public void Is_a_Correct_RunName_created() { MbUnitTestTask testTask = new MbUnitTestTask("MbUnit.ReSharper3.Tests.TestType", "TestMethod", false); Assert.AreEqual("TestType.TestMethod", testTask.RunName); testTask = new MbUnitTestTask("MbUnit.ReSharper3.Tests.TestType", "TestMethod()", false); Assert.AreEqual("TestType.TestMethod", testTask.RunName); testTask = new MbUnitTestTask("TestType", "TestMethod()", false); Assert.AreEqual("TestType.TestMethod", testTask.RunName); } [Test] public void TestEqual() { Assert.AreEqual(new MbUnitTestTask("Are", "Equal", true), new MbUnitTestTask("Are", "Equal", true)); Assert.AreEqual(new MbUnitTestTask("Are", "Equal", true).GetHashCode(), new MbUnitTestTask("Are", "Equal", true).GetHashCode()); } [Test] public void IsNotEqual() { Assert.AreNotEqual(new MbUnitTestTask("Are", "Equal", true), new MbUnitTestTask("Area", "NotEqual", true)); Assert.AreNotEqual(new MbUnitTestTask("Are", "Equal", true), new MbUnitTestTask("Not", "Equal", true)); Assert.AreNotEqual(new MbUnitTestTask("Are", "Equal", true), new MbUnitTestTask("Area", "Equal", false)); Assert.AreNotEqual(new MbUnitTestTask("Are", "Equal", true).GetHashCode(), new MbUnitTestTask("Area", "Equal", false).GetHashCode()); } [Test] public void Initialize_from_Constructor_with_XmlElement() { XmlDocument xmlDoc = new XmlDocument(); XmlElement ele = xmlDoc.CreateElement("task"); ele.Attributes.Append(CreateAttribute(xmlDoc, "TestType", "Foo")); ele.Attributes.Append(CreateAttribute(xmlDoc, "TestMethod", "Bar")); ele.Attributes.Append(CreateAttribute(xmlDoc, "Explicity", "false")); MbUnitTestTask testTask = new MbUnitTestTask(ele); Assert.AreEqual("Foo", testTask.TestType); Assert.AreEqual("Bar", testTask.TestMethod); Assert.AreEqual(false, testTask.Explicity); ele = xmlDoc.CreateElement("task"); ele.Attributes.Append(CreateAttribute(xmlDoc, "TestType", "Test")); ele.Attributes.Append(CreateAttribute(xmlDoc, "TestMethod", "for")); ele.Attributes.Append(CreateAttribute(xmlDoc, "Explicity", "true")); testTask = new MbUnitTestTask(ele); Assert.AreEqual("Test", testTask.TestType); Assert.AreEqual("for", testTask.TestMethod); Assert.AreEqual(true, testTask.Explicity); } [Test] public void TestSaveXml() { MbUnitTestTask testTask = new MbUnitTestTask("Foo", "Bar", false); XmlDocument doc = new XmlDocument(); XmlElement ele = doc.CreateElement("task"); testTask.SaveXml(ele); Assert.AreEqual("Foo", ele.Attributes["TestType"].Value); Assert.AreEqual("Bar", ele.Attributes["TestMethod"].Value); Assert.AreEqual("false", ele.Attributes["Explicity"].Value); testTask = new MbUnitTestTask("Test", "for", true); Assert.AreEqual("Test", testTask.TestType); Assert.AreEqual("for", testTask.TestMethod); Assert.AreEqual(true, testTask.Explicity); ele = doc.CreateElement("task"); testTask.SaveXml(ele); Assert.AreEqual("Test", ele.Attributes["TestType"].Value); Assert.AreEqual("for", ele.Attributes["TestMethod"].Value); Assert.AreEqual("true", ele.Attributes["Explicity"].Value); } [Test] public void TestMethodAction_Created() { MbUnitTestTask testTask = new MbUnitTestTask("MbUnit.ReSharper3.Tests.TestType, MbUnit.ReSharper3.Tests", "TestMethod", false); Assert.AreEqual("TestMethod", testTask.MbUnitTestAction.MethodName); } private static XmlAttribute CreateAttribute(XmlDocument xmlDoc, string name, string value) { XmlAttribute attribute = xmlDoc.CreateAttribute(name); attribute.Value = value; return attribute; } } }