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 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 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 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 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); }
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); } }
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 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 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); }
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 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 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); } }
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 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 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 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 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 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); } }
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); }
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); }
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); } }
public void Fail_OnWrongNameFlag([ValueSource(nameof(InvalidInputsInvalidNameArgument))] string[] inputParams) { // Arrange var warnWrittenOut = false; var loggerListenerMock = new Mock <ILoggerListener>(); loggerListenerMock.Setup(listener => listener.Warn(It.IsAny <string>())).Callback(delegate { warnWrittenOut = true; }); AppioLogger.RegisterListener(loggerListenerMock.Object); // Act var result = _objectUnderTest.Execute(inputParams); // Assert Assert.IsTrue(warnWrittenOut); Assert.IsFalse(result.Success); AppioLogger.RemoveListener(loggerListenerMock.Object); }
public void NewOpcuaAppCommandStrategy_Should_FailOnInvalidPortValue([ValueSource(nameof(InvalidInputs_UnknownPortValue))] string[] inputParam) { // Arrange var port = inputParam.ElementAtOrDefault(7); var loggerListenerMock = new Mock <ILoggerListener>(); AppioLogger.RegisterListener(loggerListenerMock.Object); // Act var result = _objectUnderTest.Execute(inputParam); // Assert Assert.IsFalse(result.Success); Assert.AreEqual(string.Format(OutputText.NewOpcuaappCommandFailureInvalidServerPort, port), result.OutputMessages.First().Key); AppioLogger.RemoveListener(loggerListenerMock.Object); loggerListenerMock.Verify(x => x.Warn(LoggingText.InvalidServerPort), Times.Once); }
public void Success_OnImportingModelToClientServer([ValueSource(nameof(ValidInputs))] string[] inputParams) { // Arrange var infoWrittenOut = false; var projectDirectory = $"{inputParams.ElementAt(1)}"; var modelsDirectory = "models"; var modelFilePath = $"{inputParams.ElementAt(3)}"; var modelTargetPath = projectDirectory + "\\" + _modelName; var appioprojFilePath = Path.Combine(projectDirectory, projectDirectory + Constants.FileExtension.Appioproject); _fileSystemMock.Setup(x => x.FileExists(modelFilePath)).Returns(true); _fileSystemMock.Setup(x => x.GetFileName(modelFilePath)).Returns(_modelName); _fileSystemMock.Setup(x => x.GetExtension(modelFilePath)).Returns(_validModelExtension); _fileSystemMock.Setup(x => x.CombinePaths(projectDirectory, Constants.DirectoryName.Models)).Returns(modelsDirectory); _fileSystemMock.Setup(x => x.CombinePaths(modelsDirectory, _modelName)).Returns(modelTargetPath); _fileSystemMock.Setup(x => x.DirectoryExists(projectDirectory)).Returns(true); _fileSystemMock.Setup(x => x.CombinePaths(projectDirectory, projectDirectory + Constants.FileExtension.Appioproject)).Returns(appioprojFilePath); _modelValidatorMock.Setup(x => x.Validate(modelFilePath, It.IsAny <string>())).Returns(true); using (var clientServerAppioprojFileStream = new MemoryStream(Encoding.ASCII.GetBytes(_defaultOpcuaClientServerAppContent))) using (var nodesetFileStream = new MemoryStream(Encoding.ASCII.GetBytes(_sampleNodesetContent))) { _fileSystemMock.Setup(x => x.ReadFile(appioprojFilePath)).Returns(clientServerAppioprojFileStream); _fileSystemMock.Setup(x => x.ReadFile(modelFilePath)).Returns(nodesetFileStream); var loggerListenerMock = new Mock <ILoggerListener>(); loggerListenerMock.Setup(listener => listener.Info(string.Format(LoggingText.ImportInforamtionModelCommandSuccess, modelFilePath))).Callback(delegate { infoWrittenOut = true; }); AppioLogger.RegisterListener(loggerListenerMock.Object); // Act var result = _objectUnderTest.Execute(inputParams); // Assert Assert.IsTrue(result.Success); Assert.IsTrue(infoWrittenOut); Assert.AreEqual(string.Format(OutputText.ImportInformationModelCommandSuccess, inputParams.ElementAt(3)), result.OutputMessages.First().Key); _fileSystemMock.Verify(x => x.CopyFile(modelFilePath, modelTargetPath), Times.Once); AppioLogger.RemoveListener(loggerListenerMock.Object); } }
public void Should_Register_And_Remove_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); var loggerCountAfterAdd = AppioLogger.LoggerListeners.Count(); AppioLogger.RemoveListener(loggerListenerMock.Object); var loggerCountAfterRemove = AppioLogger.LoggerListeners.Count(); // Assert: Verify the result of the test. Assert.AreEqual(loggerCountAfterAdd, 1); Assert.AreEqual(loggerCountAfterRemove, 0); CleanupAppioLogger(); }
public void ShouldExecuteStrategy_Fail_MissingParameter([ValueSource(nameof(InvalidInputs))] string[] inputParams) { // Arrange var fileSystemMock = new Mock <IFileSystem>(); var loggerListenerMock = new Mock <ILoggerListener>(); loggerListenerMock.Setup(y => y.Warn(It.IsAny <string>())); AppioLogger.RegisterListener(loggerListenerMock.Object); var deployStrategy = new DeployNameStrategy(string.Empty, fileSystemMock.Object); // Act var strategyResult = deployStrategy.Execute(inputParams); // Assert Assert.IsFalse(strategyResult.Success); Assert.AreEqual(OutputText.OpcuaappDeployFailure, strategyResult.OutputMessages.First().Key); Assert.AreEqual(string.Empty, strategyResult.OutputMessages.First().Value); loggerListenerMock.Verify(y => y.Warn(It.IsAny <string>()), Times.Once); AppioLogger.RemoveListener(loggerListenerMock.Object); }
public void CleanNameStrategy_Should_IgnoreNotExistingDirectory([ValueSource(nameof(ValidInputs))] string[] inputParams) { // Arrange var projectName = inputParams.ElementAt(0); _fileSystemMock.Setup(x => x.DirectoryExists(projectName)).Returns(false); 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); }
public void PublishNameStrategy_Should_IgnoreInvalidInputParams(string applicationName) { // Arrange var fileSystemMock = new Mock <IFileSystem>(); var objectUnderTest = new PublishNameStrategy(string.Empty, fileSystemMock.Object); var loggerListenerMock = new Mock <ILoggerListener>(); loggerListenerMock.Setup(x => x.Warn(LoggingText.EmptyOpcuaappName)); AppioLogger.RegisterListener(loggerListenerMock.Object); // Act var result = objectUnderTest.Execute(new[] { applicationName }); // Assert Assert.IsFalse(result.Success); Assert.IsNotNull(result.OutputMessages); Assert.AreEqual(OutputText.OpcuaappPublishFailure, result.OutputMessages.First().Key); loggerListenerMock.Verify(x => x.Warn(LoggingText.EmptyOpcuaappName), Times.Once); AppioLogger.RemoveListener(loggerListenerMock.Object); }
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); }