This repository was archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Added extensions methods #2
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
25d0a38
Added more extension methods (with some unit tests)
GeertvanHorrik 403fd75
Added extensions and fixtures for testing purposes
GeertvanHorrik 5f94116
Added use of shouldly
GeertvanHorrik 6edb3dc
Output GitTestExtensions to Log instead of Trace
GeertvanHorrik 22437c2
Added JetBrainsAnnotations.Fody
GeertvanHorrik 9de105f
Moved TestValues class to GitTools.Testing namespace
GeertvanHorrik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/GitTools.Core.Tests/Extensions/StringExtensionsFacts.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace GitTools.Tests | ||
{ | ||
using NUnit.Framework; | ||
using Shouldly; | ||
|
||
[TestFixture] | ||
public class StringExtensionsFacts | ||
{ | ||
[TestCase("/develop", false)] | ||
[TestCase("/master", false)] | ||
[TestCase("/pr/25", true)] | ||
[TestCase("/pull/25", true)] | ||
[TestCase("/pull-requests/25", true)] | ||
public void TheIsPullRequestMethod(string input, bool expectedValue) | ||
{ | ||
var actualValue = input.IsPullRequest(); | ||
|
||
actualValue.ShouldBe(expectedValue); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace GitTools | ||
{ | ||
// TODO: Constants go here | ||
// TODO: constants classes go here | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace GitTools | ||
{ | ||
using System.Text; | ||
using JetBrains.Annotations; | ||
|
||
public static class StringBuilderExtensions | ||
{ | ||
[StringFormatMethod("format")] | ||
public static void AppendLineFormat(this StringBuilder stringBuilder, string format, params object[] args) | ||
{ | ||
stringBuilder.AppendFormat(format, args); | ||
stringBuilder.AppendLine(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
namespace GitTools | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
|
||
public static class ProcessHelper | ||
{ | ||
private static volatile object _lockObject = new object(); | ||
|
||
// http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/f6069441-4ab1-4299-ad6a-b8bb9ed36be3 | ||
public static Process Start(ProcessStartInfo startInfo) | ||
{ | ||
Process process; | ||
|
||
lock (_lockObject) | ||
{ | ||
using (new ChangeErrorMode(ErrorModes.FailCriticalErrors | ErrorModes.NoGpFaultErrorBox)) | ||
{ | ||
process = Process.Start(startInfo); | ||
process.PriorityClass = ProcessPriorityClass.Idle; | ||
} | ||
} | ||
|
||
return process; | ||
} | ||
|
||
// http://csharptest.net/532/using-processstart-to-capture-console-output/ | ||
public static int Run(Action<string> output, Action<string> errorOutput, TextReader input, string exe, string args, string workingDirectory, params KeyValuePair<string, string>[] environmentalVariables) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should be using threads to read this. I should add an issue to fix this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably. I just copy/pasted this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, not for this PR anyways. Just a note to myself really |
||
{ | ||
if (String.IsNullOrEmpty(exe)) | ||
{ | ||
throw new FileNotFoundException(); | ||
} | ||
|
||
if (output == null) | ||
{ | ||
throw new ArgumentNullException("output"); | ||
} | ||
|
||
var psi = new ProcessStartInfo | ||
{ | ||
UseShellExecute = false, | ||
RedirectStandardError = true, | ||
RedirectStandardOutput = true, | ||
RedirectStandardInput = true, | ||
WindowStyle = ProcessWindowStyle.Hidden, | ||
CreateNoWindow = true, | ||
ErrorDialog = false, | ||
WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory, | ||
FileName = exe, | ||
Arguments = args | ||
}; | ||
|
||
foreach (var environmentalVariable in environmentalVariables) | ||
{ | ||
if (!psi.EnvironmentVariables.ContainsKey(environmentalVariable.Key) && environmentalVariable.Value != null) | ||
psi.EnvironmentVariables.Add(environmentalVariable.Key, environmentalVariable.Value); | ||
if (psi.EnvironmentVariables.ContainsKey(environmentalVariable.Key) && environmentalVariable.Value == null) | ||
psi.EnvironmentVariables.Remove(environmentalVariable.Key); | ||
} | ||
|
||
using (var process = Process.Start(psi)) | ||
{ | ||
using (var mreOut = new ManualResetEvent(false)) | ||
{ | ||
using (var mreErr = new ManualResetEvent(false)) | ||
{ | ||
process.EnableRaisingEvents = true; | ||
process.OutputDataReceived += (o, e) => | ||
{ | ||
// ReSharper disable once AccessToDisposedClosure | ||
if (e.Data == null) | ||
{ | ||
mreOut.Set(); | ||
} | ||
else | ||
{ | ||
output(e.Data); | ||
} | ||
}; | ||
process.BeginOutputReadLine(); | ||
process.ErrorDataReceived += (o, e) => | ||
{ | ||
// ReSharper disable once AccessToDisposedClosure | ||
if (e.Data == null) | ||
{ | ||
mreErr.Set(); | ||
} | ||
else | ||
{ | ||
errorOutput(e.Data); | ||
} | ||
}; | ||
|
||
process.BeginErrorReadLine(); | ||
|
||
string line; | ||
while (input != null && null != (line = input.ReadLine())) | ||
{ | ||
process.StandardInput.WriteLine(line); | ||
} | ||
|
||
process.StandardInput.Close(); | ||
process.WaitForExit(); | ||
|
||
mreOut.WaitOne(); | ||
mreErr.WaitOne(); | ||
|
||
return process.ExitCode; | ||
} | ||
} | ||
} | ||
} | ||
|
||
[Flags] | ||
public enum ErrorModes | ||
{ | ||
Default = 0x0, | ||
FailCriticalErrors = 0x1, | ||
NoGpFaultErrorBox = 0x2, | ||
NoAlignmentFaultExcept = 0x4, | ||
NoOpenFileErrorBox = 0x8000 | ||
} | ||
|
||
public struct ChangeErrorMode : IDisposable | ||
{ | ||
private readonly int _oldMode; | ||
|
||
public ChangeErrorMode(ErrorModes mode) | ||
{ | ||
_oldMode = SetErrorMode((int)mode); | ||
} | ||
|
||
void IDisposable.Dispose() { SetErrorMode(_oldMode); } | ||
|
||
[DllImport("kernel32.dll")] | ||
static extern int SetErrorMode(int newMode); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing
namespace?