using System; using System.Xml; using MbUnit.ReSharperRunner.MbUnit; namespace MbUnit.ReSharperRunner.Tasks { [Serializable] public class MbUnitTestFixtureTask : MbUnitRemoteTask, IEquatable { private readonly string assemblyLocation; private readonly bool explicitly; private readonly string typeName; [NonSerialized] private object instance; public MbUnitTestFixtureTask(XmlElement element) : base(element) { typeName = GetXmlAttribute(element, "TypeName"); assemblyLocation = GetXmlAttribute(element, "AssemblyLocation"); explicitly = GetXmlAttribute(element, "Explicitly") == "true"; } public MbUnitTestFixtureTask(string assemblyLocation, string typeName, bool explicitly) : base(MbUnitTestProvider.ProviderId) { if (assemblyLocation == null) { throw new ArgumentNullException("assemblyLocation"); } if (typeName == null) { throw new ArgumentNullException("typeName"); } this.assemblyLocation = assemblyLocation; this.typeName = typeName; this.explicitly = explicitly; } public MbUnitTestFixtureAction MbUnitTestAction { get { return new MbUnitTestFixtureAction(assemblyLocation, typeName); } } public object Instance { get { return instance; } set { instance = value; } } public string AssemblyLocation { get { return assemblyLocation; } } public bool Explicitly { get { return explicitly; } } public string TypeName { get { return typeName; } } public override string RunName { get { return typeName; } } public override void SaveXml(XmlElement element) { base.SaveXml(element); SetXmlAttribute(element, "TypeName", TypeName); SetXmlAttribute(element, "AssemblyLocation", AssemblyLocation); SetXmlAttribute(element, "Explicitly", Explicitly ? "true" : "false"); } public bool Equals(MbUnitTestFixtureTask mbUnitTestFixtureTask) { if (mbUnitTestFixtureTask == null) { return false; } if (!base.Equals(mbUnitTestFixtureTask)) { return false; } if (!Equals(assemblyLocation, mbUnitTestFixtureTask.assemblyLocation)) { return false; } if (!Equals(explicitly, mbUnitTestFixtureTask.explicitly)) { return false; } if (!Equals(typeName, mbUnitTestFixtureTask.typeName)) { return false; } if (!Equals(instance, mbUnitTestFixtureTask.instance)) { return false; } return true; } public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return true; } return Equals(obj as MbUnitTestFixtureTask); } public override int GetHashCode() { int result = base.GetHashCode(); result = 29 * result + (assemblyLocation != null ? assemblyLocation.GetHashCode() : 0); result = 29 * result + explicitly.GetHashCode(); result = 29 * result + (typeName != null ? typeName.GetHashCode() : 0); result = 29 * result + (instance != null ? instance.GetHashCode() : 0); return result; } } }