Skip to content

Instantly share code, notes, and snippets.

@akimboyko
akimboyko / gist:3709454
Created Sep 12, 2012
Ninject Kernel with multiple Modules
View gist:3709454
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 Sep 12, 2012
NUnit Exception Testing
View gist:3709463
void Main()
{
// nunit runner
NUnit.ConsoleRunner.Runner.Main(new string[]
{
Assembly.GetExecutingAssembly().Location,
});
}
public interface IBookMarket
@akimboyko
akimboyko / gist:3709484
Created Sep 12, 2012
ConstructorArgument example
View gist:3709484
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 Oct 25, 2012
Simple unittest for LinqPad
View Nunit snippet 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 Dec 11, 2012
PowerShell exception re-throwing sample
View gist:4258647
Write-Host 'throw'
try
{
try
{
throw "exception"
}
catch
{
@akimboyko
akimboyko / gist:4259463
Created Dec 11, 2012
Dynamic wher clause: System.Linq.Dynamic and PredicateBuilder
View gist:4259463
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>>()
View gist:4275479
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 Dec 17, 2012
How to rewrite unittest not to test actual work with database, but works only with mocks
View gist:4318084
void Main()
{
// add NUnit and RhinoMocks
SomeRule_InsertInfo_WasInserted();
SomeRule_GetInfo_ReciveCorrectInfo();
}
// DTO
public class Info
@akimboyko
akimboyko / gist:4319926
Created Dec 17, 2012
Build Fluent nHibernate SQLite configuration in memory
View gist:4319926
/// <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 Dec 10, 2015
Ninject Abstract Factory sample
View gist:4370128
void Main()
{
var kernel = new StandardKernel();
kernel.Load<FuncModule>(); // for sake of LinqPAD
kernel.Bind<IJobFactory>().ToFactory();
// wire concreet implementation of
kernel