using System; using System.Xml; using MbUnit.ReSharperRunner.MbUnit; namespace MbUnit.ReSharperRunner.Tasks { [Serializable] public class MbUnitTestTask : MbUnitRemoteTask, IEquatable { private readonly bool explicity; private readonly string testMethod; private readonly string testType; public MbUnitTestTask(XmlElement element) : base(element) { testMethod = GetXmlAttribute(element, "TestMethod"); testType = GetXmlAttribute(element, "TestType"); explicity = GetXmlAttribute(element, "Explicity") == "true"; } public MbUnitTestTask(string testType, string testMethod, bool explicity) : base(MbUnitTestProvider.ProviderId) { if (testMethod == null) { throw new ArgumentNullException("testMethod"); } if (testType == null) { throw new ArgumentNullException("testType"); } this.testType = testType; this.testMethod = testMethod; this.explicity = explicity; } public bool Explicity { get { return explicity; } } public string TestMethod { get { return testMethod; } } public string TestType { get { return testType; } } public MbUnitTestMethodAction MbUnitTestAction { get { return new MbUnitTestMethodAction(testType, testMethod); } } public override string RunName { get { string className; int pos = testType.LastIndexOf('.'); if (pos >= 0) { className = testType.Substring(pos + 1); } else { className = testType; } string methodName = TestMethod; if (methodName.EndsWith("()")) { methodName = methodName.Substring(0, methodName.Length - 2); } return string.Format("{0}.{1}", className, methodName); } } public bool Equals(MbUnitTestTask mbUnitTestTask) { if (mbUnitTestTask == null) { return false; } if (!base.Equals(mbUnitTestTask)) { return false; } if (!Equals(explicity, mbUnitTestTask.explicity)) { return false; } if (!Equals(testMethod, mbUnitTestTask.testMethod)) { return false; } if (!Equals(testType, mbUnitTestTask.testType)) { return false; } return true; } public override void SaveXml(XmlElement element) { base.SaveXml(element); SetXmlAttribute(element, "TestMethod", TestMethod); SetXmlAttribute(element, "TestType", TestType); SetXmlAttribute(element, "Explicity", Explicity ? "true" : "false"); } public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return true; } return Equals(obj as MbUnitTestTask); } public override int GetHashCode() { int result = base.GetHashCode(); result = 29 * result + explicity.GetHashCode(); result = 29 * result + (testMethod != null ? testMethod.GetHashCode() : 0); result = 29 * result + (testType != null ? testType.GetHashCode() : 0); return result; } } }