Skip to content

Instantly share code, notes, and snippets.

View darrencauthon's full-sized avatar

Darren Cauthon darrencauthon

View GitHub Profile
public class ObjectUnderTest
{
private string _prefix;
public ObjectUnderTest(string prefix)
{
_prefix = prefix;
}
public class ObjectUnderTest
{
private readonly MappingEngine mappingEngine;
public ObjectUnderTest(string prefix)
{
var configuration = new Configuration(new TypeMapFactory(), MapperRegistry.AllMappers());
configuration.CreateMap<Person, PersonModel>()
.ForMember(x => x.Name, y => y.MapFrom(orig => prefix + orig.Name));
@darrencauthon
darrencauthon / gist:672410
Created November 11, 2010 12:22
To Use a Tuple or Not? Not, I say.
void Main()
{
var people = new []{
new Person() { Id = 1, FirstName = "Darren", LastName = "Cauthon", IsAFanOfAynRand = true, IsACoolPerson = true},
new Person() { Id = 2, FirstName = "Caleb", LastName = "Cauthon", IsAFanOfAynRand = true, IsACoolPerson = false},
new Person() { Id = 3, FirstName = "Evan", LastName = "Cauthon", IsAFanOfAynRand = false, IsACoolPerson = true},
};
var unreadable = new UnreadableCoolAynRandFanRetriever(people);
var readable = new ReadableCoolAynRandFanRetriever(people);
@darrencauthon
darrencauthon / gist:672429
Created November 11, 2010 12:43
Returning an anonymous type as a dynamic to retrieve the values elsewhere
public class IdRetriever {
private IEnumerable<Person> people;
public IdRetriever(IEnumerable<Person> people){
this.people = people;
}
public IEnumerable<int> GetIds(){
return GetTheIds()
@darrencauthon
darrencauthon / Using a class to determine which implementation to use
Created November 21, 2010 17:25
This is a short example showing how one can use a separate class to determine which class should be used in which context.
public class CatalogContextDeterminer
{
private XPrincipal principal;
public CatalogContextDeterminer(XPrincipal principal)
{
principal = principal;
}
public Type GetCatalogContextType()
//First the usage
//Would be cool to use it for taking out parameters from a table, when I only use a few parameters and don't have a real class
[Given(@"the following Dealer exists")]
public void GivenTheFollowingDealerExists(DynamicItems people)
{
var person = people.First();
string Id = Convert.ToInt32(person.Id);
string Name = person.Name;
// do your stuff
@darrencauthon
darrencauthon / Karl's first example
Created March 24, 2011 02:57
Example from Karl
public class UserRepository
{
private readonly IDataStore _store;
private readonly IEncryption _encryption;
public UserRepository(IDataStore store, IEncryption encryption)
{
_store = store;
_encryption = encryption;
}
@darrencauthon
darrencauthon / Code that will still pass Karl's tests
Created March 24, 2011 03:55
Code that will still pass Karl's tests
public class UserRepository
{
private readonly IDataStore dataStore;
private readonly IEncryption encryption;
public UserRepository(IDataStore dataStore, IEncryption encryption)
{
this.dataStore = dataStore;
this.encryption = encryption;
}
public class Tests
{
private AutoMoqer mocker;
[SetUp]
public void Setup()
{
mocker = new AutoMoqer();
mocker.GetMock<IEncryption>()
@darrencauthon
darrencauthon / AppRuntime.cs
Created April 26, 2011 17:31
Sample SimpleCQRS Runtime
public class AppRuntime : SimpleCqrsRuntime<UnityServiceLocator>
{
private readonly string connectionString;
public AppRuntime(string connectionString)
{
this.connectionString = connectionString;
}
protected override IEventStore GetEventStore(IServiceLocator serviceLocator)