Inheritance: IPowerShellExecutor
コード例 #1
0
        public void Constructor_AllParametersAreSet_ObjectIsInstantiated()
        {
            // Arrange
            var powerShellSessionFactory = new Mock<IPowerShellSessionFactory>();

            // Act
            var powerShellExecutor = new PowerShellExecutor(powerShellSessionFactory.Object);

            // Assert
            Assert.IsNotNull(powerShellExecutor);
        }
コード例 #2
0
        public void ExecuteScript_ScriptPathIsInvalid_ResultIsFalse(string scriptPath)
        {
            // Arrange
            var powerShellSessionFactory = new Mock<IPowerShellSessionFactory>();
            var powerShellExecutor = new PowerShellExecutor(powerShellSessionFactory.Object);

            // Act
            var result = powerShellExecutor.ExecuteScript(scriptPath);

            // Assert
            Assert.AreEqual(result.Status, ServiceResultType.Failure);
        }
コード例 #3
0
        public void ExecuteScript_ScriptPathIsSet_PowerShellSessionFactoryReturnsNull_ResultIsFalse()
        {
            // Arrange
            string scriptPath = "some-script.ps1";

            var powerShellSessionFactory = new Mock<IPowerShellSessionFactory>();
            var powerShellExecutor = new PowerShellExecutor(powerShellSessionFactory.Object);

            IPowerShellSession powerShellSession = null;
            powerShellSessionFactory.Setup(s => s.GetSession()).Returns(powerShellSession);

            // Act
            var result = powerShellExecutor.ExecuteScript(scriptPath);

            // Assert
            Assert.AreEqual(result.Status, ServiceResultType.Failure);
        }
コード例 #4
0
        public void ExecuteScript_ScriptPathIsSet_PowerShellSessionExecutesScript_ResultIsTrue()
        {
            // Arrange
            string scriptPath = "some-script.ps1";

            var powerShellSessionFactory = new Mock<IPowerShellSessionFactory>();
            var powerShellExecutor = new PowerShellExecutor(powerShellSessionFactory.Object);

            var powerShellSessionMock = new Mock<IPowerShellSession>();
            powerShellSessionFactory.Setup(s => s.GetSession()).Returns(powerShellSessionMock.Object);

            // Act
            var result = powerShellExecutor.ExecuteScript(scriptPath);

            // Assert
            Assert.AreEqual(result.Status, ServiceResultType.Success);
        }
コード例 #5
0
        public void ExecuteScript_ScriptPathIsSet_PowerShellSessionThrowsException_ResultIsFalse()
        {
            // Arrange
            string scriptPath = "some-script.ps1";

            var powerShellSessionFactory = new Mock<IPowerShellSessionFactory>();
            var powerShellExecutor = new PowerShellExecutor(powerShellSessionFactory.Object);

            var powerShellSessionMock = new Mock<IPowerShellSession>();
            powerShellSessionMock.Setup(p => p.ExecuteScript(It.IsAny<string>())).Throws(new Exception());

            powerShellSessionFactory.Setup(s => s.GetSession()).Returns(powerShellSessionMock.Object);

            // Act
            var result = powerShellExecutor.ExecuteScript(scriptPath);

            // Assert
            Assert.AreEqual(result.Status, ServiceResultType.Failure);
        }