Skip to content

Instantly share code, notes, and snippets.

@Rookian
Rookian / gist:c30128591f3986e2c38c
Created August 28, 2014 21:12
EF AutoMapper Proxy Tests:
using System.Data.Entity;
using System.Linq;
using AutoMapper;
namespace EFTests
{
public class Program
{
public static void Main()
{
@Rookian
Rookian / FormFactory
Created December 9, 2011 23:51
StructureMap Factory
public class FormFactory : IFormFactory
{
private readonly Func<Type, object, Form> _createFormWithRuntimeParam;
public FormFactory(Func<Type, object, Form> createFormWithRuntimeParam)
{
_createFormWithRuntimeParam = createFormWithRuntimeParam;
}
public TForm CreateForm<TForm>() where TForm : Form
@Rookian
Rookian / spec.cs
Created January 7, 2012 17:54
Reflection or public?
[Subject(typeof(Bootstrapper))]
public class When_injecting_unit_of_work_and_repositories_and_parameter_config_in_a_consumer
{
class ConsumerForTest
{
private readonly IUnitOfWork _unitOfWork;
private readonly IRepository<PosDevice> _posDeviceRepository;
private readonly IRepository<Store> _storeRepository;
private readonly ParameterConfig _parameterConfig;
@Rookian
Rookian / DisposeSpec.cs
Created January 7, 2012 18:29
The current proxy generator can not intercept the specified method for the following reason: - Sealed methods can not be intercepted.
public class UnitOfWork : IUnitOfWork
{
private ObjectContext _db;
public UnitOfWork(ObjectContext db)
{
_db = db;
}
public void Commit()
nicht funktionierender Aufruf:
C:\TFS_BDD_TestingFramework\Machine.Specifications-Release\mspec-clr4.exe --xml "\\SERVERNAME\BuildResult\MasterBuild\ImportServerMasterBuild\ImportServerMasterBuild 6.0.0.81\results.xml" --html "\\SERVERNAME\BuildResult\MasterBuild\ImportServerMasterBuild\ImportServerMasterBuild 6.0.0.81" " \\SERVERNAME\BuildResult\MasterBuild\ImportServerMasterBuild\ImportServerMasterBuild 6.0.0.81\Release\ImportServerTests.dll"
Ergebnis:
Could not load file or assembly 'file:///\\SERVERNAME\BuildResult\MasterBuild\ImportServerMasterBuild\ImportServerMasterBuild 6.0.0.81\Release\ImportServerTests.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
funktionierender Aufruf:
C:\TFS_BDD_TestingFramework\Machine.Specifications-Release\mspec-clr4.exe --xml "C:\BuildResult\MasterBuild\ImportServerMasterBuild\ImportServerMasterBuild 6.0.0.81\results.xml" --html "C:\BuildResult\MasterBuild\ImportServerMasterBuild\ImportServerMasterBuild 6.0.0.81" " C:
@Rookian
Rookian / mvpAbstractFactorySeviceLocator
Created March 22, 2012 12:03
Abstract Factory / Service Locator
public class MainViewPresenter : Presenter<IMainView>
{
private readonly IArticleRepository _articlesRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly IPresenterFactory _presenterFactory;
public MainViewPresenter(IMainView view, IArticleRepository articlesRepository, IUnitOfWork unitOfWork, IPresenterFactory presenterFactory)
: base(view)
{
_articlesRepository = articlesRepository;
@Rookian
Rookian / PresenterSpecs.cs
Created March 26, 2012 11:43
FakeItEasyAbstractClassAndVirtualMembers
[Subject(typeof(Presenter<>))]
public class When_disposing_a_presenter
{
static IUnitOfWork UnitOfWork;
static Presenter<IView> Presenter;
static IView View;
Establish context = () =>
{
UnitOfWork = A.Fake<IUnitOfWork>();
@Rookian
Rookian / Ctor With Runtime Values And Service Dependencies
Created May 5, 2012 11:42
Ctor With Runtime Values And Service Dependencies
class Program
{
static void Main()
{
ObjectFactory.Initialize(x =>
{
x.For<IExecuter>().Use<Executer>();
x.For<IService>().Use<Service>();
x.For<Func<Data, IExecuter>>().Use(data => ObjectFactory.With(data.GetType(), data).GetInstance<IExecuter>());
});
@Rookian
Rookian / StructureMapHttpModule.cs
Created June 1, 2012 11:53
DependencyInjection StructureMap HttpModule
/// <summary>
/// HttpModule is the better choice for session management, because when more than one controller is involved within one webrequest,
/// the session will be disposed by one controller and the other controller can not reuse the session, because it is already disposed
/// </summary>
public class UnitOfWorkHttpModule : IHttpModule
{
/// <summary>
/// Should be refactored to use constructor injection
/// http://bugsquash.blogspot.de/2009/11/windsor-managed-httpmodules.html
/// </summary>
@Rookian
Rookian / SerializationExtensions.cs
Created June 6, 2012 11:14
Dictionary Serialization
public static class SerializationExtensions
{
public static string Serialize<T>(this T obj)
{
var serializer = new DataContractSerializer(obj.GetType());
using (var writer = new StringWriter())
using (var stm = new XmlTextWriter(writer))
{
serializer.WriteObject(stm, obj);
return writer.ToString();