Skip to content

Instantly share code, notes, and snippets.

@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"});
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: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");
}
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];
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)
{
// declaration
public class ServiceLogger : IServiceLogger
{
private readonly ILog log;
public ServiceLogger(object o)
{
log = LogManager.GetLogger(o.GetType().Name);
}