I cannot figure out how to unit test if this batch file fails if it is not provided with arguments.
[Cmdlet(VerbsCommon.Move, "SomeResource")] public class MoveSomeResource : Cmdlet { private int _id; [Parameter(Position = 0, Mandatory = true)] [ValidateNotNullOrEmpty] public int ID { get { return _id; } set { _id = value; } } protected override void ProcessRecord() { string text = string.Format("Move Resource {0} ", this._id);
I tried the following method, but it does not crash due to a ValidateNotNullOrEmpty error, but it fulfills the role in // Do Processing and does not work there.
[TestMethod] public void TestMoveBluh() { MoveSomeResource cmd = new MoveSomeResource(); IEnumerator result = cmd.Invoke().GetEnumerator(); try { result.MoveNext(); } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(ArgumentException)); } }
source share