Beispiel #1
0
        public void BuildStrategy_ShouldFail_DueToNotExistingProject([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrange
            var projectName = inputParams.ElementAtOrDefault(0);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            var fileSystemMock = new Mock <IFileSystem>();

            fileSystemMock.Setup(x => x.DirectoryExists(projectName)).Returns(false);

            var buildStrategy = new BuildNameStrategy(string.Empty, fileSystemMock.Object);

            // Act
            var strategyResult = buildStrategy.Execute(inputParams);

            // Assert
            Assert.IsFalse(strategyResult.Success);
            Assert.AreEqual(string.Format(OutputText.OpcuaappBuildFailureProjectDoesNotExist, projectName), strategyResult.OutputMessages.First().Key);
            fileSystemMock.VerifyAll();
            loggerListenerMock.Verify(y => y.Warn(LoggingText.BuildProjectDoesNotExist), Times.Once);
            AppioLogger.RemoveListener(loggerListenerMock.Object);
            fileSystemMock.Verify(x => x.DirectoryExists(projectName), Times.Once);
        }
Beispiel #2
0
        public void BuildStrategy_Should_SucceessOnBuildableServerProject([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrange
            var projectName = inputParams.ElementAtOrDefault(0);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            var projectBuildDirectory = Path.Combine(projectName, Constants.DirectoryName.MesonBuild);

            var fileSystemMock = new Mock <IFileSystem>();

            fileSystemMock.Setup(x => x.DirectoryExists(projectName)).Returns(true);

            fileSystemMock.Setup(x => x.CombinePaths(It.IsAny <string>(), It.IsAny <string>())).Returns(projectBuildDirectory);
            fileSystemMock.Setup(x => x.CallExecutable(Constants.ExecutableName.Meson, projectName, Constants.DirectoryName.MesonBuild)).Returns(true);
            fileSystemMock.Setup(x => x.CallExecutable(Constants.ExecutableName.Ninja, projectBuildDirectory, string.Empty)).Returns(true);

            var appioprojFilePath = Path.Combine(projectName, projectName + Constants.FileExtension.Appioproject);

            fileSystemMock.Setup(x => x.CombinePaths(projectName, projectName + Constants.FileExtension.Appioproject)).Returns(appioprojFilePath);

            var serverConstantsFilePath = Path.Combine();

            fileSystemMock.Setup(x => x.CombinePaths(projectName, Constants.DirectoryName.SourceCode, Constants.DirectoryName.ServerApp, Constants.FileName.SourceCode_constants_h)).Returns(serverConstantsFilePath);

            using (var appioprojMemoryStreamFirstCall = new MemoryStream(Encoding.ASCII.GetBytes(_appioprojServerContent)))
                using (var appioprojMemoryStreamSecondCall = new MemoryStream(Encoding.ASCII.GetBytes(_appioprojServerContent)))
                    using (var serverConstantsMemoryStrean = new MemoryStream(Encoding.ASCII.GetBytes(_sampleServerConstantsFileContent)))
                    {
                        fileSystemMock.SetupSequence(x => x.ReadFile(appioprojFilePath)).Returns(appioprojMemoryStreamFirstCall).Returns(appioprojMemoryStreamSecondCall);
                        fileSystemMock.Setup(x => x.ReadFile(serverConstantsFilePath)).Returns(serverConstantsMemoryStrean);

                        var buildStrategy = new BuildNameStrategy(string.Empty, fileSystemMock.Object);

                        // Act
                        var strategyResult = buildStrategy.Execute(inputParams);

                        // Assert
                        Assert.IsTrue(strategyResult.Success);
                        Assert.AreEqual(string.Format(OutputText.OpcuaappBuildSuccess, projectName), strategyResult.OutputMessages.First().Key);
                        fileSystemMock.VerifyAll();
                        loggerListenerMock.Verify(y => y.Info(It.IsAny <string>()), Times.Once);
                        AppioLogger.RemoveListener(loggerListenerMock.Object);
                        fileSystemMock.Verify(x => x.DirectoryExists(projectName), Times.Once);
                    }
        }
Beispiel #3
0
        public void BuildStrategy_ShouldFail_DueToFailingExecutableCalls([ValueSource(nameof(FailingExecutableStates))] bool[] executableStates)
        {
            // Arrange
            var projectName = "anyName";

            var mesonState = executableStates.ElementAt(0);
            var ninjaState = executableStates.ElementAt(1);

            var fileSystemMock = new Mock <IFileSystem>();

            fileSystemMock.Setup(x => x.DirectoryExists(projectName)).Returns(true);

            fileSystemMock.Setup(x => x.CallExecutable(Constants.ExecutableName.Meson, It.IsAny <string>(), It.IsAny <string>())).Returns(mesonState);
            fileSystemMock.Setup(x => x.CallExecutable(Constants.ExecutableName.Ninja, It.IsAny <string>(), It.IsAny <string>())).Returns(ninjaState);

            var appioprojFilePath = Path.Combine(projectName, projectName + Constants.FileExtension.Appioproject);

            fileSystemMock.Setup(x => x.CombinePaths(projectName, projectName + Constants.FileExtension.Appioproject)).Returns(appioprojFilePath);

            var serverConstantsFilePath = Path.Combine();

            fileSystemMock.Setup(x => x.CombinePaths(projectName, Constants.DirectoryName.SourceCode, Constants.DirectoryName.ServerApp, Constants.FileName.SourceCode_constants_h)).Returns(serverConstantsFilePath);

            using (var appioprojMemoryStreamFirstCall = new MemoryStream(Encoding.ASCII.GetBytes(_appioprojServerContent)))
                using (var appioprojMemoryStreamSecondCall = new MemoryStream(Encoding.ASCII.GetBytes(_appioprojServerContent)))
                    using (var serverConstantsMemoryStrean = new MemoryStream(Encoding.ASCII.GetBytes(string.Empty)))
                    {
                        fileSystemMock.SetupSequence(x => x.ReadFile(appioprojFilePath)).Returns(appioprojMemoryStreamFirstCall).Returns(appioprojMemoryStreamSecondCall);
                        fileSystemMock.Setup(x => x.ReadFile(serverConstantsFilePath)).Returns(serverConstantsMemoryStrean);

                        var buildStrategy      = new BuildNameStrategy(string.Empty, fileSystemMock.Object);
                        var loggerListenerMock = new Mock <ILoggerListener>();
                        loggerListenerMock.Setup(B => B.Warn(It.IsAny <string>()));
                        AppioLogger.RegisterListener(loggerListenerMock.Object);

                        // Act
                        var strategyResult = buildStrategy.Execute(new[] { projectName });

                        // Assert
                        Assert.IsFalse(strategyResult.Success);
                        Assert.AreEqual(OutputText.OpcuaappBuildFailure, strategyResult.OutputMessages.First().Key);
                        fileSystemMock.Verify(x => x.ReadFile(appioprojFilePath), Times.Exactly(2));
                        loggerListenerMock.Verify(y => y.Warn(It.IsAny <string>()), Times.Once);
                        AppioLogger.RemoveListener(loggerListenerMock.Object);
                    }
        }
Beispiel #4
0
        public void ShouldExecuteStrategy_Fail_MissingParameter([ValueSource(nameof(InvalidInputs))] string[] inputParams)
        {
            // Arrange
            var projectName = inputParams.ElementAtOrDefault(0);

            var fileSystemMock     = new Mock <IFileSystem>();
            var loggerListenerMock = new Mock <ILoggerListener>();

            loggerListenerMock.Setup(y => y.Warn(It.IsAny <string>()));
            AppioLogger.RegisterListener(loggerListenerMock.Object);
            var buildStrategy = new BuildNameStrategy(string.Empty, fileSystemMock.Object);

            // Act
            var strategyResult = buildStrategy.Execute(inputParams);

            // Assert
            Assert.IsFalse(strategyResult.Success);
            Assert.AreEqual(string.Format(OutputText.OpcuaappBuildFailureProjectDoesNotExist, projectName), strategyResult.OutputMessages.First().Key);
            loggerListenerMock.Verify(y => y.Warn(It.IsAny <string>()), Times.Once);
            AppioLogger.RemoveListener(loggerListenerMock.Object);
        }