Last active
January 3, 2016 05:59
-
-
Save gravypower/8419719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Patterns.AbstractFactory.People | |
{ | |
using Patterns.AbstractFactory.Drinks; | |
/// <summary> | |
/// The aaron. | |
/// </summary> | |
public class Aaron : ICocktailFactory | |
{ | |
/// <summary> | |
/// The favorite drink. | |
/// </summary> | |
/// <returns> | |
/// The <see cref="IDrink"/>. | |
/// </returns> | |
public IDrink FavoriteDrink() | |
{ | |
return new StirredMartini(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Patterns.AbstractFactory | |
{ | |
using Patterns.AbstractFactory.Drinks; | |
using Patterns.AbstractFactory.People; | |
/// <summary> | |
/// The bar person. | |
/// </summary> | |
public class BarPerson : IBarPerson | |
{ | |
/// <summary> | |
/// The mix drink. | |
/// </summary> | |
/// <typeparam name="T"> | |
/// The factory that supplies the drink to me made. | |
/// </typeparam> | |
/// <returns> | |
/// The <see cref="IDrink"/>. | |
/// </returns> | |
public IDrink MixDrink<T>() where T : ICocktailFactory, new() | |
{ | |
return new T().FavoriteDrink(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Patterns.AbstractFactory | |
{ | |
using NUnit.Framework; | |
using Patterns.AbstractFactory.Drinks; | |
using Patterns.AbstractFactory.People; | |
[TestFixture] | |
public class BarPersonTests | |
{ | |
[Test] | |
public void CanCreateShakenMartiniForMrBond() | |
{ | |
var barPerson = new BarPerson(); | |
var drink = barPerson.MixDrink<MrBond>(); | |
Assert.That(drink, Is.TypeOf<ShakenMartini>()); | |
} | |
[Test] | |
public void CanCreateStirredMartiniForAaron() | |
{ | |
var barPerson = new BarPerson(); | |
var drink = barPerson.MixDrink<Aaron>(); | |
Assert.That(drink, Is.TypeOf<StirredMartini>()); | |
} | |
[Test] | |
public void CanCreateCoffeeMartiniForScott() | |
{ | |
var barPerson = new BarPerson(); | |
var drink = barPerson.MixDrink<Scott>(); | |
Assert.That(drink, Is.TypeOf<CoffeeMartini>()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Patterns.AbstractFactory.People | |
{ | |
using Patterns.AbstractFactory.Drinks; | |
/// <summary> | |
/// The mr bond. | |
/// </summary> | |
public class MrBond : ICocktailFactory | |
{ | |
/// <summary> | |
/// The favorite drink. | |
/// </summary> | |
/// <returns> | |
/// The <see cref="IDrink"/>. | |
/// </returns> | |
public IDrink FavoriteDrink() | |
{ | |
return new ShakenMartini(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Patterns.AbstractFactory.People | |
{ | |
using Patterns.AbstractFactory.Drinks; | |
/// <summary> | |
/// The scott. | |
/// </summary> | |
public class Scott : ICocktailFactory | |
{ | |
/// <summary> | |
/// The favorite drink. | |
/// </summary> | |
/// <returns> | |
/// The <see cref="IDrink"/>. | |
/// </returns> | |
public IDrink FavoriteDrink() | |
{ | |
return new CoffeeMartini(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment