ExecuteScript() public method

public ExecuteScript ( string scriptPath ) : IServiceResult
scriptPath string
return IServiceResult
        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);
        }
        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);
        }
        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);
        }
        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);
        }