Skip to content

Instantly share code, notes, and snippets.

View akimboyko's full-sized avatar
🙃

Akim Boyko akimboyko

🙃
View GitHub Profile
@akimboyko
akimboyko / gist:3709454
Created September 12, 2012 19:54
Ninject Kernel with multiple Modules
void Main()
{
var kernel = new Ninject.StandardKernel(new EntitieseModule(), new DocumentStoreModule(), new ModelRepositoryModule());
}
public interface IModelRepository<T> where T: IModel
{
//interface stuff here
}
@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 / gist:3709484
Created September 12, 2012 20:01
ConstructorArgument example
void Main()
{
using(var kernel = new StandardKernel(new ExampleKernel()))
{
var d6 = kernel.Get<Die>();
var d20 = kernel.Get<Die>(new ConstructorArgument("numSides", 20));
d6.NumSides.Dump();
d20.NumSides.Dump();
}
@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:4258647
Created December 11, 2012 13:41
PowerShell exception re-throwing sample
Write-Host 'throw'
try
{
try
{
throw "exception"
}
catch
{
@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