Skip to content

Instantly share code, notes, and snippets.

View ashic's full-sized avatar

Ashic Mahtab ashic

View GitHub Profile
public class when_withdrawing_money_from_empty_account
{
Establish context = ()=> depositor = new Depositor(13);
Because of = ()=> depositor.Withdraw(50.0m);
It should_decrease_balance = ()=> depositor.Balance.ShouldBeGreaterThan(0.01m);
It should_have_account_open = ()=> depositor.AccountIsOpen.ShouldBeTrue();
}
@ashic
ashic / duck test
Created July 28, 2011 13:58
testing duck
namespace DuckTest
{
class Program
{
static void Main(string[] args)
{
var connectionString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
var db = new DuckContext(connectionString);
db.In<Person>()
@ashic
ashic / insert-if.cs
Created July 29, 2011 10:15
Possible Insert If syntax
db.In<Person>().Insert(()=> new Person{ Name = "John", Age = 5, Id = 5 })
.IfNotExists(()=> new Person{Name = "John", Age = 5});
//intentionally kept the id out.
//This'll mean that we can handle creates in a kind of idempotent manner.
@ashic
ashic / duck.cs
Created July 29, 2011 11:43
duck
var personId = new Guid("9438D2F0-AD99-45C0-86D3-CAF9C3E77CAF");
//fails...says @p0 not passed in
db.In<Person>()
.Where(x => x.PersonId == personId)
.Update(x => new Person { Name = "XX" });
//succeeds
db.In<Person>()
.Where(x => x.PersonId == new Guid("9438D2F0-AD99-45C0-86D3-CAF9C3E77CAF"))
@ashic
ashic / denormalizer-testing.cs
Created August 20, 2011 04:03
denormalizer testing
public abstract class DenormalizerTest<TDenormalizer, TView>
{
public abstract IEnumerable<Event> GivenTheseEvents();
public abstract IQueryable<TView> WhenIPerformThisQuery();
public abstract IEnumerable<TView> IShouldGetTheseResults();
[Test]
public void PerformTest()
{
var events = GivenTheseEvents();
@ashic
ashic / ko.js
Created August 26, 2011 05:09
ko
<select data-bind='value:selected, options:availableOptions, optionsText:'name' />
<div data-bind='template:{"name":resolveTemplate, data:selected}' />
var vm = {
'selected' : ko.observable(''),
'availableOptions' : ko.ObservableArray([{'name':'foo', 'value':'fooval}, {'name':'bar', 'value':'barval'}]),
'resolveTemplate' : function(){
var selectedItem;
selectedItem = selected();
if(selectedItem){
@ashic
ashic / containskey
Created September 16, 2011 14:02
ContainsKey on object
namespace System
{
public static class ObjectExtensions
{
public static bool ContainsKey(this object target, string key)
{
return target.GetType().GetProperties().Any(x => x.Name == key);
}
}
}
public static IDictionary<string, object> ToDictionary(this object target)
{
return target.GetType().GetProperties().ToDictionary(x => x.Name, y => y.GetValue(target, new object[] { }));
}
@ashic
ashic / object.js
Created September 23, 2011 09:54
object
if(!window.MYNAMESPACE) window.MYNAMESPACE = {};
window.MYNAMESPACE.proxy = function(){
var that, someSharedVariable;
that = {};
someSharedVariable = 10;
that.doSomething = function(){
callJqueryOrSomething();
//use someSharedVariable;
@ashic
ashic / jquery-dateFormat
Created January 2, 2012 00:24
jquery-dateFormat
var date = getDate();
var format = 'dd-MM-yyyy hh:mm:ss';
var formattedDate = $.format.date(date, format);
alert(formattedDate); //alerts 02-01-2012 12:23:41