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
public static byte Compress(string text) | |
{ | |
using (var ms = new MemoryStream()) | |
{ | |
using (var zip = new GZipStream(ms, | |
CompressionMode.Compress)) | |
using (var writer = new StreamWriter(zip, Encoding.UTF8)) | |
{ | |
writer.Write(text); | |
} |
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
[Test] | |
public void EnsureDependencyIsCalledWithCorrectArguments() | |
{ | |
var dependency = MockRepository.GenerateMock<IDependency>(); | |
dependency.Expect(x => x.DoSomething(null, 0)) | |
.IgnoreArguments().Return(7).Repeat.Once(); | |
dependency.Expect(x => x.DoSomething(null, 0)) | |
.IgnoreArguments().Return(3).Repeat.Once(); | |
var systemUnderTest = new SystemUnderTest(dependency); |
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
[Test] | |
public void UsingMoqWithVerifications() | |
{ | |
// Arrange | |
var dependency = new Mock<IDependency>(); | |
// unfortunately there does not seem to be a simple way to set multiple return values with Moq... | |
var returnValues = new[] {7, 3}; | |
var index = -1; | |
dependency.Setup(x => x.DoSomething(It.IsAny<SomeComplexType>(), It.IsAny<int>())) |
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
public class ProcessHelper | |
{ | |
/// <summary> | |
/// Starts a command line process, redirecting both StdOut and StdErr. | |
/// </summary> | |
/// <param name="fileName">Path to the executable</param> | |
/// <param name="arguments">Command line arguments</param> | |
/// <param name="onErr">Action to perform when data from the child process is read from StdErr. The action takes 2 parameters: a Process instance (representing the child process) and a string (the data it wrote to StdErr)</param> | |
/// <param name="onOut">Action to perform when data from the child process is read from StdOut. The action takes 2 parameters: a Process instance (representing the child process) and a string (the data it wrote to StdOut)</param> | |
/// <returns></returns> |
NewerOlder