Skip to content

Instantly share code, notes, and snippets.

View akimboyko's full-sized avatar
🙃

Akim Boyko akimboyko

🙃
View GitHub Profile
@akimboyko
akimboyko / gist:3709463
Created September 12, 2012 19:57
NUnit Exception Testing
void Main()
{
// nunit runner
NUnit.ConsoleRunner.Runner.Main(new string[]
{
Assembly.GetExecutingAssembly().Location,
});
}
public interface IBookMarket
@akimboyko
akimboyko / Nunit snippet for LinqPad
Created October 25, 2012 14:14
Simple unittest for LinqPad
void Main()
{
// add references: nunit.framework.dll and nunit-console-runner.dll
// nunit runner
NUnit.ConsoleRunner.Runner.Main(new string[]
{
Assembly.GetExecutingAssembly().Location,
});
}
@akimboyko
akimboyko / gist:4259463
Created December 11, 2012 15:45
Dynamic wher clause: System.Linq.Dynamic and PredicateBuilder
void Main()
{
// add assembly System.Linq.Dynamic and using System.Linq.Dynamic
var fruits = new [] { new Product { Id = 1, ColA = "Apple", ColB = "Red" }, new Product { Id = 2, ColA = "IceCream", ColB = "White" } };
var cars = new [] { new Product { Id = 1, ColA = "Ferrary", ColB = "Red" }, new Product { Id = 2, ColA = "Ford", ColB = "Black" } };
var predicate =
PredicateBuilder
.True<Tuple<Product, Product>>()
@akimboyko
akimboyko / gist:4275479
Created December 13, 2012 10:15
Regex with {}
void Main()
{
var input = @"{TEST} is {TEST}";
ObtainTokens(input).Dump();
}
public static IEnumerable<string> ObtainTokens(/*this*/ string originalString)
{
Regex expression = new Regex(@"{(\w*)}");
@akimboyko
akimboyko / gist:4318084
Created December 17, 2012 12:54
How to rewrite unittest not to test actual work with database, but works only with mocks
void Main()
{
// add NUnit and RhinoMocks
SomeRule_InsertInfo_WasInserted();
SomeRule_GetInfo_ReciveCorrectInfo();
}
// DTO
public class Info
@akimboyko
akimboyko / gist:4319926
Created December 17, 2012 17:08
Build Fluent nHibernate SQLite configuration in memory
/// <summary>
/// Builds the configuration.
/// </summary>
/// <returns>nHibernate SQLite configuration</returns>
protected override Configuration BuildConfiguration()
{
CleanUpDbFileIfRequired();
return Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory()
@akimboyko
akimboyko / gist:4370128
Last active December 10, 2015 02:48
Ninject Abstract Factory sample
void Main()
{
var kernel = new StandardKernel();
kernel.Load<FuncModule>(); // for sake of LinqPAD
kernel.Bind<IJobFactory>().ToFactory();
// wire concreet implementation of
kernel
@akimboyko
akimboyko / gist:4379572
Created December 26, 2012 10:50
Call generic implementation of method using Reflection
void Main()
{
GetPersisterFor(new Foo());
}
public interface IPersister { }
public interface IEntity { }
public class Foo : IEntity { }
public class Bar : IEntity { }
@akimboyko
akimboyko / gist:4437787
Created January 2, 2013 20:41
Ninject, static constructor and named bindings
void Main()
{
using(var kernel = new StandardKernel())
{
kernel
.Bind<IDocumentService>()
.ToMethod(x => CoDocumentService.Create(x.Kernel.Get<IMessage>(),x.Kernel.Get<IClientChannel>("IClientChannel")))
.InTransientScope();
kernel
void Main()
{
// FindBaseClassWith
Assert.That(typeof(DeriviedLeft).FindBaseClassWith(typeof(DeriviedLeft)), Is.EqualTo(typeof(DeriviedLeft)));
Assert.That(typeof(DeriviedLeft).FindBaseClassWith(typeof(SubDeriviedLeft)), Is.EqualTo(typeof(DeriviedLeft)));
Assert.That(typeof(DeriviedLeft).FindBaseClassWith(typeof(DeriviedRight)), Is.EqualTo(typeof(object)));
Assert.That(typeof(DeriviedLeft).FindBaseClassWith(typeof(object)), Is.EqualTo(typeof(object)));
Assert.That(typeof(DeriviedLeft).FindBaseClassWith(typeof(Another)), Is.EqualTo(typeof(object)));
Assert.That(typeof(DeriviedRight).FindBaseClassWith(typeof(DeriviedRight)), Is.EqualTo(typeof(DeriviedRight)));
Assert.That(typeof(DeriviedRight).FindBaseClassWith(typeof(DeriviedLeft)), Is.EqualTo(typeof(object)));