public void InvokeWithMissingWorkingDirectoryThrowsContractException()
        {
            // Arrange
            var parameters = new DictionaryParameters();
            parameters.Add("CommandLine", "arbitrary-string");
            parameters.Add("missing-parameter-WorkingDirectory", "arbitrary-string");
            parameters.Add("Credential", CredentialCache.DefaultCredentials);
            var jobResult = new JobResult();

            // Act
            var sut = new ProgrammePlugin();
            var result = sut.Invoke(parameters, jobResult);

            // Assert
            // N/A
        }
        public void GetConfigurationSucceeds()
        {
            // Arrange
            var configuration = new DictionaryParameters();
            var sut = new ProgrammePlugin();
            sut.Initialise(configuration, new Logger(), true);

            // Act
            configuration = sut.Configuration;

            // Assert
            Assert.AreEqual(configuration, sut.Configuration);
        }
        public void SetConfigurationSucceeds()
        {
            // Arrange
            var configuration = new DictionaryParameters();

            // Act
            var sut = new ProgrammePlugin();
            sut.Configuration = configuration;

            // Assert
            Assert.AreEqual(configuration, sut.Configuration);
        }
        public void InvokeFails()
        {
            // Arrange
            var commandLine = "arbitrary-string";
            var workingDirectory = "arbitrary-string";
            var credential = new NetworkCredential("arbitrary-user", "arbitrary-password", "arbitrary-domain");
            var parameters = new DictionaryParameters();
            parameters.Add("JobId", 42);
            parameters.Add("CommandLine", commandLine);
            parameters.Add("WorkingDirectory", workingDirectory);
            parameters.Add("Credential", credential);
            var jobResult = new JobResult();

            Mock.SetupStatic(typeof(biz.dfch.CS.Utilities.Process));

            Mock.Arrange(
                () => biz.dfch.CS.Utilities.Process.StartProcess(
                    Arg.Is<string>(commandLine),
                    Arg.Is<string>(workingDirectory),
                    Arg.Is<NetworkCredential>(credential))
                )
                .Throws<InvalidOperationException>()
                .OccursOnce();

            // Act
            var sut = new ProgrammePlugin();
            sut.Initialise(new DictionaryParameters(), new Logger(), true);
            var result = sut.Invoke(parameters, jobResult);

            // Assert
            Mock.Assert(
                () => biz.dfch.CS.Utilities.Process.StartProcess(
                    Arg.Is<string>(commandLine), 
                    Arg.Is<string>(workingDirectory), 
                    Arg.Is<NetworkCredential>(credential))
                );
            Assert.IsFalse(result);
            Assert.IsFalse(jobResult.Succeeded);
            Assert.AreNotEqual(0, jobResult.Code);
            Assert.IsFalse(string.IsNullOrWhiteSpace(jobResult.Message));
            Assert.IsFalse(string.IsNullOrWhiteSpace(jobResult.Description));
        }
        public void InvokeSucceeds()
        {
            // Arrange
            var commandLine = "arbitrary-string";
            var workingDirectory = "arbitrary-string";
            var credential = new NetworkCredential("arbitrary-user", "arbitrary-password", "arbitrary-domain");
            var parameters = new DictionaryParameters();
            parameters.Add("JobId", 42);
            parameters.Add("CommandLine", commandLine);
            parameters.Add("WorkingDirectory", workingDirectory);
            parameters.Add("Credential", credential);
            var jobResult = new JobResult();

            Mock.SetupStatic(typeof(biz.dfch.CS.Utilities.Process));

            Mock.Arrange(
                () => biz.dfch.CS.Utilities.Process.StartProcess(
                    Arg.Is<string>(commandLine), 
                    Arg.Is<string>(workingDirectory), 
                    Arg.Is<NetworkCredential>(credential))
                )
                .Returns(default(Dictionary<string, string>))
                .OccursOnce();

            // Act
            var sut = new ProgrammePlugin();
            sut.Initialise(new DictionaryParameters(), new Logger(), true);
            var result = sut.Invoke(parameters, jobResult);

            // Assert
            Mock.Assert(
                () => biz.dfch.CS.Utilities.Process.StartProcess(
                    Arg.Is<string>(commandLine), 
                    Arg.Is<string>(workingDirectory), 
                    Arg.Is<NetworkCredential>(credential))
                );
            Assert.IsTrue(result);
            Assert.IsTrue(jobResult.Succeeded);
            Assert.AreEqual(0, jobResult.Code);
        }
        public void InvokeWithInvalidTypeCredentialThrowsContractException()
        {
            // Arrange
            var parameters = new DictionaryParameters();
            parameters.Add("CommandLine", "arbitrary-string");
            parameters.Add("WorkingDirectory", "arbitrary-string");
            parameters.Add("Credential", new object());
            var jobResult = new JobResult();

            // Act
            var sut = new ProgrammePlugin();
            var result = sut.Invoke(parameters, jobResult);

            // Assert
            // N/A
        }