Skip to content

Instantly share code, notes, and snippets.

@dbones
Created March 15, 2014 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbones/9569663 to your computer and use it in GitHub Desktop.
Save dbones/9569663 to your computer and use it in GitHub Desktop.
classes which I use for testing ( ArmChair which is hopefully comming soon )
/// <summary>
/// base for all domain object which use this Uow
/// </summary>
public abstract class EntityRoot
{
public virtual int Id { get; protected set; }
}
public class Book : EntityRoot
{
private readonly IList<Contributor> _contributors = new List<Contributor>();
private readonly IList<Edition> _editions = new List<Edition>();
protected Book()
{
}
public Book(string title, Person author)
{
Title = title;
_contributors.Add(new Contributor(author, ContributorType.Author));
}
public virtual void AddContributor(Person contributor, ContributorType contributorType)
{
if (_contributors.Any(x=> x.ContributorId == contributor.Id))
return;
_contributors.Add(new Contributor(contributor, contributorType));
}
public virtual void AddEdition(Edition edition)
{
if (_editions.Contains(edition))
{
_editions.Remove(edition);
}
_editions.Add(edition);
}
public virtual string Title { get; private set; }
public virtual IEnumerable<Contributor> Contributors { get { return _contributors; } }
public virtual IEnumerable<Edition> Editions { get { return _editions; } }
}
public enum ContributorType
{
Author,
CoAuthor,
Editor
}
public enum EditionType
{
HardBack,
Paper,
Electronic
}
public class Contributor
{
protected Contributor()
{
}
public Contributor(int id, string name, ContributorType contribution)
{
ContributorId = id;
Name = name;
Contribution = contribution;
}
public Contributor(Person person, ContributorType contribution) : this(person.Id, person.Name, contribution)
{
}
public virtual string Name { get; private set; }
public virtual ContributorType Contribution { get; private set; }
public virtual int ContributorId { get; private set; }
}
public class Edition
{
public Edition(string name, EditionType editionType)
{
Name = name;
Type = editionType;
}
protected Edition()
{
}
public virtual DateTime ReleaseDate { get; set; }
public virtual string Name { get; private set; }
public virtual EditionType Type { get; private set; }
public override bool Equals(object obj)
{
var other = obj as Edition;
if (other == null)
{
return false;
}
return other.GetHashCode() == GetHashCode();
}
public override int GetHashCode()
{
return Name.GetHashCode() + Type.GetHashCode(); ;
}
}
public class Person : EntityRoot
{
public Person(string name)
{
Name = name;
}
protected Person()
{
}
public virtual string Name { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment