コード例 #1
0
        public void NoWaitWithAsJob()
        {
            var mock   = new Mock <ICommandRuntime>();
            var cmdlet = new AzureStreamTestCmdlet();

            cmdlet.MyInvocation.BoundParameters["AsJob"]  = true;
            cmdlet.MyInvocation.BoundParameters["NoWait"] = true;

            mock.Setup(m => m.WriteObject(It.IsAny <object>())).Throws(new InvalidOperationException("Should not execute as job"));

            cmdlet.CommandRuntime = mock.Object;
            cmdlet.ExecuteSynchronouslyOrAsJob();
        }
コード例 #2
0
        AzureStreamTestCmdlet SetupCmdlet(bool CallShouldProcess, bool CallShouldContinue, out Mock <ICommandRuntime> mockRuntime)
        {
            var cmdlet = new AzureStreamTestCmdlet();

            cmdlet.Warning.Add(Warning);
            cmdlet.Debug.Add(Debug);
            cmdlet.Verbose.Add(Verbose);
            cmdlet.Progress.Add(Progress);
            cmdlet.Output.Add(Output);
            cmdlet.Error.Add(Error);
            mockRuntime = new Mock <ICommandRuntime>();
            if (CallShouldProcess || CallShouldContinue)
            {
                cmdlet.CallShouldProcess = true;
                mockRuntime.Setup(m => m.ShouldProcess(It.IsAny <string>())).Returns(true);
                mockRuntime.Setup(m => m.ShouldProcess(It.IsAny <string>(), It.IsAny <string>())).Returns(true);
                mockRuntime.Setup(m => m.ShouldProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            }
            else
            {
                mockRuntime.Setup(m => m.ShouldProcess(It.IsAny <string>())).Throws(new InvalidOperationException("ShouldProcess should not be called"));
                mockRuntime.Setup(m => m.ShouldProcess(It.IsAny <string>(), It.IsAny <string>())).Throws(new InvalidOperationException("ShouldProcess should not be called"));
                mockRuntime.Setup(m => m.ShouldProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Throws(new InvalidOperationException("ShouldProcess should not be called"));
            }

            if (CallShouldContinue)
            {
                cmdlet.CallShouldContinue = true;
                mockRuntime.Setup(m => m.ShouldContinue(It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            }
            else
            {
                mockRuntime.Setup(m => m.ShouldContinue(It.IsAny <string>(), It.IsAny <string>())).Throws(new InvalidOperationException("ShouldContinue should not be called"));
            }

            cmdlet.CommandRuntime = mockRuntime.Object;

            return(cmdlet);
        }