public async void CreateAsyncTest_ConditionWithUnquotedChoiceLiteral(string templateConfig, string expectedResult) { // // Template content preparation // string sourceSnippet = @" //#if( ChoiceParam == FirstChoice ) FIRST //#elseif (ChoiceParam == SecondChoice ) SECOND //#elseif (ChoiceParam == ThirdChoice ) THIRD //#else UNKNOWN //#endif "; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, templateConfig); //content templateSourceFiles.Add("sourcFile", sourceSnippet); // // Dependencies preparation and mounting // IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint?sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); SimpleConfigModel configModel = SimpleConfigModel.FromJObject(JObject.Parse(templateConfig)); IRunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, rpg, configModel, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); IParameterSet parameters = new ParameterSet(runnableConfig); ITemplateParameter choiceParameter; Assert.True(parameters.TryGetParameterDefinition("ChoiceParam", out choiceParameter), "ChoiceParam expected to be extracted from template config"); parameters.ResolvedValues[choiceParameter] = "SecondChoice"; IDirectory sourceDir = sourceMountPoint !.DirectoryInfo("/") !; // // Running the actual scenario: template files processing and generating output (including macros processing) // await rpg.CreateAsync(environment, runnableConfig, sourceDir, parameters, targetDir, CancellationToken.None); // // Veryfying the outputs // string resultContent = environment.Host.FileSystem.ReadAllText(Path.Combine(targetDir, "sourcFile")).Trim(); Assert.Equal(expectedResult, resultContent); }
public void CreateEvents_AreQueued_WhenFilesAreCreatedInOneFolder(int numOfFiles, int expectedValue) { _manager.Monitor(_folders); TestFileSystemHelper.CreateDummyFiles(_folders[0].Path, numOfFiles); AssertQueueItemCount(expectedValue, item => item.EventArgs.ChangeType == WatcherChangeTypes.Created); }
public void CreateEvents_AreQueued_WhenFilesAreCreatedInDifferntFolders(int numOfFiles, int numOfFolders, int expectedValue) { _manager.Monitor(_folders); Parallel.For(0, numOfFolders, i => TestFileSystemHelper.CreateDummyFiles(_folders[i].Path, numOfFiles)); AssertQueueItemCount(expectedValue, item => item.EventArgs.ChangeType == WatcherChangeTypes.Created); }
public void BeforeEachTest() { _manager = new FileMonitorManager( Mock.Of <IFileSystemEventPoller>(p => p.DisposeAsync() == Task.FromResult <object>(null)), LogManager.GetLogger(typeof(FileMonitorManager)) ); _folders = TestFileSystemHelper.CreateAndGetTestFolders(); }
public void ChangeEvents_AreQueued_WhenFilesAreChanged(int numOfFiles, int expectedValue) { _manager.Monitor(_folders); var folder = _folders[0]; TestFileSystemHelper.CreateDummyFiles(folder.Path, numOfFiles); Parallel.ForEach(Directory.GetFiles(folder.Path), file => File.WriteAllText(file, "Hello World")); AssertQueueItemCount(expectedValue, item => item.EventArgs.ChangeType == WatcherChangeTypes.Changed); }
public void DeleteEvents_AreQueued_WhenFilesAreDeleted(int numOfFiles, int expectedValue) { _manager.Monitor(_folders); var folder = _folders[0]; TestFileSystemHelper.CreateDummyFiles(folder.Path, numOfFiles); foreach (var file in Directory.GetFiles(folder.Path)) { File.Delete(file); } AssertQueueItemCount(expectedValue, item => item.EventArgs.ChangeType == WatcherChangeTypes.Deleted); }
public void EventWorker_DeletesFileFromSvn_WhenFileIsDeletedFromDirectory() { _manager.Monitor(_testFolders); _manager.StartProcessing(); var folder = _testFolders[0]; var fileName = TestFileSystemHelper.MakeUniqueFileName("css"); DoAndWaitForWorker(() => TestFileSystemHelper.CreateFile(fileName, folder.Path)); var filePath = folder.Path + "\\" + fileName; DoAndWaitForWorker(() => File.Delete(filePath)); using (var client = new SvnClient()) { var status = GetSvnStatus(client, filePath); Assert.That(status, Is.EqualTo(SvnStatus.None)); } }
public void EventWorker_CommittsNewFileToSvn_WhenFileIsAdded() { _manager.Monitor(_testFolders); _manager.StartProcessing(); var folder = _testFolders[0]; var fileName = TestFileSystemHelper.MakeUniqueFileName("css"); using (var client = new SvnClient()) { SvnInfoEventArgs info; client.GetInfo(folder.RepositoryUrl, out info); var revisionBeforeAdd = info.Revision; DoAndWaitForWorker(() => TestFileSystemHelper.CreateFile(fileName, folder.Path)); client.GetInfo(folder.RepositoryUrl, out info); var revisionAfterAdd = info.Revision; Assert.That(revisionAfterAdd, Is.EqualTo(revisionBeforeAdd + 1)); } }
public void BeforeEachTest() { var sharpSvnClient = new SharpSvnClient(new NetworkCredential(), LogFor <SharpSvnClient>()); _workerWrapper = new TestEventWorkerWrapper(new FileSystemEventWorker(sharpSvnClient, LogFor <FileSystemEventWorker>()), LogFor <TestEventWorkerWrapper>()); _manager = new FileMonitorManager(new FileSystemEventPoller(_workerWrapper, LogFor <FileSystemEventPoller>()), LogFor <FileMonitorManager>()); var repositoryUrl = TestRepositoryHelper.RepositoryUrl; TestRepositoryHelper.SetupRepository(); //Create folders _testFolders = TestFileSystemHelper.CreateAndGetTestFolders(repositoryUrl); foreach (var folder in _testFolders) { TestRepositoryHelper.CreateDirectoryInRepository(folder.RepositoryUrl); if (!sharpSvnClient.SvnCheckOut(folder.RepositoryUrl, folder.Path)) { throw new InvalidOperationException("Failed to checkout " + folder.Path + "."); } } }
public void EventWorker_CommitsChangeToSvn_WhenFileIsChanged() { _manager.Monitor(_testFolders); _manager.StartProcessing(); var folder = _testFolders[0]; var fileName = TestFileSystemHelper.MakeUniqueFileName("css"); DoAndWaitForWorker(() => TestFileSystemHelper.CreateFile(fileName, folder.Path)); var filePath = folder.Path + "\\" + fileName; using (var client = new SvnClient()) { SvnInfoEventArgs info; client.GetInfo(folder.RepositoryUrl, out info); var revisionBeforeChange = info.Revision; DoAndWaitForWorker(() => File.AppendAllText(filePath, "Hello World")); client.GetInfo(folder.RepositoryUrl, out info); var revisionAfterChange = info.Revision; Assert.That(revisionAfterChange, Is.EqualTo(revisionBeforeChange + 1)); } }
public async void CreateAsyncTest_MultiChoiceParamJoining() { // // Template content preparation // string templateConfig = @" { ""identity"": ""test.template"", ""symbols"": { ""Platform"": { ""type"": ""parameter"", ""description"": ""The target framework for the project."", ""datatype"": ""choice"", ""allowMultipleValues"": true, ""choices"": [ { ""choice"": ""Windows"", ""description"": ""Windows Desktop"" }, { ""choice"": ""WindowsPhone"", ""description"": ""Windows Phone"" }, { ""choice"": ""MacOS"", ""description"": ""Macintosh computers"" }, { ""choice"": ""iOS"", ""description"": ""iOS mobile"" }, { ""choice"": ""android"", ""description"": ""android mobile"" }, { ""choice"": ""nix"", ""description"": ""Linux distributions"" } ], ""defaultValue"": ""MacOS|iOS"" }, ""joinedRename"": { ""type"": ""generated"", ""generator"": ""join"", ""replaces"": ""SupportedPlatforms"", ""parameters"": { ""symbols"": [ { ""type"": ""ref"", ""value"": ""Platform"" } ], ""separator"": "", "", ""removeEmptyValues"": true, } } } } "; string sourceSnippet = @" // This file is generated for platfrom: SupportedPlatforms "; string expectedSnippet = @" // This file is generated for platfrom: MacOS, iOS "; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, templateConfig); //content templateSourceFiles.Add("sourcFile", sourceSnippet); // // Dependencies preparation and mounting // IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint?sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); SimpleConfigModel configModel = SimpleConfigModel.FromJObject(JObject.Parse(templateConfig)); IRunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, rpg, configModel, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); IParameterSet parameters = new ParameterSet(runnableConfig); ITemplateParameter choiceParameter; Assert.True(parameters.TryGetParameterDefinition("Platform", out choiceParameter), "ChoiceParam expected to be extracted from template config"); parameters.ResolvedValues[choiceParameter] = new MultiValueParameter(new[] { "MacOS", "iOS" }); IDirectory sourceDir = sourceMountPoint !.DirectoryInfo("/") !; // // Running the actual scenario: template files processing and generating output (including macros processing) // await rpg.CreateAsync(environment, runnableConfig, sourceDir, parameters, targetDir, CancellationToken.None); // // Veryfying the outputs // string resultContent = environment.Host.FileSystem.ReadAllText(Path.Combine(targetDir, "sourcFile")); Assert.Equal(expectedSnippet, resultContent); }
public async void CreateAsyncTest_GuidsMacroProcessingCaseSensitivity() { // // Template content preparation // Guid inputTestGuid = new Guid("12aa8f4e-a4aa-4ac1-927c-94cb99485ef1"); string contentFileNamePrefix = "content - "; SimpleConfigModel config = new SimpleConfigModel() { Identity = "test", Guids = new List <Guid>() { inputTestGuid } }; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, config.ToJObject().ToString()); //content foreach (string guidFormat in GuidMacroConfig.DefaultFormats.Select(c => c.ToString())) { templateSourceFiles.Add(contentFileNamePrefix + guidFormat, inputTestGuid.ToString(guidFormat)); } // // Dependencies preparation and mounting // IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint? sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); IRunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, rpg, config, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); IParameterSet parameters = new ParameterSet(runnableConfig); IDirectory sourceDir = sourceMountPoint !.DirectoryInfo("/") !; // // Running the actual scenario: template files processing and generating output (including macros processing) // await rpg.CreateAsync(environment, runnableConfig, sourceDir, parameters, targetDir, CancellationToken.None); // // Veryfying the outputs // Guid expectedResultGuid = Guid.Empty; foreach (string guidFormat in GuidMacroConfig.DefaultFormats.Select(c => c.ToString())) { string resultContent = environment.Host.FileSystem.ReadAllText(Path.Combine(targetDir, contentFileNamePrefix + guidFormat)); Guid resultGuid; Assert.True( Guid.TryParseExact(resultContent, guidFormat, out resultGuid), $"Expected the result conent ({resultContent}) to be parseable by Guid format '{guidFormat}'"); if (expectedResultGuid == Guid.Empty) { expectedResultGuid = resultGuid; } else { Assert.Equal(expectedResultGuid, resultGuid); } } Assert.NotEqual(inputTestGuid, expectedResultGuid); }
public async void CreateAsyncTest_MultiChoiceParamReplacingAndCondition() { // // Template content preparation // string templateConfig = @" { ""identity"": ""test.template"", ""symbols"": { ""ChoiceParam"": { ""type"": ""parameter"", ""description"": ""sample switch"", ""datatype"": ""choice"", ""allowMultipleValues"": true, ""enableQuotelessLiterals"": true, ""choices"": [ { ""choice"": ""FirstChoice"", ""description"": ""First Sample Choice"" }, { ""choice"": ""SecondChoice"", ""description"": ""Second Sample Choice"" }, { ""choice"": ""ThirdChoice"", ""description"": ""Third Sample Choice"" } ], ""defaultValue"": ""ThirdChoice"", ""replaces"": ""REPLACE_VALUE"" } } } "; string sourceSnippet = @" MultiChoiceValue: REPLACE_VALUE //#if( ChoiceParam == FirstChoice ) FIRST //#endif //#if (ChoiceParam == SecondChoice ) SECOND //#endif //#if (ChoiceParam == ThirdChoice ) THIRD //#endif "; string expectedSnippet = @" MultiChoiceValue: SecondChoice|ThirdChoice SECOND THIRD "; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, templateConfig); //content templateSourceFiles.Add("sourcFile", sourceSnippet); // // Dependencies preparation and mounting // IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint?sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); SimpleConfigModel configModel = SimpleConfigModel.FromJObject(JObject.Parse(templateConfig)); IRunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, rpg, configModel, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); IParameterSet parameters = new ParameterSet(runnableConfig); ITemplateParameter choiceParameter; Assert.True(parameters.TryGetParameterDefinition("ChoiceParam", out choiceParameter), "ChoiceParam expected to be extracted from template config"); parameters.ResolvedValues[choiceParameter] = new MultiValueParameter(new[] { "SecondChoice", "ThirdChoice" }); IDirectory sourceDir = sourceMountPoint !.DirectoryInfo("/") !; // // Running the actual scenario: template files processing and generating output (including macros processing) // await rpg.CreateAsync(environment, runnableConfig, sourceDir, parameters, targetDir, CancellationToken.None); // // Veryfying the outputs // string resultContent = environment.Host.FileSystem.ReadAllText(Path.Combine(targetDir, "sourcFile")); Assert.Equal(expectedSnippet, resultContent); }
public void PerformTemplateValidation_ChoiceValuesValidation(string paramDefintion, bool isMultichoice, bool expectedToBeValid) { // // Template content preparation // Guid inputTestGuid = new Guid("12aa8f4e-a4aa-4ac1-927c-94cb99485ef1"); string contentFileNamePrefix = "content - "; JObject choiceParam = JObject.Parse(paramDefintion); choiceParam["AllowMultipleValues"] = isMultichoice; SimpleConfigModel config = new SimpleConfigModel() { Identity = "test", Name = "name", ShortNameList = new [] { "shortName" }, Symbols = new Dictionary <string, ISymbolModel>() { { "ParamA", new ParameterSymbol(choiceParam, null) } } }; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, config.ToJObject().ToString()); //content foreach (string guidFormat in GuidMacroConfig.DefaultFormats.Select(c => c.ToString())) { templateSourceFiles.Add(contentFileNamePrefix + guidFormat, inputTestGuid.ToString(guidFormat)); } // // Dependencies preparation and mounting // List <(LogLevel, string)> loggedMessages = new List <(LogLevel, string)>(); InMemoryLoggerProvider loggerProvider = new InMemoryLoggerProvider(loggedMessages); IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(addLoggerProviders: new [] { loggerProvider }); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint? sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); RunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, rpg, config, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); if (expectedToBeValid) { runnableConfig.PerformTemplateValidation(); Assert.Empty(loggedMessages.Where(l => l.Item1 >= LogLevel.Warning)); } else { var exc = Assert.Throws <TemplateValidationException>(runnableConfig.PerformTemplateValidation); Assert.Contains("The template configuration ", exc.Message); Assert.Contains(" is not valid.", exc.Message); Assert.Single(loggedMessages.Where(l => l.Item1 >= LogLevel.Warning)); string errorMessage = loggedMessages.First(l => l.Item1 >= LogLevel.Warning).Item2; Assert.Contains( "Choice parameter is invalid. It allows multiple values ('AllowMultipleValues=true'), while some of the configured choices contain separator characters ('|', ','). Invalid choices: {First|Choice}", errorMessage); } }
public void WriteSource() { TestFileSystemHelper.WriteTemplateSource(_environmentSettings, _sourceBaseDir, _sourceFiles); }
public async void InstantiateAsync_ParamsProperlyHonored(string?parameterValue, string expectedOutput, bool instantiateShouldFail) { // // Template content preparation // string sourceSnippet = @" //#if( ChoiceParam == FirstChoice ) FIRST //#elseif (ChoiceParam == SecondChoice ) SECOND //#elseif (ChoiceParam == ThirdChoice ) THIRD //#else UNKNOWN //#endif "; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, TemplateConfigQuotelessLiteralsEnabled); //content templateSourceFiles.Add("sourceFile", sourceSnippet); // // Dependencies preparation and mounting // IEngineEnvironmentSettings environment = _engineEnvironmentSettings; string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint?sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); // cannot use SimpleConfigModel dirrectly - due to missing easy way of creating ParameterSymbols SimpleConfigModel configModel = SimpleConfigModel.FromJObject(JObject.Parse(TemplateConfigQuotelessLiteralsEnabled)); var runnableConfig = new RunnableProjectConfig(environment, rpg, configModel, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); TemplateCreator creator = new TemplateCreator(_engineEnvironmentSettings); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); IReadOnlyDictionary <string, string?> parameters = new Dictionary <string, string?>() { { "ChoiceParam", parameterValue } }; var res = await creator.InstantiateAsync( templateInfo : runnableConfig, name : "tst", fallbackName : "tst2", inputParameters : parameters, outputPath : targetDir); if (instantiateShouldFail) { Assert.NotNull(res.ErrorMessage); Assert.Null(res.OutputBaseDirectory); } else { Assert.Null(res.ErrorMessage); Assert.NotNull(res.OutputBaseDirectory); string resultContent = _engineEnvironmentSettings.Host.FileSystem .ReadAllText(Path.Combine(res.OutputBaseDirectory !, "sourceFile")).Trim(); Assert.Equal(expectedOutput, resultContent); } }