public void SearchAndReplace_Execute_Success() { var templateName = "Test"; var sourceFile = Path.GetFullPath(@".\TestData\temp\Source.cs"); var mergeFile = Path.GetFullPath(@".\TestData\temp\Source_searchreplace.cs"); var expected = File.ReadAllText(@".\TestData\SearchReplace\Source_expected.cs").Replace("\r\n", string.Empty).Replace("\n", string.Empty); var path = Path.GetFullPath(@".\TestData\temp"); Directory.CreateDirectory(path); File.Copy(Path.Combine(Environment.CurrentDirectory, $"TestData\\SearchReplace\\Source.cs"), sourceFile, true); File.Copy(Path.Combine(Environment.CurrentDirectory, $"TestData\\SearchReplace\\Source_searchreplace.cs"), mergeFile, true); GenContext.Current = new FakeContextProvider() { GenerationOutputPath = Directory.GetCurrentDirectory(), DestinationPath = Directory.GetCurrentDirectory(), }; var mergePostAction = new SearchAndReplacePostAction(templateName, new MergeConfiguration(mergeFile, true)); mergePostAction.Execute(); var result = File.ReadAllText(sourceFile); Directory.Delete(path, true); Assert.Equal(expected, result.Replace("\r\n", string.Empty).Replace("\n", string.Empty)); }
public void Execute_FileNotFound_Error() { var templateName = "Test"; var mergeFile = Path.GetFullPath(@".\TestData\SearchReplace\NoSource_searchreplace.cs"); var mergePostAction = new SearchAndReplacePostAction(templateName, new MergeConfiguration(mergeFile, true)); Exception ex = Assert.Throws <Exception>(() => mergePostAction.Execute()); Assert.Equal(string.Format(StringRes.PostActionException, typeof(SearchAndReplacePostAction), templateName), ex.Message); Assert.Equal(typeof(FileNotFoundException), ex.InnerException.GetType()); Assert.Equal(string.Format(StringRes.MergeFileNotFoundExceptionMessage, mergeFile, templateName), ex.InnerException.Message); }
public void Execute_FileNotFound_NoError() { var templateName = "Test"; var mergeFile = Path.GetFullPath(@".\TestData\temp\NoSource_searchreplace.cs"); var path = Path.GetFullPath(@".\TestData\temp"); var failedFileName = @"temp\NoSource_failedpostaction.cs"; var relativeSourceFilePath = "temp\\NoSource.cs"; Directory.CreateDirectory(path); File.Copy(Path.Combine(Environment.CurrentDirectory, $"TestData\\SearchReplace\\NoSource_searchreplace.cs"), mergeFile, true); GenContext.Current = new FakeContextProvider() { OutputPath = path, DestinationPath = Path.GetFullPath(@".\Destination\Project"), DestinationParentPath = Path.GetFullPath(@".\Destination\"), }; var mergePostAction = new SearchAndReplacePostAction(templateName, new MergeConfiguration(mergeFile, false)); mergePostAction.Execute(); var expected = new FailedMergePostActionInfo( relativeSourceFilePath, mergeFile, failedFileName, string.Format(StringRes.FailedMergePostActionFileNotFound, relativeSourceFilePath, templateName), MergeFailureType.FileNotFound); Directory.Delete(path, true); Assert.Collection <FailedMergePostActionInfo>( GenContext.Current.FailedMergePostActions, f1 => { Assert.Equal(expected.Description, f1.Description); Assert.Equal(expected.FailedFileName, f1.FailedFileName); Assert.Equal(expected.FileName, f1.FileName); Assert.Equal(expected.FilePath, f1.FilePath); Assert.Equal(expected.MergeFailureType, f1.MergeFailureType); }); }