Skip to content

Instantly share code, notes, and snippets.

View AlexZeitler's full-sized avatar
👷‍♂️
Building stuff

Alexander Zeitler AlexZeitler

👷‍♂️
Building stuff
View GitHub Profile
@AlexZeitler
AlexZeitler / gist:927605
Created April 19, 2011 13:16
Can't create mocks of sealed classes
public class ListOfAValidAndAInvalidRequirement {
OnEstablish context =
fakeAccessor =>
{
IRequirement validRequirement = fakeAccessor.An<IRequirement>();
validRequirement.WhenToldTo(r => r.Validate()).Return(true); // throws ex here
IRequirement invalidRequirement = fakeAccessor.An<IRequirement>();
invalidRequirement.WhenToldTo(r=>r.Validate()).Return(false);
IList<IRequirement> requirements = new List<IRequirement>
{
@AlexZeitler
AlexZeitler / gist:934118
Created April 21, 2011 10:28
passing in objects or their members values?
I have to implement a method that does some string formatting based on string property values of two COM objects.
Now there are at least two ways to deal with it...
a) passing in the objects:
public string CreateIdForPartInView(IPartDoc part, IView drawingView) {
IModelDoc2 model = part as IModelDoc2;
string modelPath = model.GetPathName();
string modelName = Path.GetFileNameWithoutExtension(modelPath);
string id = string.Format("{0}-1@{1}", modelName, drawingView.Name);
@AlexZeitler
AlexZeitler / gist:945176
Created April 27, 2011 20:51
rudimentary draft of comparing items of two lists on specified property as machine.specfication extension method
public class Given_two_lists_containing_a_point_each_when_comparing_points_on_x_value {
static IList<Point> _expectedPoints;
static IList<Point> _actualPoints;
Establish context
= () => {
_expectedPoints = new List<Point>
{
new Point {X = 153.6m, Y = 21m, Z = 0}
};
@AlexZeitler
AlexZeitler / gist:957821
Created May 5, 2011 20:11
Passing System.Type to Moq.As<T>
public override object CreateFake(Type firstInterfaceType, Type secondInterfaceType)
{
var closedFirstMockType = typeof(Mock<>).MakeGenericType(firstInterfaceType);
var closedSecondMockType = typeof (Mock<>).MakeGenericType(secondInterfaceType);
var objectProperty = closedFirstMockType.GetProperty("Object", closedFirstMockType);
var instance = Activator.CreateInstance(closedFirstMockType);
return objectProperty.GetValue(instance, null);
}
Tried:
@AlexZeitler
AlexZeitler / gist:957870
Created May 5, 2011 20:34
Enums replaced
public class StepFileItemState {
private Action _processToNextStep;
public static readonly StepFileItemState Uploaded =
new StepFileItemState() {
_proceedToNextStep = () => {
// impl
}
};
@AlexZeitler
AlexZeitler / gist:1148962
Created August 16, 2011 12:31
Inheritance of BehaviorConfigs for machine.fakes
using Machine.Fakes;
using Machine.Specifications;
namespace BehaviorConfigInheritance {
public class Given_a_car_when_starting_it : WithSubject<Car> {
static string _sound;
Establish context = () =>
{
//With(new EngineLoaded(300));
@AlexZeitler
AlexZeitler / gist:1183163
Created August 31, 2011 09:28
Localization JSON
[
{
"Button": {
"de-DE": "Speichern",
"en-GB": "Save"
}
},
{
"Email": {
"de-DE": "E-Mail-Adresse",
@AlexZeitler
AlexZeitler / gist:1364110
Created November 14, 2011 14:59
JsonNetFormatter issue
Start a project from scratch
Install-Package WebApi.All
Install-Package WebApiContrib
var config = new WebApiConfiguration();
config.Formatters.Clear();
config.Formatters.Add(new JsonNetFormatter()); // doesn't compile here
cannot convert from 'WebApiContrib.Formatters.JsonNet.JsonNetFormatter' to 'System.Net.Http.Formatting.MediaTypeFormatter'
@AlexZeitler
AlexZeitler / dabblet.css
Created December 16, 2011 15:10
Untitled
div[class*='tocolor-'] {color:red }
@AlexZeitler
AlexZeitler / gist:1521939
Created December 26, 2011 19:04
knockoutjs list template with nav container
<nav id="menu">
<ul id="thelist" data-bind="foreach: contents">
<li><span data-bind="text: title"></span></li>
</ul>
</nav>