This file contains 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> |
This file contains 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 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 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 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
/// <summary> | |
/// Helper class to manage a (part of) an array of T (similar to the BCL's ArraySegment, but actually providing some useful functionality) | |
/// </summary> | |
public class ArraySegment<T> : IEnumerable<T> | |
{ | |
private readonly T[] _rawArray; | |
private readonly int _offset; | |
private readonly int _length; | |
public ArraySegment(T[] rawArray, int offset, int length) |
This file contains 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
using System; | |
using System.Collections.Generic; | |
// Factory methods provided in non-generic abstract base class | |
public abstract class Builder | |
{ | |
public static Builder<T> For<T>() where T : new() | |
{ | |
return new Builder<T>(() => new T()); | |
} |
This file contains 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
{ | |
"traceId": "[snip]", | |
"traceEntries": { | |
"inbound": [ | |
{ | |
"source": "api-inspector", | |
"timestamp": "2015-11-23T14:38:14.3755947Z", | |
"elapsed": "00:00:00.0980973", | |
"data": { | |
"request": { |
This file contains 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
using System; | |
using System.IO; | |
namespace Tools.Infrastructure | |
{ | |
class Logger | |
{ | |
static object _lock = new object(); | |
public static void Info(string message) | |
{ |
This file contains 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
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Data.Common; | |
using System.Linq; | |
using System.Reflection; | |
namespace Tools | |
{ |
This file contains 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
//Copyright (C) 2013 DvdKhl | |
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | |
//to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
//and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
//WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
OlderNewer