Skip to content

Instantly share code, notes, and snippets.

@johncoder
Created October 22, 2012 13:24
Show Gist options
  • Save johncoder/3931493 to your computer and use it in GitHub Desktop.
Save johncoder/3931493 to your computer and use it in GitHub Desktop.
Are My Seams Showing?
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace AreMySeamsShowing
{
[TestClass]
public class WidgetTests
{
private FooA fooA;
[TestInitialize]
public void Init()
{
this.fooA = new FooA(new FooB(new FooC(new FooD()), new FooD()));
}
[TestMethod]
public void Widget_does_something_awesome_when_fooA_deduce_is_true()
{
var widget = new FakeWidget(this.fooA, outcome: true);
widget.Execute();
Assert.IsTrue(widget.SomethingAwesomeHappened);
}
[TestMethod]
public void Widget_does_something_less_awesome_when_fooA_deduce_is_false()
{
var widget = new FakeWidget(this.fooA, outcome: false);
widget.Execute();
Assert.IsTrue(widget.SomethingLessAwesomeHappened);
}
}
public class FakeWidget : Widget
{
public bool SomethingAwesomeHappened { get; set; }
public bool SomethingLessAwesomeHappened { get; set; }
public FakeWidget(FooA fooA, bool outcome)
: base(fooA)
{
Deduce = () => outcome;
}
protected override void DoSomethingAwesome()
{
SomethingAwesomeHappened = true;
}
protected override void DoSomethingLessAwesome()
{
SomethingLessAwesomeHappened = true;
}
}
public class Widget
{
private FooA fooA;
protected Func<bool> Deduce { get; set; }
public Widget(FooA fooa)
{
this.fooA = fooa;
Deduce = fooa.Deduce;
}
public void Execute()
{
if (this.Deduce())
this.DoSomethingAwesome();
else
this.DoSomethingLessAwesome();
}
protected virtual void DoSomethingLessAwesome()
{
Console.WriteLine("This is slightly less awesome.");
}
protected virtual void DoSomethingAwesome()
{
Console.WriteLine("Is this awesome enough?");
}
}
public class FooA
{
public FooA(FooB fooB) { }
public bool Deduce() { return true; }
}
public class FooB
{
public FooB(FooC fooC, FooD fooD) { }
}
public class FooC
{
public FooC(FooD fooD) { }
}
public class FooD { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment