Skip to content

Instantly share code, notes, and snippets.

@travisjj
Created September 20, 2013 19:59
Show Gist options
  • Save travisjj/6642986 to your computer and use it in GitHub Desktop.
Save travisjj/6642986 to your computer and use it in GitHub Desktop.
Mockery
public class Db : IDisposable
{
private List<Intern> Interns { get; set; }
private List<Work> Works { get; set; }
private int internId = 0;
private int workId = 0;
public Db()
{
this.Interns = new List<Intern>();
this.Works = new List<Work>();
var sir = new Intern(internId++,"sir");
this.Interns.Add(sir);
var coffee = new Work(workId++,sir.InternId,"Coffee",sir);
this.Works.Add(coffee);
sir.Works.Add(coffee);
Console.WriteLine("Connection Open");
}
public Intern InternById(int id)
{
return this.Interns.FirstOrDefault( i => i.InternId == id );
}
public void Dispose()
{
Console.WriteLine("Connection Disposed");
}
}
public class Intern
{
public int InternId { get; set; }
public string Name { get; set; }
public bool GetsCoffee { get; set; }
//Navigation Property
public virtual List<Work> Works { get; set; }
public Intern( int id, string name )
{
this.Works = new List<Work>();
this.InternId = id;
this.Name = name;
this.GetsCoffee = true;
}
}
public class Work
{
public int WorkId { get; set; }
public int InternId { get; set; }
public string Description { get; set; }
public virtual Intern Intern { get; set; }
public Work( int WorkId, int InternId, string wrk, Intern intern )
{
this.WorkId = WorkId;
this.InternId = InternId;
this.Description = wrk;
this.Intern = intern;
}
}
void Main()
{
using ( var db = new Db() )
{
var intern = db.InternById(0);
Console.WriteLine(intern.InternId);
Console.WriteLine(intern.Name);
intern.Works.ForEach( w => Console.WriteLine(w.Intern.Name + " worked on getting " + w.Description) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment