Skip to content

Instantly share code, notes, and snippets.

// declaration
public class ServiceLogger : IServiceLogger
{
private readonly ILog log;
public ServiceLogger(object o)
{
log = LogManager.GetLogger(o.GetType().Name);
}
data = PersonHelper.SortPersonsByAge(data, Constants.MinAge, Constants.MaxAge);
// ....
/// <summary>
/// Sorts list of persons
/// </summary>
public static List<Person> SortPersonsByAge(IList<Person> persons, int minAge, int maxAge)
{
public void Sort(List<Person> data)
{
Person tmp = null;
for(int i = 0; i<data.Count; i++)
{
for(int j = i; j<data.Count; j++)
{
if(data[j].Compare(data[i]))
{
tmp = data[j];
@skalinets
skalinets / gist:1499201
Created December 19, 2011 22:25
FluentAssertions and exceptions
[Fact]
public void should_throw_exception_for_negatives()
{
// act
Action c = () => calculator.Add("-1,2");
// assert
c.ShouldThrow<Exception>().WithMessage("negatives are not allowed");
}
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using FluentAssertions;
using NUnit.Framework;
using Nancy.Helpers;
namespace NancySelfHosting
@skalinets
skalinets / gist:1768041
Created February 8, 2012 10:40
What it would be if String.Split() did not accept muptiple delimiters
[Fact]
public void selectManyTest()
{
var s = "2#3,4%5";
var delimiters = "#,%";
var e = delimiters
.Aggregate(Enumerable.Repeat(s, 1), (current, delimiter) =>
current.SelectMany(s1 => s1.Split(delimiter)));
e.Should().Equal(new[] {"2", "3", "4", "5"});
@skalinets
skalinets / gist:1815851
Created February 13, 2012 10:32
Maybe the most crazy implementation of StringCalculator Kata
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentAssertions;
using Xunit;
namespace StringCalculatorKata
{
public class StringCalculatorKata
@skalinets
skalinets / gist:1835067
Created February 15, 2012 11:04
StringCalculator Kata (no regex, very close to ideal clean code -- for me)
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using FluentAssertions;
using Xunit;
namespace StringCalculatorKata
{
@skalinets
skalinets / gist:2865307
Created June 3, 2012 22:51
razor enabled fubu web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
@skalinets
skalinets / gist:3823521
Created October 2, 2012 21:47
lg alias
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"