Skip to content

Instantly share code, notes, and snippets.

@AlexZeitler
Created August 16, 2011 12:31
Show Gist options
  • Save AlexZeitler/1148962 to your computer and use it in GitHub Desktop.
Save AlexZeitler/1148962 to your computer and use it in GitHub Desktop.
Inheritance of BehaviorConfigs for machine.fakes
using Machine.Fakes;
using Machine.Specifications;
namespace BehaviorConfigInheritance {
public class Given_a_car_when_starting_it : WithSubject<Car> {
static string _sound;
Establish context = () =>
{
//With(new EngineLoaded(300));
With<EngineWith300PSLoaded>();
};
Because of = () => { _sound = Subject.Start(); };
It should_roar = () => { _sound.ShouldEqual("roar"); };
}
public class Car {
readonly IEngine _engine;
public Car(IEngine engine) {
_engine = engine;
}
public string Start() {
if (_engine.Power >= 300) {
return "roar";
}
return "whisper";
}
}
public interface IEngine {
int Power { get; }
}
public class EngineLoaded {
static int _horsePower;
public EngineLoaded(int horsePower) {
_horsePower = horsePower;
}
OnEstablish context =
OnEstablish;
public static void OnEstablish(IFakeAccessor fakeAccessor) {
IEngine eninge = new Engine(_horsePower);
fakeAccessor.Configure(c => c.For<IEngine>().Use(eninge));
}
}
public class Engine : IEngine {
public Engine(int power) {
Power = power;
}
public int Power { get; private set; }
}
public class EngineWith300PSLoaded : EngineLoaded {
public EngineWith300PSLoaded() : base(300) {
}
OnEstablish context = EngineLoaded.OnEstablish;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment