Skip to content

Instantly share code, notes, and snippets.

View jbogard's full-sized avatar

Jimmy Bogard jbogard

View GitHub Profile
@jbogard
jbogard / gist:b28a1d88e7ecb833544020a8d9d76173
Last active June 30, 2016 13:57 — forked from cryo75/gist:e4699b021d26820203e6896bd6532962
Automapper StackOverflowException
public class UserModel
{
public virtual CategoryModel Category { get; set; }
public virtual UserGroupModel Group { get; set; }
}
public class CategoryModel
{
public CategoryModel Category { get; set; }
}
void Main()
{
var configurationStore = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);
var mapper = new MappingEngine(configurationStore);
var server = new Server();
configurationStore
.CreateMap<From, To>()
.ForMember(d => d.ServerThing, m => m.MapFrom(s => s.ServerThingId))
internal static class AsyncHelper {
private static readonly TaskFactory taskFactory = new TaskFactory(CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, TaskScheduler.Default);
public static TResult RunSync<TResult>(this Func<Task<TResult>> func) {
return taskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult();
}
public static void RunSync(this Func<Task> func) {
taskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult();
}
@jbogard
jbogard / gist:6690905
Last active December 23, 2015 20:39
Fun with tests.
namespace Accounts
{
namespace NewAccounts
{
public class When_creating_a_new_account {
Account account = new Account();
public void Does_not_have_any_subscriptions() {
account.Subscriptions.Count.ShouldEqual(0);
}
public class DatabaseDeleter
{
private readonly ISessionFactory _configuration;
private static readonly string[] _ignoredTables = new[] { "sysdiagrams", /* DB Migration tables too */ };
private static string[] _tablesToDelete;
private static string _deleteSql;
private static object _lockObj = new object();
private static bool _initialized;
public DatabaseDeleter(ISessionFactory sessionSource)