Skip to content

Instantly share code, notes, and snippets.

@hmemcpy
hmemcpy / gist:9f47ae12d88b4ab38439
Last active August 29, 2015 14:06
ATDD style tests with BDDfy!
private const string program = @"
/* 1 */ class Person
/* 2 */ {
/* 3 */ public int _age = 22;
/* 4 */ public int Age { get { return _age; } set { _age = value; } }
public override string ToString() { return ""hi""; }
/* 5 */ }
/* 6 */
/* 7 */ class Program
/* 8 */ {
This file has been truncated, but you can view the full file.
TearDown : JetBrains.Util.Tests.TestLoggerListener+TestWrapperException : 124 exceptions were thrown.
#001: Component CatalogType: JetBrains.ProjectModel.SolutionActivityTrackingComponent [Singleton, Corrupted] construction has failed. Exception has been thrown by the target of an invocation. Sequence contains more than one element
--- EXCEPTION #1/4 [InvalidOperationException]
Message = “Sequence contains more than one element”
ExceptionPath = Root.InnerException.InnerException.InnerException
ClassName = System.InvalidOperationException
Data.DescriptorType = “JetBrains.Application.Extensibility.PartComponentDescriptor, JetBrains.Platform.ReSharper.ComponentModel, Version=8.2.0.2151, Culture=neutral, PublicKeyToken=1010a0d8d6380325”
Data.State = Null
HResult = COR_E_INVALIDOPERATION=80131509
@hmemcpy
hmemcpy / gist:9447256
Last active August 29, 2015 13:57
Why do u crash?????
<entry>
<record>10589</record>
<time>2014/03/09 11:56:50.360</time>
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.InvalidOperationException: Attempting to get the view from an adapter in state Closed
at Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.get_WpfTextViewHost()
at Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.ClearCommandContext()
at Microsoft.VisualStudio.Editor.Implementation.VsMouseProcessor.PostprocessMouseLeftButtonUp(MouseButtonEventArgs e)
at Microsoft.VisualStudio.Text.Utilities.WpfMouseProcessor.&lt;&gt;c__DisplayClass30.&lt;UIElement_MouseLeftButtonUp&gt;b__29()
@hmemcpy
hmemcpy / fakee
Last active January 1, 2016 23:48
AcountProvider provider = AccountProvider.CreateProvider();
AcountProvider outProvider;
A.CallTo(() => mockAppointment.GetAccountCollection().GetProviderImpl(out outProvider)) // GetProviderImpl is a generic method
.Returns(true)
.AssignsOutAndRefParameters(provider);
bool result = mockAppointment.GetAccountCollection().GetProviderImp(out outProvider); // this returns false and provider is null???
class MyBusinessObject
{
public int? MyNullable;
public bool HasSomeBusinessProperty
{
get { return myNullable.HasValue; }
}
}
@hmemcpy
hmemcpy / gist:5023336
Last active December 14, 2015 03:48
Who knew static initializers depend on the order?
public static readonly string[] MyPaths = GetAllPaths("path1", "path2");
static readonly string[] AllExtensions = new[] { ".htm", ".html", ".sshtml" };
private static string[] GetAllPaths(params string[] viewLocations)
{
// this will throw a NRE since AllExtensions is null!
return viewLocations.SelectMany(view => AllExtensions.Select(extension => view + extension)).ToArray();
}
@hmemcpy
hmemcpy / FakeItEasy.ExternalAnnotations.xml
Last active December 14, 2015 01:09
An external annotations file for FakeItEasy, so ReSharper won't complain about implicit captures on CallTo() lambdas. Place this file alongside FakeItEasy.dll and reload your solution.
<?xml version="1.0" encoding="utf-8"?>
<assembly name="FakeItEasy">
<member name="M:FakeItEasy.A.CallTo(System.Linq.Expressions.Expression{System.Action})">
<parameter name="callSpecification">
<attribute ctor="M:JetBrains.Annotations.InstantHandleAttribute.#ctor" />
</parameter>
</member>
<member name="M:FakeItEasy.A.CallTo``1(System.Linq.Expressions.Expression{System.Func{``0}})">
<parameter name="callSpecification">
<attribute ctor="M:JetBrains.Annotations.InstantHandleAttribute.#ctor" />
I'm tryng to refactor a monstrous WCF service into something more manageable.
At the time of writing, the service takes about 9 dependencies via constructor, which makes unit testing it very difficult.
The service is handling local state via state machine, does validation on the parameters, throws fault exceptions, performs the actual operation and fires publication events via a pub/sub channel. This code is very similar accross all other service calls.
I realize that I can do several of those things (argument validation, pub/sub notifications) differently, perhaps via WCF behaviors, but my gut tells me that the general approach is wrong -- this feels too "procedural".
I wonder if acronyms like DDD or CQRS or other techniques can help out here?
Thanks!
@hmemcpy
hmemcpy / readme.md
Created February 5, 2013 21:08
Your feedback on the System.Diagnostics.Abstractions API is requested...

I'm working on a small project, inspired by the awesome System.IO.Abstractions, aiming to provide a wrapper over System.Diagnostics.Process, to assist testability of anything process-related.

Where System.IO.Abstractions provides a wrapper over the Path, File, Directory types, as well as a wrapper objects over FileInfo and DirectoryInfo, all conveniently accessible from an IFileSystem, mirroring the way those types exist today in the .NET framework, the System.Diagnostics.Process type presents its own challenges when trying to create a convenient wrapper.

Your feedback on the API is, therefore, very much appreciated.

The Process class has several static methods for launching a new process, as well as other stuff:

void EnterDebugMode();

Process GetCurrentProcess();

@hmemcpy
hmemcpy / gist:3434473
Created August 23, 2012 09:06
Better way to indian?
// converts 0x00010203 to a byte array, containing: 0x03, 0x02, 0x01, 0x00
public static byte[] ToBigEndian(int data)
{
var result = new byte[4];
result[0] = (byte)data;
result[1] = (byte)(((uint)data >> 8) & 0xFF);
result[2] = (byte)(((uint)data >> 16) & 0xFF);
result[3] = (byte)(((uint)data >> 24) & 0xFF);