public void MergePostAction_Execute_Success() { var templateName = "Test"; var sourceFile = Path.GetFullPath(@".\TestData\temp\Source.cs"); var mergeFile = Path.GetFullPath(@".\TestData\temp\Source_postaction.cs"); var expected = File.ReadAllText(@".\TestData\Merge\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\\Merge\\Source.cs"), sourceFile, true); File.Copy(Path.Combine(Environment.CurrentDirectory, $"TestData\\Merge\\Source_postaction.cs"), mergeFile, true); GenContext.Current = new FakeContextProvider() { GenerationOutputPath = Directory.GetCurrentDirectory(), DestinationPath = Directory.GetCurrentDirectory(), }; var mergePostAction = new MergePostAction(templateName, new MergeConfiguration(mergeFile, true)); mergePostAction.Execute(); var result = File.ReadAllText(sourceFile).Replace("\r\n", string.Empty).Replace("\n", string.Empty); Directory.Delete(path, true); Assert.Equal(expected, result); }
public void Execute_FileNotFound_ErrorAsync() { var templateName = "Test"; var mergeFile = Path.GetFullPath(@".\TestData\Merge\NoSource_postaction.cs"); var mergePostAction = new MergePostAction(templateName, new MergeConfiguration(mergeFile, true)); Exception ex = Assert.Throws <Exception>(() => mergePostAction.Execute()); Assert.Equal(string.Format(StringRes.PostActionException, typeof(MergePostAction), templateName), ex.Message); Assert.Equal(typeof(FileNotFoundException), ex.InnerException.GetType()); Assert.Equal(string.Format(StringRes.MergeFileNotFoundExceptionMessage, mergeFile, templateName), ex.InnerException.Message); }
public void MergePostAction_Execute_LineNotFound_Error() { var templateName = "Test"; var sourceFile = Path.GetFullPath(@".\TestData\Merge\Source_fail.cs"); var mergeFile = Path.GetFullPath(@".\TestData\Merge\Source_fail_postaction.cs"); var mergePostAction = new MergePostAction(templateName, new MergeConfiguration(mergeFile, true)); var result = File.ReadAllText(sourceFile); Exception ex = Assert.Throws <Exception>(() => mergePostAction.Execute()); Assert.Equal(string.Format(StringRes.PostActionException, typeof(MergePostAction), templateName), ex.Message); Assert.Equal(typeof(InvalidDataException), ex.InnerException.GetType()); Assert.Equal(string.Format(StringRes.MergeLineNotFoundExceptionMessage, "namespace TestData", sourceFile, templateName), ex.InnerException.Message); }
public void MergePostAction_Execute_LineNotFound_NoError() { var templateName = "Test"; var sourceFile = Path.GetFullPath(@".\TestData\temp\Source_fail.cs"); var mergeFile = Path.GetFullPath(@".\TestData\temp\Source_fail_postaction.cs"); var outputPath = Path.GetFullPath(@".\TestData\temp"); var destinationPath = Path.GetFullPath(@".\Destination\Project"); Directory.CreateDirectory(outputPath); File.Copy(Path.Combine(Environment.CurrentDirectory, $"TestData\\Merge\\Source_fail.cs"), sourceFile, true); File.Copy(Path.Combine(Environment.CurrentDirectory, $"TestData\\Merge\\Source_fail_postaction.cs"), mergeFile, true); GenContext.Current = new FakeContextProvider() { GenerationOutputPath = outputPath, DestinationPath = destinationPath, }; var mergePostAction = new MergePostAction(templateName, new MergeConfiguration(mergeFile, false)); var result = File.ReadAllText(Path.Combine(outputPath, sourceFile)); mergePostAction.Execute(); var expected = new FailedMergePostActionInfo( "temp\\Source_fail.cs", Path.Combine(outputPath, "Source_fail_postaction.cs"), "temp\\Source_fail_failedpostaction.cs", Path.Combine(outputPath, "Source_fail_failedpostaction.cs"), string.Format(StringRes.FailedMergePostActionLineNotFound, "namespace TestData", "temp\\Source_fail.cs", templateName), MergeFailureType.LineNotFound); Directory.Delete(outputPath, true); Assert.Collection <FailedMergePostActionInfo>( GenContext.Current.FailedMergePostActions, f1 => { Assert.Equal(expected.Description, f1.Description); Assert.Equal(expected.FailedFileName, f1.FailedFileName); Assert.Equal(expected.FailedFilePath, f1.FailedFilePath); Assert.Equal(expected.FileName, f1.FileName); Assert.Equal(expected.FilePath, f1.FilePath); Assert.Equal(expected.MergeFailureType, f1.MergeFailureType); }); }
public void MergePostAction_Execute_LineNotFound_Error() { var templateName = "Test"; var sourceFile = Path.GetFullPath(@".\TestData\Merge\Source_fail.cs"); var mergeFile = Path.GetFullPath(@".\TestData\Merge\Source_fail_postaction.cs"); GenContext.Current = new TestContextProvider() { GenerationOutputPath = Environment.CurrentDirectory, DestinationPath = Environment.CurrentDirectory, }; var mergePostAction = new MergePostAction(templateName, new MergeConfiguration(mergeFile, new CSharpStyleProvider(), true)); var result = File.ReadAllText(sourceFile); Exception ex = Assert.Throws <Exception>(() => mergePostAction.Execute()); Assert.Equal(string.Format(StringRes.PostActionException, typeof(MergePostAction), templateName), ex.Message); Assert.Equal(typeof(InvalidDataException), ex.InnerException.GetType()); Assert.Equal(string.Format(StringRes.MergeLineNotFoundExceptionMessage, "namespace TestData", sourceFile, templateName), ex.InnerException.Message); }