Skip to content

Instantly share code, notes, and snippets.

View amirci's full-sized avatar

Amir Barylko amirci

View GitHub Profile
@amirci
amirci / param_with_anonymous_class.cs
Created September 14, 2011 15:39
Anonymous classes as parameters
// using a IDictionary
public void ExecuteCall(string query, IDictionary<string, object> parameters);
ExecuteCall("SELECT * from....", new Dictionary { {"City", "New York" }, { "Code", 3 } });
// using an anonymous
public void ExecuteCall(string query, object parameters);
// and to call it
ExecuteCall("SELECT * from....", new { City = "New York", Code = 3 } );
@amirci
amirci / virtual_and_new.cs
Created June 6, 2011 05:30
Virtual and redefining methods with "new" is not the same
public class ConcreteMockTest
{
[Test]
public void Worker_WhenDoWorkIsCalled_SendsEmailToTylerAboutRussianBrides()
{
var emailSender = new FakeEmailSender();
var worker = new Worker(emailSender);
worker.DoWork();
@amirci
amirci / prdc_dsl_populate.cs
Created June 5, 2011 20:17
DSL to populate presenters and sessions
return MakeSlots(
b => b.From(7).To(8).Event("Registration & Breakfast"),
b => b.From(8).To(8.15).Event("Welcome"),
b => b.From(8.15).To(9.15).Event("KeyNote"),
b => b.From(9.30).To(10.45)
.InRoom(LombardyA)
.Presenter("Tom Opgenorth").Session("Intro Into the Android Army"),
b => b.InRoom(LombardyB)
.Session("Limits of TDD: How To Test Code Never Meant To Be")
.Presenter("Robert Reppel"),
@amirci
amirci / test_prdc_api.rb
Created May 16, 2011 12:32
Testing PrDC API
require 'rubygems'
require 'net/http'
require 'json'
require 'uri'
require 'date'
@host = 'prairiedevcon.com'
#@host = 'localhost'
@port = '80'
#@port = '50758'
@amirci
amirci / local nuget packages.rb
Created April 10, 2011 04:56
Install packages from packages_local.config
FileList["**/packages_local.config"].each do |file|
cp file, "packages.config"
sh "nuget install packages.config /OutputDirectory Packages /source #{local_feed}"
end
@amirci
amirci / Rakefile.rb
Created March 27, 2011 00:58
Rakefile to generate nuget packages passing the name of the package, version and folder to get the assemblies from
require 'rubygems'
require 'rake/clean'
require 'albacore'
include FileUtils
desc 'Publish nuget package'
task :default => ["deploy:publish"]
namespace :deploy do
@amirci
amirci / Fluid enumerable join to string.cs
Created March 18, 2011 03:53
Extensions to Join all the elements in the collection calling the functor and using separator
public static string Join<T>(this IEnumerable<T> collection, char separator, Func<T, string> fn)
{
return collection
.Head()
.Aggregate(new StringBuilder(), (b, x) =>
{
b.Append(fn(x));
b.Append(separator);
return b;
})
@amirci
amirci / PropertiesInterceptor
Created November 5, 2010 02:29
Interceptor that stores the properties of an interface
public class PropertyInterceptor : IInterceptor
{
private readonly IDictionary<string, object> _properties = new Dictionary<string, object>();
public void Intercept(IInvocation invocation)
{
var key = invocation.Method.Name.Substring(4);
if (invocation.Method.Name.StartsWith("set_"))
{