public void NewOpcuaAppCommandStrategy_Should_IgnoreInput([ValueSource(nameof(InvalidInputsSecondParam))] string[] inputParams)
        {
            // Arrange
            var loggerListenerMock = new Mock <ILoggerListener>();
            var warnWrittenOut     = false;

            loggerListenerMock.Setup(listener => listener.Warn(It.IsAny <string>())).Callback(delegate { warnWrittenOut = true; });
            AppioLogger.RegisterListener(loggerListenerMock.Object);

            var invalidNameCharsMock = new[] { '/' };
            var invalidPathCharsMock = new[] { '\\' };

            _fileSystemMock.Setup(x => x.GetInvalidFileNameChars()).Returns(invalidNameCharsMock);
            _fileSystemMock.Setup(x => x.GetInvalidPathChars()).Returns(invalidPathCharsMock);

            // Act
            var result = _objectUnderTest.Execute(inputParams);

            // Assert
            Assert.IsTrue(warnWrittenOut);
            Assert.IsFalse(result.Success);
            Assert.AreEqual(string.Format(OutputText.NewOpcuaappCommandFailureInvalidProjectName, inputParams.ElementAt(1)), result.OutputMessages.First().Key);
            _fileSystemMock.Verify(x => x.CreateDirectory(It.IsAny <string>()), Times.Never);
            _fileSystemMock.Verify(x => x.CreateFile(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            _fileSystemMock.Verify(x => x.LoadTemplateFile(It.IsAny <string>()), Times.Never);
            AppioLogger.RemoveListener(loggerListenerMock.Object);
        }
        public void Fail_OnMissingModelFile([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrange
            var warnWrittenOut      = false;
            var opcuaAppName        = $"{inputParams.ElementAtOrDefault(1)}";
            var modelsDirectory     = "models";
            var modelFilePath       = $"{inputParams.ElementAtOrDefault(3)}";
            var validModelExtension = ".xml";

            _fileSystemMock.Setup(x => x.CombinePaths(opcuaAppName, Constants.DirectoryName.Models)).Returns(modelsDirectory);
            _fileSystemMock.Setup(x => x.GetExtension(modelFilePath)).Returns(validModelExtension);
            _fileSystemMock.Setup(x => x.FileExists(modelFilePath)).Returns(false);
            _fileSystemMock.Setup(x => x.DirectoryExists(opcuaAppName)).Returns(true);

            var loggerListenerMock = new Mock <ILoggerListener>();

            loggerListenerMock.Setup(listener => listener.Warn(string.Format(LoggingText.InvalidInformationModelNotExistingPath, modelFilePath))).Callback(delegate { warnWrittenOut = true; });
            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Act
            var result = _objectUnderTest.Execute(inputParams);

            // Assert
            Assert.IsTrue(warnWrittenOut);
            Assert.IsFalse(result.Success);
            Assert.AreEqual(string.Format(OutputText.ImportInformationModelCommandNotExistingModelPath, modelFilePath), result.OutputMessages.First().Key);
            _fileSystemMock.Verify(x => x.CopyFile(modelFilePath, modelsDirectory), Times.Never);
            AppioLogger.RemoveListener(loggerListenerMock.Object);
        }
        public void NewOpcuaAppCommandStrategy_Should_IgnoreInput_UnknownParams([ValueSource(nameof(InvalidInputsFistParam))] string[] inputParams)
        {
            // Arrange
            var nameFlag = inputParams.ElementAtOrDefault(0);

            var loggerListenerMock = new Mock <ILoggerListener>();
            var warnWrittenOut     = false;

            loggerListenerMock.Setup(listener => listener.Warn(It.IsAny <string>())).Callback(delegate { warnWrittenOut = true; });
            AppioLogger.RegisterListener(loggerListenerMock.Object);

            var invalidNameCharsMock = new[] { '/' };
            var invalidPathCharsMock = new[] { '\\' };

            _fileSystemMock.Setup(x => x.GetInvalidFileNameChars()).Returns(invalidNameCharsMock);
            _fileSystemMock.Setup(x => x.GetInvalidPathChars()).Returns(invalidPathCharsMock);

            // Act
            var result = _objectUnderTest.Execute(inputParams);

            // Assert
            Assert.IsTrue(warnWrittenOut);
            Assert.IsFalse(result.Success);
            _fileSystemMock.Verify(x => x.CreateDirectory(It.IsAny <string>()), Times.Never);
            _fileSystemMock.Verify(x => x.CreateFile(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            _fileSystemMock.Verify(x => x.LoadTemplateFile(It.IsAny <string>()), Times.Never);
            AppioLogger.RemoveListener(loggerListenerMock.Object);
        }
Exemple #4
0
 public void SetupTest()
 {
     _fileSystemMock     = new Mock <IFileSystem>();
     _validator          = new ModelValidator(_fileSystemMock.Object);
     _loggerListenerMock = new Mock <ILoggerListener>();
     AppioLogger.RegisterListener(_loggerListenerMock.Object);
 }
Exemple #5
0
        public void RemoveServerFormClientServer([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrage
            var clientName = inputParams.ElementAtOrDefault(1);
            var serverName = inputParams.ElementAtOrDefault(3);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Arrange client file
            var appioClientPath = Path.Combine(clientName, clientName + Constants.FileExtension.Appioproject);

            _fileSystemMock.Setup(x => x.CombinePaths(clientName, clientName + Constants.FileExtension.Appioproject)).Returns(appioClientPath);
            _fileSystemMock.Setup(x => x.FileExists(appioClientPath)).Returns(true);

            using (var clientMemoryStream = new MemoryStream(Encoding.ASCII.GetBytes(_sampleClientServerAppioprojContent)))
                using (var clientServerMemoryStream = new MemoryStream(Encoding.ASCII.GetBytes(_sampleClientServerAppioprojContent)))
                {
                    _fileSystemMock.SetupSequence(x => x.ReadFile(appioClientPath)).Returns(clientMemoryStream).Returns(clientServerMemoryStream);

                    // Act
                    var commandResult = _objectUnderTest.Execute(inputParams);

                    // Assert
                    Assert.IsTrue(commandResult.Success);
                    Assert.IsNotNull(commandResult.OutputMessages);
                    var firstMessageLine = commandResult.OutputMessages.FirstOrDefault();
                    AppioLogger.RemoveListener(loggerListenerMock.Object);
                    loggerListenerMock.Verify(x => x.Info(Resources.text.logging.LoggingText.ReferenceRemoveSuccess), Times.Once);
                    Assert.AreEqual(string.Format(OutputText.ReferenceRemoveSuccess, clientName, serverName), firstMessageLine.Key);
                    Assert.AreEqual(string.Empty, firstMessageLine.Value);
                }
        }
        public void FailBecauseOfMissingAppioslnFile([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrange
            var solutionName = inputParams.ElementAtOrDefault(1);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Arrange appiosln file
            var appioslnPath = Path.Combine(solutionName + Constants.FileExtension.Appiosln);

            _fileSystemMock.Setup(x => x.CombinePaths(solutionName + Constants.FileExtension.Appiosln)).Returns(appioslnPath);
            _fileSystemMock.Setup(x => x.FileExists(appioslnPath)).Returns(false);


            // Act
            var commandResult = _objectUnderTest.Execute(inputParams);


            // Assert
            Assert.IsFalse(commandResult.Success);
            Assert.IsNotNull(commandResult.OutputMessages);
            var firstMessageLine = commandResult.OutputMessages.FirstOrDefault();

            AppioLogger.RemoveListener(loggerListenerMock.Object);
            Assert.AreEqual(string.Format(OutputText.SlnAppioslnNotFound, appioslnPath), firstMessageLine.Key);
            Assert.AreEqual(string.Empty, firstMessageLine.Value);
            _fileSystemMock.Verify(x => x.FileExists(appioslnPath), Times.Once);
        }
        public void CommandFactoryFallbackCommand_Should_ReturnFailure()
        {
            // Arrange
            const string defaultCommandName = "any-name";
            var          mockCommand        = new Mock <ICommand <object> >();

            mockCommand.Setup(x => x.Name).Returns(defaultCommandName);

            var commandArrayMock   = new ICommand <object>[] { mockCommand.Object };
            var objectUnderTest    = new CommandFactory <object>(commandArrayMock, defaultCommandName);
            var command            = objectUnderTest.GetCommand("any-name2");
            var loggerListenerMock = new Mock <ILoggerListener>();

            loggerListenerMock.Setup(x => x.Warn(LoggingText.UnknownCommandCalled));
            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Act
            var commandResult = command.Execute(new string[0]);

            // Assert
            Assert.IsFalse(commandResult.Success);
            Assert.AreEqual(Constants.CommandResults.Failure, commandResult.OutputMessages.First().Key);
            loggerListenerMock.Verify(x => x.Warn(LoggingText.UnknownCommandCalled), Times.Once);
            AppioLogger.RemoveListener(loggerListenerMock.Object);
        }
        public void DeployStrategy_ShouldFail_DueToFailingExecutableCalls([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrange
            var projectDirectoryName    = inputParams.ElementAt(0);
            var projectPublishDirectory = Path.Combine(projectDirectoryName, Constants.DirectoryName.Publish);

            var fileSystemMock = new Mock <IFileSystem>();

            fileSystemMock.Setup(x => x.CallExecutable(Constants.ExecutableName.CreateDebianInstaller, _deployDirectory, It.IsAny <string>())).Returns(false);
            fileSystemMock.Setup(x => x.CombinePaths(projectDirectoryName, Constants.DirectoryName.Publish)).Returns(projectPublishDirectory);
            fileSystemMock.Setup(x => x.CombinePaths(projectPublishDirectory, Constants.ExecutableName.AppClient)).Returns(_appClientPublishLocation);
            fileSystemMock.Setup(x => x.CombinePaths(projectPublishDirectory, Constants.ExecutableName.AppServer)).Returns(_appServerPublishLocation);
            fileSystemMock.Setup(x => x.CombinePaths(projectDirectoryName, Constants.DirectoryName.Deploy)).Returns(_deployDirectory);
            fileSystemMock.Setup(x => x.CombinePaths(_deployDirectory, Constants.ExecutableName.AppClient)).Returns(_appClientDeployLocation);
            fileSystemMock.Setup(x => x.CombinePaths(_deployDirectory, Constants.ExecutableName.AppServer)).Returns(_appServerDeployLocation);
            fileSystemMock.Setup(x => x.FileExists(_appClientPublishLocation)).Returns(true);
            fileSystemMock.Setup(x => x.FileExists(_appServerPublishLocation)).Returns(true);

            var buildStrategy      = new DeployNameStrategy(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[] { projectDirectoryName });

            // Assert
            Assert.IsFalse(strategyResult.Success);
            Assert.AreEqual(string.Format(OutputText.OpcuaappDeployWithNameFailure, projectDirectoryName), strategyResult.OutputMessages.First().Key);

            loggerListenerMock.Verify(y => y.Warn(LoggingText.CreateDebianInstallerFails), Times.Once);
            AppioLogger.RemoveListener(loggerListenerMock.Object);
        }
        public void FailOnBuildingNotExisitingProject([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrange
            var solutionName = inputParams.ElementAtOrDefault(1);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            _commandMock.Setup(x => x.Execute(It.IsAny <string[]>())).Returns(new CommandResult(false, new MessageLines()));

            // Arrange appiosln file
            var appioslnPath = Path.Combine(solutionName + Constants.FileExtension.Appiosln);

            _fileSystemMock.Setup(x => x.CombinePaths(solutionName + Constants.FileExtension.Appiosln)).Returns(appioslnPath);
            _fileSystemMock.Setup(x => x.FileExists(appioslnPath)).Returns(true);

            var solutionFullName = Path.Combine(solutionName + Constants.FileExtension.Appiosln);

            using (Stream slnMemoryStream = new MemoryStream(Encoding.ASCII.GetBytes(_sampleAppioslnContentWithOneProject)))
                using (var appioprojMemoryStream = new MemoryStream(Encoding.ASCII.GetBytes(_sampleOpcuaClientAppContent)))
                {
                    _fileSystemMock.Setup(x => x.ReadFile(solutionFullName)).Returns(slnMemoryStream);

                    // Act
                    var commandResult = _objectUnderTest.Execute(inputParams);

                    // Assert
                    Assert.IsFalse(commandResult.Success);
                    Assert.IsNotNull(commandResult.OutputMessages);
                    var firstMessageLine = commandResult.OutputMessages.FirstOrDefault();
                    AppioLogger.RemoveListener(loggerListenerMock.Object);
                }
        }
        public void HelpStrategy_Should_WriteHelpTextWithOptions()
        {
            // Arrange help data
            var helpData = new HelpData
            {
                CommandName       = sampleCommandName,
                HelpTextFirstLine = { { sampleFirstLineText, string.Empty } },
                Options           = { { sampleOption, sampleOptionDescription } },
                HelpTextLastLine  = { { string.Empty, sampleLastLineText } },
                LogMessage        = sampleLogMessage,
                HelpText          = sampleHelpText,
            };

            AppioLogger.RegisterListener(_loggerListenerMock.Object);

            var helpStrategy = new HelpStrategy <object>(helpData);

            helpStrategy.CommandFactory = _factoryMock.Object;

            // Act
            var strategyResult = helpStrategy.Execute(new string[] { });

            // Assert
            Assert.IsTrue(strategyResult.Success);
            Assert.IsNotNull(strategyResult.OutputMessages);

            Assert.IsTrue(strategyResult.OutputMessages.Contains(new KeyValuePair <string, string>(sampleFirstLineText, string.Empty)));
            Assert.IsTrue(strategyResult.OutputMessages.Contains(new KeyValuePair <string, string>("Options:", string.Empty)));
            Assert.IsTrue(strategyResult.OutputMessages.Contains(new KeyValuePair <string, string>(sampleOption, sampleOptionDescription)));
            Assert.IsTrue(strategyResult.OutputMessages.Contains(new KeyValuePair <string, string>(string.Empty, sampleLastLineText)));

            _loggerListenerMock.Verify(x => x.Info(sampleLogMessage), Times.Once);
            AppioLogger.RemoveListener(_loggerListenerMock.Object);
        }
        public void FailOnAppioslnDeserialization([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrage
            var solutionName = inputParams.ElementAtOrDefault(1);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Arrange appiosln file
            var appioslnPath = Path.Combine(solutionName + Constants.FileExtension.Appiosln);

            _fileSystemMock.Setup(x => x.CombinePaths(solutionName + Constants.FileExtension.Appiosln)).Returns(appioslnPath);
            _fileSystemMock.Setup(x => x.FileExists(appioslnPath)).Returns(true);

            var solutionFullName = Path.Combine(solutionName + Constants.FileExtension.Appiosln);

            using (Stream slnMemoryStream = new MemoryStream(Encoding.ASCII.GetBytes(string.Empty)))
            {
                _fileSystemMock.Setup(x => x.ReadFile(solutionFullName)).Returns(slnMemoryStream);

                // Act
                var commandResult = _objectUnderTest.Execute(inputParams);

                // Assert
                Assert.IsFalse(commandResult.Success);
                Assert.IsNotNull(commandResult.OutputMessages);
                var firstMessageLine = commandResult.OutputMessages.FirstOrDefault();
                AppioLogger.RemoveListener(loggerListenerMock.Object);
                Assert.AreEqual(string.Format(OutputText.SlnCouldntDeserliazeSln, solutionName), firstMessageLine.Key);
                Assert.AreEqual(string.Empty, firstMessageLine.Value);
                _fileSystemMock.Verify(x => x.ReadFile(solutionFullName), Times.Once);
            }
        }
Exemple #12
0
        public void Fail_OnGeneratingNodesetWithFailingPythonScript()
        {
            // Arrange file system
            var modelPath               = Path.Combine(_projectName, Constants.DirectoryName.Models, _modelFullName);
            var srcDirectory            = Path.Combine(_projectName, Constants.DirectoryName.SourceCode, Constants.DirectoryName.ServerApp);
            var modelName               = Path.GetFileNameWithoutExtension(_modelFullName);
            var modelSourcePath         = Path.Combine(Constants.DirectoryName.Models, _modelFullName);
            var modelSourceRelativePath = @"../../" + modelSourcePath;
            var modelTargetFullPath     = Path.Combine(Constants.DirectoryName.InformationModels, modelName.ToLower());

            _fileSystemMock.Setup(x => x.GetExtension(_modelFullName)).Returns(Constants.FileExtension.InformationModel);
            _fileSystemMock.Setup(x => x.CombinePaths(_projectName, Constants.DirectoryName.Models, _modelFullName)).Returns(modelPath);
            _fileSystemMock.Setup(x => x.FileExists(modelPath)).Returns(true);
            _modelValidator.Setup(x => x.Validate(modelPath, Resources.Resources.UANodeSetXsdFileName)).Returns(true);
            _fileSystemMock.Setup(x => x.CombinePaths(_projectName, Constants.DirectoryName.SourceCode, Constants.DirectoryName.ServerApp)).Returns(srcDirectory);
            _fileSystemMock.Setup(x => x.GetFileNameWithoutExtension(_modelFullName)).Returns(modelName);
            _fileSystemMock.Setup(x => x.CombinePaths(Constants.DirectoryName.InformationModels, modelName.ToLower())).Returns(modelTargetFullPath);
            _fileSystemMock.Setup(x => x.CombinePaths(Constants.DirectoryName.Models, _modelFullName)).Returns(modelSourcePath);
            _fileSystemMock.Setup(x => x.CallExecutable(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(false);

            // Arrange logger listener
            _loggerListenerMock.Setup(listener => listener.Warn(LoggingText.NodesetCompilerExecutableFails)).Callback(delegate { _loggerWroteOut = true; });
            AppioLogger.RegisterListener(_loggerListenerMock.Object);

            // Act
            var result = _objectUnderTest.GenerateNodesetSourceCodeFiles(_projectName, _defaultModelData, new List <RequiredModelsData>());

            // Assert
            Assert.IsFalse(result);
            Assert.IsTrue(_loggerWroteOut);
            Assert.AreEqual(string.Format(OutputText.GenerateInformationModelFailure, _projectName, _modelFullName), _objectUnderTest.GetOutputMessage());
            _fileSystemMock.Verify(x => x.CallExecutable(Constants.ExecutableName.PythonScript, srcDirectory, It.IsAny <string>()), Times.Once);
        }
Exemple #13
0
        public void PublishNameStrategy_Should_IgnoreNotExistingBuildFiles()
        {
            const string applicationName     = "any-name";
            const string buildDirectory      = "build";
            const string publishDirectory    = "publish";
            const string clientAppSourcePath = "client-source";
            const string serverAppSourcePath = "server-source";
            const string clientAppTargetPath = "client-target";
            const string serverAppTargetPath = "client-target";

            var loggerListenerMock = new Mock <ILoggerListener>();

            loggerListenerMock.Setup(x => x.Warn(LoggingText.MissingBuiltOpcuaAppFiles));
            AppioLogger.RegisterListener(loggerListenerMock.Object);

            var fileSystemMock = new Mock <IFileSystem>();

            fileSystemMock.Setup(x => x.CombinePaths(applicationName, Constants.DirectoryName.Publish)).Returns(publishDirectory);
            fileSystemMock.Setup(x => x.CombinePaths(applicationName, Constants.DirectoryName.MesonBuild)).Returns(buildDirectory);
            fileSystemMock.Setup(x => x.CombinePaths(buildDirectory, Constants.ExecutableName.AppClient)).Returns(clientAppSourcePath);
            fileSystemMock.Setup(x => x.CombinePaths(buildDirectory, Constants.ExecutableName.AppServer)).Returns(serverAppSourcePath);
            fileSystemMock.Setup(x => x.CombinePaths(publishDirectory, Constants.ExecutableName.AppClient)).Returns(clientAppTargetPath);
            fileSystemMock.Setup(x => x.CombinePaths(publishDirectory, Constants.ExecutableName.AppServer)).Returns(serverAppTargetPath);
            var objectUnderTest = new PublishNameStrategy(string.Empty, fileSystemMock.Object);

            // Act
            var result = objectUnderTest.Execute(new[] { applicationName });

            // Assert
            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.OutputMessages);
            Assert.AreEqual(string.Format(OutputText.OpcuaappPublishFailureMissingExecutables, applicationName), result.OutputMessages.First().Key);
            loggerListenerMock.Verify(x => x.Warn(LoggingText.MissingBuiltOpcuaAppFiles), Times.Once);
            AppioLogger.RemoveListener(loggerListenerMock.Object);
        }
Exemple #14
0
        public void FailOnUnknownServerParametar([ValueSource(nameof(InvalidInputs_UnknownServerParam))] string[] inputParams)
        {
            // Arrange
            var clientName     = inputParams.ElementAt(1);
            var serverNameFlag = inputParams.ElementAtOrDefault(2);

            // Arrange client file
            var appioprojectPath = Path.Combine(clientName, clientName + Constants.FileExtension.Appioproject);

            _fileSystemMock.Setup(x => x.CombinePaths(clientName, clientName + Constants.FileExtension.Appioproject)).Returns(appioprojectPath);
            _fileSystemMock.Setup(x => x.FileExists(appioprojectPath)).Returns(true);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Act
            var commandResult = _objectUnderTest.Execute(inputParams);

            // Assert
            Assert.IsFalse(commandResult.Success);
            Assert.IsNotNull(commandResult.OutputMessages);
            var firstMessageLine = commandResult.OutputMessages.FirstOrDefault();

            AppioLogger.RemoveListener(loggerListenerMock.Object);
            loggerListenerMock.Verify(x => x.Warn(It.IsAny <string>()), Times.Once);
            Assert.AreEqual(string.Empty, firstMessageLine.Value);
        }
        public void PassThroughEmptySolution([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrange
            var solutionName = inputParams.ElementAtOrDefault(1);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Arrange appiosln file
            var appioslnPath = Path.Combine(solutionName + Constants.FileExtension.Appiosln);

            _fileSystemMock.Setup(x => x.CombinePaths(solutionName + Constants.FileExtension.Appiosln)).Returns(appioslnPath);
            _fileSystemMock.Setup(x => x.FileExists(appioslnPath)).Returns(true);

            var solutionFullName = Path.Combine(solutionName + Constants.FileExtension.Appiosln);

            using (var slnMemoryStream = new MemoryStream(Encoding.ASCII.GetBytes(_defaultAppioslnContent)))
            {
                _fileSystemMock.Setup(x => x.ReadFile(solutionFullName)).Returns(slnMemoryStream);

                // Act
                var commandResult = _objectUnderTest.Execute(inputParams);

                // Assert
                Assert.IsTrue(commandResult.Success);
                Assert.IsNotNull(commandResult.OutputMessages);
                var firstMessageLine = commandResult.OutputMessages.FirstOrDefault();
                AppioLogger.RemoveListener(loggerListenerMock.Object);
                Assert.AreEqual(_operationData.SuccessOutputMessage, firstMessageLine.Key);
                Assert.AreEqual(string.Empty, firstMessageLine.Value);
            }
        }
Exemple #16
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);
        }
 public void Setup()
 {
     _fileSystemMock  = new Mock <IFileSystem>();
     _certGenMock     = new Mock <AbstractCertificateGenerator>();
     _objectUnderTest = new GenerateCertificateStrategy(_fileSystemMock.Object, _certGenMock.Object);
     _listenerMock    = new Mock <ILoggerListener>();
     AppioLogger.RegisterListener(_listenerMock.Object);
 }
        public void Setup()
        {
            _fileSystemMock  = new Mock <IFileSystem>();
            _objectUnderTest = new ImportCertificateStrategy(_fileSystemMock.Object);

            _loggerListenerMock = new Mock <ILoggerListener>();
            AppioLogger.RegisterListener(_loggerListenerMock.Object);
        }
Exemple #19
0
 public void SetupTest()
 {
     _defaultModelData   = new ModelData(_modelFullName, null, _namespaceVariable, null);
     _fileSystemMock     = new Mock <IFileSystem>();
     _modelValidator     = new Mock <IModelValidator>();
     _loggerListenerMock = new Mock <ILoggerListener>();
     _loggerWroteOut     = false;
     _objectUnderTest    = new NodesetGenerator(_fileSystemMock.Object, _modelValidator.Object);
     AppioLogger.RegisterListener(_loggerListenerMock.Object);
 }
Exemple #20
0
        public void PublishNameStrategy_Should_PublishClientAndServerExecutablesOfClientServerApp()
        {
            // Arrange
            const string applicationName = "any-name";

            var loggerListenerMock = new Mock <ILoggerListener>();

            loggerListenerMock.Setup(x => x.Info(LoggingText.OpcuaappPublishedSuccess));
            AppioLogger.RegisterListener(loggerListenerMock.Object);

            var fileSystemMock = new Mock <IFileSystem>();

            var publishDirectory = Path.Combine(applicationName, Constants.DirectoryName.Publish);

            fileSystemMock.Setup(x => x.CombinePaths(applicationName, Constants.DirectoryName.Publish)).Returns(publishDirectory);

            var buildDirectory = Path.Combine(applicationName, Constants.DirectoryName.MesonBuild);

            fileSystemMock.Setup(x => x.CombinePaths(applicationName, Constants.DirectoryName.MesonBuild)).Returns(buildDirectory);

            var clientAppSourcePath = Path.Combine(buildDirectory, Constants.ExecutableName.AppClient);

            fileSystemMock.Setup(x => x.CombinePaths(buildDirectory, Constants.ExecutableName.AppClient)).Returns(clientAppSourcePath);

            var serverAppSourcePath = Path.Combine(buildDirectory, Constants.ExecutableName.AppServer);

            fileSystemMock.Setup(x => x.CombinePaths(buildDirectory, Constants.ExecutableName.AppServer)).Returns(serverAppSourcePath);

            var clientAppTargetPath = Path.Combine(publishDirectory, Constants.ExecutableName.AppClient);

            fileSystemMock.Setup(x => x.CombinePaths(publishDirectory, Constants.ExecutableName.AppClient)).Returns(clientAppTargetPath);

            var serverAppTargetPath = Path.Combine(publishDirectory, Constants.ExecutableName.AppServer);

            fileSystemMock.Setup(x => x.CombinePaths(publishDirectory, Constants.ExecutableName.AppServer)).Returns(serverAppTargetPath);

            fileSystemMock.Setup(x => x.FileExists(clientAppSourcePath)).Returns(true);
            fileSystemMock.Setup(x => x.FileExists(serverAppSourcePath)).Returns(true);

            var objectUnderTest = new PublishNameStrategy(string.Empty, fileSystemMock.Object);

            // Act
            var result = objectUnderTest.Execute(new[] { applicationName });

            // Assert
            Assert.IsTrue(result.Success);
            Assert.IsNotNull(result.OutputMessages);
            Assert.AreEqual(string.Format(OutputText.OpcuaappPublishSuccess, applicationName), result.OutputMessages.First().Key);
            fileSystemMock.Verify(x => x.CreateDirectory(publishDirectory), Times.Once);
            fileSystemMock.Verify(x => x.CopyFile(clientAppSourcePath, clientAppTargetPath), Times.Once);
            fileSystemMock.Verify(x => x.CopyFile(serverAppSourcePath, serverAppTargetPath), Times.Once);
            loggerListenerMock.Verify(x => x.Info(LoggingText.OpcuaappPublishedSuccess), Times.Once);
            AppioLogger.RemoveListener(loggerListenerMock.Object);
        }
        public void SetUpTest()
        {
            _fileSystemMock     = new Mock <IFileSystem>();
            _modelValidator     = new Mock <IModelValidator>();
            _loggerListenerMock = new Mock <ILoggerListener>();
            _loggerWroteOut     = false;
            _commandName        = Constants.CommandName.Generate + " " + Constants.GenerateCommandOptions.Name;
            _nodesetGenerator   = new Mock <INodesetGenerator>();
            _strategy           = new GenerateInformationModelStrategy(Constants.GenerateCommandOptions.Name, _fileSystemMock.Object, _modelValidator.Object, _nodesetGenerator.Object);

            AppioLogger.RegisterListener(_loggerListenerMock.Object);
        }
        public void AddOpcuaappToNotEmptySln([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrange
            var solutionName = inputParams.ElementAtOrDefault(1);
            var opcuaappName = inputParams.ElementAtOrDefault(3);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Arrange appiosln file
            var appioslnPath = Path.Combine(solutionName + Constants.FileExtension.Appiosln);

            _fileSystemMock.Setup(x => x.CombinePaths(solutionName + Constants.FileExtension.Appiosln)).Returns(appioslnPath);
            _fileSystemMock.Setup(x => x.FileExists(appioslnPath)).Returns(true);

            var    solutionFullName = Path.Combine(solutionName + Constants.FileExtension.Appiosln);
            Stream slnMemoryStream  = new MemoryStream(Encoding.ASCII.GetBytes(_sampleAppioslnContent));

            _fileSystemMock.Setup(x => x.ReadFile(solutionFullName)).Returns(slnMemoryStream);

            // Arrange appioproj file
            var appioprojPath = Path.Combine(opcuaappName, opcuaappName + Constants.FileExtension.Appioproject);

            _fileSystemMock.Setup(x => x.CombinePaths(opcuaappName, opcuaappName + Constants.FileExtension.Appioproject)).Returns(appioprojPath);
            _fileSystemMock.Setup(x => x.FileExists(appioprojPath)).Returns(true);

            Stream opcuaappMemoryStream = new MemoryStream(Encoding.ASCII.GetBytes(_sampleOpcuaServerAppContent));

            _fileSystemMock.Setup(x => x.ReadFile(appioprojPath)).Returns(opcuaappMemoryStream);


            // Act
            var commandResult = _objectUnderTest.Execute(inputParams);


            // Assert
            Assert.IsTrue(commandResult.Success);
            Assert.IsNotNull(commandResult.OutputMessages);
            var firstMessageLine = commandResult.OutputMessages.FirstOrDefault();

            AppioLogger.RemoveListener(loggerListenerMock.Object);
            loggerListenerMock.Verify(x => x.Info(Resources.text.logging.LoggingText.SlnAddSuccess), Times.Once);
            Assert.AreEqual(string.Format(OutputText.SlnAddSuccess, opcuaappName, solutionName), firstMessageLine.Key);
            Assert.AreEqual(string.Empty, firstMessageLine.Value);
            _fileSystemMock.Verify(x => x.WriteFile(solutionFullName, It.IsAny <IEnumerable <string> >()), Times.Once);

            slnMemoryStream.Close();
            slnMemoryStream.Dispose();
            opcuaappMemoryStream.Close();
            opcuaappMemoryStream.Dispose();
        }
        public void NewOpcuaAppCommandStrategy_Should_GenerateBothClientServerCertificates([ValueSource(nameof(ValidInputs_ClientServerAppType))] string[] inputParam)
        {
            // Arrange
            var projectName = inputParam.ElementAtOrDefault(1);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            var          projectDirectory      = $"{projectName}";
            const string sourceCodeDirectory   = "source-directory";
            const string clientSourceDirectory = "client-source-directory";
            const string serverSourceDirectory = "server-source-directory";

            _fileSystemMock.Setup(x => x.CombinePaths(projectDirectory, Constants.DirectoryName.SourceCode)).Returns(sourceCodeDirectory);
            _fileSystemMock.Setup(x => x.CombinePaths(sourceCodeDirectory, Constants.DirectoryName.ClientApp)).Returns(clientSourceDirectory);
            _fileSystemMock.Setup(x => x.CombinePaths(sourceCodeDirectory, Constants.DirectoryName.ServerApp)).Returns(serverSourceDirectory);

            var          projectFileName              = $"{projectName}{Constants.FileExtension.Appioproject}";
            const string projectFilePath              = "project-file-path";
            const string clientDirectoryPath          = "client-directory-path";
            const string serverDirectoryPath          = "server-directory-path";
            const string mesonBuildFilePath           = "meson-build-file-path";
            const string clientMainC                  = "client-main-c-file";
            const string serverMainC                  = "server-main-c-file";
            const string serverMesonBuild             = "server-meson-build-file";
            const string serverloadInformationModelsC = "server-loadInformationModels-c-file";
            const string serverconstantsH             = "constants-h-file";
            const string serverMainCallbacksC         = "mainCallbacks-c-file";
            const string modelsDirectory              = "models";

            _fileSystemMock.Setup(x => x.CombinePaths(projectDirectory, projectFileName)).Returns(projectFilePath);
            _fileSystemMock.Setup(x => x.CombinePaths(projectDirectory, Constants.DirectoryName.ServerApp)).Returns(serverDirectoryPath);
            _fileSystemMock.Setup(x => x.CombinePaths(projectDirectory, Constants.DirectoryName.ClientApp)).Returns(clientDirectoryPath);
            _fileSystemMock.Setup(x => x.CombinePaths(projectDirectory, Constants.FileName.SourceCode_meson_build)).Returns(mesonBuildFilePath);
            _fileSystemMock.Setup(x => x.CombinePaths(clientSourceDirectory, Constants.FileName.SourceCode_main_c)).Returns(clientMainC);
            _fileSystemMock.Setup(x => x.CombinePaths(serverSourceDirectory, Constants.FileName.SourceCode_main_c)).Returns(serverMainC);
            _fileSystemMock.Setup(x => x.CombinePaths(serverSourceDirectory, Constants.FileName.SourceCode_meson_build)).Returns(serverMesonBuild);
            _fileSystemMock.Setup(x => x.CombinePaths(serverSourceDirectory, Constants.FileName.SourceCode_loadInformationModels_c)).Returns(serverloadInformationModelsC);
            _fileSystemMock.Setup(x => x.CombinePaths(serverSourceDirectory, Constants.FileName.SourceCode_constants_h)).Returns(serverconstantsH);
            _fileSystemMock.Setup(x => x.CombinePaths(serverSourceDirectory, Constants.FileName.SourceCode_mainCallbacks_c)).Returns(serverMainCallbacksC);
            _fileSystemMock.Setup(x => x.CombinePaths(projectDirectory, Constants.DirectoryName.Models)).Returns(modelsDirectory);

            // Act
            var result = _objectUnderTest.Execute(inputParam);

            // Assert
            Assert.IsTrue(result.Success);
            _certGenMock.Verify(x => x.Generate(projectName, Constants.FileName.ClientCryptoPrefix), Times.Once);
            _certGenMock.Verify(x => x.Generate(projectName, Constants.FileName.ServerCryptoPrefix), Times.Once);
        }
        public void Should_Register_One_LoggerListener()
        {
            // Follow the AAA pattern
            // Arrange: Set up data for the test.
            var loggerListenerMock = new Mock <ILoggerListener>();

            // Act: Perform the action of the test.
            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Assert: Verify the result of the test.
            Assert.AreEqual(AppioLogger.LoggerListeners.Count(), 1);

            CleanupAppioLogger();
        }
Exemple #25
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);
                    }
        }
Exemple #26
0
        public void Success_OnImportingSampleModel([ValueSource(nameof(ValidInputsLoadSample))] string[] inputParams)
        {
            // Arrange
            var infoWrittenOut    = false;
            var projectName       = inputParams.ElementAtOrDefault(1);
            var modelsDirectory   = projectName + "\\" + "models";
            var appioprojFilePath = projectName + "\\" + projectName + ".appioproj";
            var loadedModel       = "anyModelName";
            var loadedTypes       = "anyTypesName";
            var sampleModelName   = "DiNodeset.xml";
            var sampleTypesName   = "DiTypes.bsd";
            var modelTargetPath   = modelsDirectory + "\\" + sampleModelName;
            var typesTargetPath   = modelsDirectory + "\\" + sampleTypesName;

            _fileSystemMock.Setup(x => x.DirectoryExists(projectName)).Returns(true);
            _fileSystemMock.Setup(x => x.CombinePaths(projectName, projectName + Constants.FileExtension.Appioproject)).Returns(appioprojFilePath);
            _fileSystemMock.Setup(x => x.CombinePaths(projectName, Constants.DirectoryName.Models)).Returns(modelsDirectory);
            _fileSystemMock.Setup(x => x.LoadTemplateFile(Resources.Resources.SampleInformationModelFileName)).Returns(loadedModel);
            _fileSystemMock.Setup(x => x.CombinePaths(modelsDirectory, sampleModelName)).Returns(modelTargetPath);
            _fileSystemMock.Setup(x => x.LoadTemplateFile(Resources.Resources.SampleInformationModelTypesFileName)).Returns(loadedTypes);
            _fileSystemMock.Setup(x => x.CombinePaths(modelsDirectory, sampleTypesName)).Returns(typesTargetPath);

            var loggerListenerMock = new Mock <ILoggerListener>();

            loggerListenerMock.Setup(listener => listener.Info(string.Format(LoggingText.ImportInforamtionModelCommandSuccess, sampleModelName))).Callback(delegate { infoWrittenOut = true; });
            AppioLogger.RegisterListener(loggerListenerMock.Object);


            using (var serverAppioprojFileStream = new MemoryStream(Encoding.ASCII.GetBytes(_defaultOpcuaServerAppContent)))
                using (var nodesetFileStream = new MemoryStream(Encoding.ASCII.GetBytes(_sampleNodesetContent)))
                {
                    _fileSystemMock.Setup(x => x.ReadFile(appioprojFilePath)).Returns(serverAppioprojFileStream);
                    _fileSystemMock.Setup(x => x.ReadFile(modelTargetPath)).Returns(nodesetFileStream);

                    // Act
                    var result = _objectUnderTest.Execute(inputParams);

                    // Assert
                    Assert.IsTrue(result.Success);
                    Assert.IsTrue(infoWrittenOut);
                    Assert.AreEqual(string.Format(OutputText.ImportSampleInformationModelSuccess, sampleModelName), result.OutputMessages.First().Key);
                    _fileSystemMock.Verify(x => x.CreateFile(modelTargetPath, loadedModel), Times.Once);
                    _fileSystemMock.Verify(x => x.CreateFile(typesTargetPath, loadedTypes), Times.Once);
                    _fileSystemMock.Verify(x => x.ReadFile(appioprojFilePath), Times.Once);
                    _fileSystemMock.Verify(x => x.WriteFile(appioprojFilePath, It.IsAny <IEnumerable <string> >()));
                    AppioLogger.RemoveListener(loggerListenerMock.Object);
                }
        }
        public void FailOnClientDeserialization([ValueSource(nameof(ValidInputs))] string[] inputParams)
        {
            // Arrage
            var serverName = inputParams.ElementAtOrDefault(3);
            var clientName = inputParams.ElementAtOrDefault(1);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            var appioClientPath = Path.Combine(clientName, clientName + Constants.FileExtension.Appioproject);

            _fileSystemMock.Setup(x => x.CombinePaths(clientName, clientName + Constants.FileExtension.Appioproject)).Returns(appioClientPath);
            _fileSystemMock.Setup(x => x.FileExists(appioClientPath)).Returns(true);
            var appioServerPath = Path.Combine(serverName, serverName + Constants.FileExtension.Appioproject);

            _fileSystemMock.Setup(x => x.CombinePaths(serverName, serverName + Constants.FileExtension.Appioproject)).Returns(appioServerPath);
            _fileSystemMock.Setup(x => x.FileExists(appioServerPath)).Returns(true);

            Stream emptyMemoryStream = new MemoryStream(Encoding.ASCII.GetBytes(string.Empty));

            _fileSystemMock.Setup(x => x.ReadFile(appioClientPath)).Returns(emptyMemoryStream);
            Stream serverMemoryStream = new MemoryStream(Encoding.ASCII.GetBytes(_sampleOpcuaServerAppContent));

            _fileSystemMock.Setup(x => x.ReadFile(appioServerPath)).Returns(serverMemoryStream);


            // Act
            var commandResult = _objectUnderTest.Execute(inputParams);


            // Assert
            Assert.IsFalse(commandResult.Success);
            Assert.IsNotNull(commandResult.OutputMessages);
            var firstMessageLine = commandResult.OutputMessages.FirstOrDefault();

            AppioLogger.RemoveListener(loggerListenerMock.Object);
            loggerListenerMock.Verify(x => x.Warn(Resources.text.logging.LoggingText.ReferenceCouldntDeserliazeClient), Times.Once);
            Assert.AreEqual(string.Format(OutputText.ReferenceCouldntDeserliazeClient, appioClientPath), firstMessageLine.Key);
            Assert.AreEqual(string.Empty, firstMessageLine.Value);
            _fileSystemMock.Verify(x => x.ReadFile(appioClientPath), Times.Once);

            emptyMemoryStream.Close();
            emptyMemoryStream.Dispose();
            serverMemoryStream.Close();
            serverMemoryStream.Dispose();
        }
        public void NewOpcuaAppCommandStrategy_Should_FailOnInvalidUrlParameter([ValueSource(nameof(InvalidInputs_UnknownUrlParam))] string[] inputParam)
        {
            // Arrange
            var urlFlag = inputParam.ElementAtOrDefault(4);

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Act
            var result = _objectUnderTest.Execute(inputParam);

            // Assert
            Assert.IsFalse(result.Success);
            AppioLogger.RemoveListener(loggerListenerMock.Object);
            loggerListenerMock.Verify(x => x.Warn(string.Format(LoggingText.UnknownParameterProvided, "new opcuaapp")), Times.Once);
        }
Exemple #29
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);
                    }
        }
Exemple #30
0
        public void CleanNameStrategy_Should_IgnoreInvalidParameters([ValueSource(nameof(InvalidInputs))] string[] inputParams)
        {
            // Arrange

            var loggerListenerMock = new Mock <ILoggerListener>();

            AppioLogger.RegisterListener(loggerListenerMock.Object);

            // Act
            var result = _objectUnderTest.Execute(inputParams);

            // Assert
            AppioLogger.RemoveListener(loggerListenerMock.Object);
            loggerListenerMock.Verify(x => x.Info(Resources.text.logging.LoggingText.CleanFailure), Times.Once);
            Assert.IsFalse(result.Success);
            Assert.AreEqual(OutputText.OpcuaappCleanFailure, result.OutputMessages.First().Key);
        }